svnno****@sourc*****
svnno****@sourc*****
2009年 2月 2日 (月) 23:01:40 JST
Revision: 105 http://svn.sourceforge.jp/view?root=swfed&view=rev&rev=105 Author: yoya Date: 2009-02-02 23:01:40 +0900 (Mon, 02 Feb 2009) Log Message: ----------- PHP から swf_tag_lossless_replace_gif_data への繋ぎこみを実装 Modified Paths: -------------- trunk/src/php_swfed.h trunk/src/swf_object.c trunk/src/swf_object.h trunk/src/swf_tag.c trunk/src/swf_tag.h trunk/src/swf_tag_lossless.c trunk/src/swf_tag_lossless.h trunk/src/swfed.c -------------- next part -------------- Modified: trunk/src/php_swfed.h =================================================================== --- trunk/src/php_swfed.h 2009-02-02 13:52:33 UTC (rev 104) +++ trunk/src/php_swfed.h 2009-02-02 14:01:40 UTC (rev 105) @@ -58,6 +58,7 @@ PHP_METHOD(swfed, replaceJpegData); PHP_METHOD(swfed, getPNGData); PHP_METHOD(swfed, replacePNGData); +PHP_METHOD(swfed, replaceGIFData); PHP_METHOD(swfed, getSoundData); PHP_METHOD(swfed, replaceMLDData); PHP_METHOD(swfed, getEditString); Modified: trunk/src/swf_object.c =================================================================== --- trunk/src/swf_object.c 2009-02-02 13:52:33 UTC (rev 104) +++ trunk/src/swf_object.c 2009-02-02 14:01:40 UTC (rev 105) @@ -299,6 +299,26 @@ return result; } +int +swf_object_replace_gifdata(swf_object_t *swf, int image_id, + unsigned char *gif_data, + unsigned long gif_data_len) { + int result = 1; + swf_tag_t *tag; + if (swf == NULL) { + fprintf(stderr, "swf_object_replace_gifdata: swf == NULL\n"); + return 1; + } + for (tag=swf->tag ; tag ; tag=tag->next) { + result = swf_tag_replace_gif_data(tag, image_id, + gif_data, gif_data_len); + if (! result) { + break; + } + } + return result; +} + unsigned char * swf_object_get_sounddata(swf_object_t *swf, unsigned long *length, int sound_id) { swf_tag_t *tag; Modified: trunk/src/swf_object.h =================================================================== --- trunk/src/swf_object.h 2009-02-02 13:52:33 UTC (rev 104) +++ trunk/src/swf_object.h 2009-02-02 14:01:40 UTC (rev 105) @@ -36,6 +36,9 @@ extern int swf_object_replace_pngdata(swf_object_t *swf, int image_id, unsigned char *png_data, unsigned long png_data_len); +extern int swf_object_replace_gifdata(swf_object_t *swf, int image_id, + unsigned char *gif_data, + unsigned long gif_data_len); extern unsigned char *swf_object_get_sounddata(swf_object_t *swf, unsigned long *length, int sound_id); extern int swf_object_replace_melodata(swf_object_t *swf, int sound_id, unsigned char *melo_data, Modified: trunk/src/swf_tag.c =================================================================== --- trunk/src/swf_tag.c 2009-02-02 13:52:33 UTC (rev 104) +++ trunk/src/swf_tag.c 2009-02-02 14:01:40 UTC (rev 105) @@ -436,6 +436,54 @@ return result; } +int +swf_tag_replace_gif_data(swf_tag_t *tag, int image_id, + unsigned char *gif_data, + unsigned long gif_data_len) { + swf_tag_info_t *tag_info; + swf_tag_detail_handler_t *detail_handler; + int result; + if (tag == NULL) { + fprintf(stderr, "swf_tag_replace_gif_data: tag == NULL\n"); + return 1; + } + // DefineBitsJPEG or 2 or 3 + // BitsLossless or 2 + if ((tag->tag != 6) && (tag->tag != 21) && (tag->tag != 35) && + (tag->tag != 20) && (tag->tag != 36)) { + return 1; + } + tag_info = get_swf_tag_info(tag->tag); + detail_handler = tag_info->detail_handler(); + if (detail_handler->identity(tag, image_id)) { + return 1; + } + if (tag->detail) { + detail_handler->destroy(tag); + tag->detail = NULL; + } + if (tag->tag == 20) { + tag->tag = 20; + } else { + tag->tag = 36; + } + + tag_info = get_swf_tag_info(tag->tag); + detail_handler = tag_info->detail_handler(); + tag->detail = detail_handler->create(); + result= swf_tag_lossless_replace_gif_data(tag->detail, image_id, + gif_data, gif_data_len, tag); + if (result == 0) { + free(tag->data); + tag->data = NULL; + tag->length = 0; + } else { + detail_handler->destroy(tag); + tag->detail = NULL; + } + return result; +} + /* * DefineSound */ Modified: trunk/src/swf_tag.h =================================================================== --- trunk/src/swf_tag.h 2009-02-02 13:52:33 UTC (rev 104) +++ trunk/src/swf_tag.h 2009-02-02 14:01:40 UTC (rev 105) @@ -58,6 +58,9 @@ extern int swf_tag_replace_png_data(swf_tag_t *tag, int image_id, unsigned char *png_data, unsigned long png_data_len); +extern int swf_tag_replace_gif_data(swf_tag_t *tag, int image_id, + unsigned char *gif_data, + unsigned long gif_data_len); /* sound */ extern unsigned char *swf_tag_get_sound_data(swf_tag_t *tag, unsigned long *length, Modified: trunk/src/swf_tag_lossless.c =================================================================== --- trunk/src/swf_tag_lossless.c 2009-02-02 13:52:33 UTC (rev 104) +++ trunk/src/swf_tag_lossless.c 2009-02-02 14:01:40 UTC (rev 105) @@ -12,6 +12,7 @@ #include "swf_define.h" #include "swf_tag_lossless.h" #include "swf_png.h" +#include "swf_gif.h" swf_tag_detail_handler_t lossless_detail_handler; @@ -444,3 +445,59 @@ } return 0; } + +int +swf_tag_lossless_replace_gif_data(void *detail, int image_id, + unsigned char *gif_data, + unsigned long gif_data_len, swf_tag_t *tag) { + int tag_no, format; + unsigned short width, height; + unsigned char *result_data; + void *colormap = NULL; + int colormap_count = 0; + swf_tag_lossless_detail_t *swf_tag_lossless = (swf_tag_lossless_detail_t *) detail; + if (detail == NULL) { + fprintf(stderr, "swf_tag_lossless_replace_lossless_data: detail == NULL at line(%d)\n", __LINE__); + return 1; + } + swf_tag_lossless->image_id = image_id; + result_data = gifconv_gif2lossless(gif_data, gif_data_len, + &tag_no, &format, + &width, &height, + &colormap, &colormap_count); + + if (result_data == NULL) { + fprintf(stderr, "swf_tag_lossless_replace_lossless_data: gifconv_gif2lossless failed at line(%d)\n", __LINE__); + return 1; + } + tag->tag = tag_no; + swf_tag_lossless->format = format; + swf_tag_lossless->width = width; + swf_tag_lossless->height = height; + if (format == 3) { + free(swf_tag_lossless->colormap); + free(swf_tag_lossless->colormap2); + free(swf_tag_lossless->indices); + free(swf_tag_lossless->bitmap); + free(swf_tag_lossless->bitmap2); + swf_tag_lossless->colormap = NULL; + swf_tag_lossless->colormap2 = NULL; + swf_tag_lossless->indices = NULL; + swf_tag_lossless->bitmap = NULL; + swf_tag_lossless->bitmap2 = NULL; + if (tag_no == 20) { + swf_tag_lossless->colormap = (swf_rgb_t*) colormap; + } else if (tag_no == 36) { + swf_tag_lossless->colormap2 = (swf_rgba_t*) colormap; + } else { + fprintf(stderr, "swf_tag_lossless_replace_lossless_data: internal error tag_no(%d) at line(%d).\n", tag_no, __LINE__); + return 1; + } + swf_tag_lossless->colormap_count = colormap_count; + swf_tag_lossless->indices = (unsigned char *) result_data; + } else { + fprintf(stderr, "swf_tag_lossless_replace_lossless_data: format(%d) not implemented yet. at line(%d)\n", format, __LINE__); + return 1; + } + return 0; +} Modified: trunk/src/swf_tag_lossless.h =================================================================== --- trunk/src/swf_tag_lossless.h 2009-02-02 13:52:33 UTC (rev 104) +++ trunk/src/swf_tag_lossless.h 2009-02-02 14:01:40 UTC (rev 105) @@ -50,5 +50,9 @@ unsigned char *png_data, unsigned long png_data_len, swf_tag_t *tag); +extern int swf_tag_lossless_replace_gif_data(void *detail, int image_id, + unsigned char *gif_data, + unsigned long gif_data_len, + swf_tag_t *tag); #endif /* __SWF_TAG_LOSSLESS__H__ */ Modified: trunk/src/swfed.c =================================================================== --- trunk/src/swfed.c 2009-02-02 13:52:33 UTC (rev 104) +++ trunk/src/swfed.c 2009-02-02 14:01:40 UTC (rev 105) @@ -61,6 +61,7 @@ PHP_ME(swfed, replaceJpegData, NULL, 0) PHP_ME(swfed, getPNGData, NULL, 0) PHP_ME(swfed, replacePNGData, NULL, 0) + PHP_ME(swfed, replaceGIFData, NULL, 0) PHP_ME(swfed, getSoundData, NULL, 0) PHP_ME(swfed, replaceMLDData, NULL, 0) PHP_ME(swfed, getEditString, NULL, 0) @@ -586,6 +587,32 @@ RETURN_TRUE; } +PHP_METHOD(swfed, replaceGIFData) { + char *data = NULL; + int data_len = 0; + int image_id; + swf_object_t *swf; + int result = 0; + switch (ZEND_NUM_ARGS()) { + default: + WRONG_PARAM_COUNT; + RETURN_FALSE; /* XXX */ + case 2: + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &image_id, &data, &data_len) == FAILURE) { + RETURN_FALSE; + } + break; + } + swf = get_swf_object(getThis() TSRMLS_CC); + result = swf_object_replace_gifdata(swf, image_id, + (unsigned char *)data, + (unsigned long) data_len); + if (result) { + RETURN_FALSE; + } + RETURN_TRUE; +} + PHP_METHOD(swfed, getSoundData) { unsigned long sound_id = 0; unsigned long len = 0;