1 | /* |
1 | /* |
2 | generate_image.c - Part of psiconv, a PSION 5 file formats converter |
2 | generate_image.c - Part of psiconv, a PSION 5 file formats converter |
3 | Copyright (c) 1999-2004 Frodo Looijaard <frodol@dds.nl> |
3 | Copyright (c) 1999-2005 Frodo Looijaard <frodo@frodo.looijaard.name> |
4 | |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
264 | << (greenbits+bluebits)) + |
264 | << (greenbits+bluebits)) + |
265 | (((psiconv_u32) (p_green * (1 << greenbits) + 0.5)) |
265 | (((psiconv_u32) (p_green * (1 << greenbits) + 0.5)) |
266 | << bluebits) + |
266 | << bluebits) + |
267 | ((psiconv_u32) (p_blue * (1 << bluebits) + 0.5)); |
267 | ((psiconv_u32) (p_blue * (1 << bluebits) + 0.5)); |
268 | else |
268 | else |
269 | pixel = (p_red + p_green + p_blue)/3.0 * (1 << colordepth); |
269 | pixel = (0.212671 * p_red + 0.715160 * p_green + 0.072169 * p_blue) * ((1 << colordepth) * 0.999); |
270 | } else { |
270 | } else { |
271 | dist = 4; /* Max distance is 3, so this is safe */ |
271 | dist = 4; /* Max distance is 3, so this is safe */ |
272 | pixel = -1; |
272 | pixel = -1; |
273 | for (i = 0; i < palet.length; i++) { |
273 | for (i = 0; i < palet.length; i++) { |
274 | new_dist = (p_red - palet.red[i]) * (p_red - palet.red[i]) + |
274 | new_dist = (p_red - palet.red[i]) * (p_red - palet.red[i]) + |
… | |
… | |
332 | outputbyte = 0; |
332 | outputbyte = 0; |
333 | for (y = 0; y < ysize; y++) { |
333 | for (y = 0; y < ysize; y++) { |
334 | outputbytenr = 0; |
334 | outputbytenr = 0; |
335 | for (x = 0; x < xsize; x++) { |
335 | for (x = 0; x < xsize; x++) { |
336 | if (!(pixelptr = psiconv_list_get(pixels,y*xsize+x))) { |
336 | if (!(pixelptr = psiconv_list_get(pixels,y*xsize+x))) { |
337 | psiconv_error(config,lev,0,"Massive internal corruption"); |
337 | psiconv_error(config,lev,0,"Data structure corruption"); |
338 | res = -PSICONV_E_NOMEM; |
338 | res = -PSICONV_E_NOMEM; |
339 | goto ERROR2; |
339 | goto ERROR2; |
340 | } |
340 | } |
341 | inputbitsleft = colordepth; |
341 | inputbitsleft = colordepth; |
342 | inputdata = *pixelptr; |
342 | inputdata = *pixelptr; |
… | |
… | |
958 | psiconv_error(config,lev,0,"Writing of jumptable section failed"); |
958 | psiconv_error(config,lev,0,"Writing of jumptable section failed"); |
959 | else |
959 | else |
960 | psiconv_progress(config,lev,0,"End of jumptable section"); |
960 | psiconv_progress(config,lev,0,"End of jumptable section"); |
961 | return res; |
961 | return res; |
962 | } |
962 | } |
963 | |
|
|