svnno****@sourc*****
svnno****@sourc*****
2008年 10月 7日 (火) 01:50:19 JST
Revision: 60 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=swfed&view=rev&rev=60 Author: yoya Date: 2008-10-07 01:50:19 +0900 (Tue, 07 Oct 2008) Log Message: ----------- 透明度付き(tRNS) palette 形式 PNG に対応しました。 Modified Paths: -------------- src/swf_png.c -------------- next part -------------- Modified: src/swf_png.c =================================================================== --- src/swf_png.c 2008-10-06 16:41:02 UTC (rev 59) +++ src/swf_png.c 2008-10-06 16:50:19 UTC (rev 60) @@ -90,8 +90,10 @@ png_uint_32 x, y; void *image_data; png_color *palette = NULL; -// png_color_16p background; // for bKGD ??? int palette_num = 0; + png_bytep trans = NULL; + int num_trans = 0; + png_color_16p trans_values = NULL; is_png = png_check_sig((png_bytep)png_data, 8); if (! is_png) { @@ -136,14 +138,13 @@ switch(color_type) { case PNG_COLOR_TYPE_PALETTE: *format = 3; -/* if (png_get_bKGD(png_ptr, png_info, &background)) { + png_get_PLTE(png_ptr, png_info, &palette, &palette_num); + if (png_get_tRNS(png_ptr, png_info, &trans, &num_trans, + &trans_values) && (num_trans > 0)) { *tag_no = 36; // DefineBitsLossless2 } else { - *tag_no = 20; // DefineBitsLossless1 + *tag_no = 20; // DefineBitsLossless } -*/ - *tag_no = 20; /* DefineBitsLossless */ - png_get_PLTE(png_ptr, png_info, &palette, &palette_num); break; case PNG_COLOR_TYPE_RGB: *format = 5; @@ -179,20 +180,34 @@ if (color_type == PNG_COLOR_TYPE_PALETTE) { int i; *colormap_count = palette_num; - swf_rgb_t *result_colormap = malloc(sizeof(swf_rgb_t) * palette_num); // Lossless - for (i = 0 ; i < palette_num ; i++) { - result_colormap[i].red = palette[i].red; - result_colormap[i].green = palette[i].green; - result_colormap[i].blue = palette[i].blue; + if (num_trans == 0) { + swf_rgb_t *result_colormap = malloc(sizeof(swf_rgb_t) * palette_num); // Lossless + for (i = 0 ; i < palette_num ; i++) { + result_colormap[i].red = palette[i].red; + result_colormap[i].green = palette[i].green; + result_colormap[i].blue = palette[i].blue; + } + *colormap = result_colormap; + } else { + swf_rgba_t *result_colormap = malloc(sizeof(swf_rgba_t) * palette_num); // Lossless2 + for (i = 0 ; i < palette_num ; i++) { + result_colormap[i].red = palette[i].red; + result_colormap[i].green = palette[i].green; + result_colormap[i].blue = palette[i].blue; + if (i <= num_trans) { + result_colormap[i].alpha = trans[i]; + } else { + result_colormap[i].alpha = 0xff; // XXX + } + } + *colormap = result_colormap; } - unsigned char *indices_data = - malloc(((png_width+ 3) & -4) * png_height); + unsigned char *indices_data = malloc(((png_width+ 3) & -4) * png_height); for (y=0; y < png_height; y++) { for (x=0; x < png_width; x++) { indices_data[x+y*((png_width + 3) & -4)] = png_image_data[y][x]; // XXX } } - *colormap = result_colormap; image_data = indices_data; } else if (color_type == PNG_COLOR_TYPE_RGB) { swf_xrgb_t *xrgb_list;