[Swfed-svn] swfed-svn [75] replace{PNG|Jpeg}Data で BitsLossless と BitsJPEG をお互いに変更できるように改良。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 10月 15日 (水) 03:15:52 JST


Revision: 75
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=swfed&view=rev&rev=75
Author:   yoya
Date:     2008-10-15 03:15:52 +0900 (Wed, 15 Oct 2008)

Log Message:
-----------
replace{PNG|Jpeg}Data で BitsLossless と BitsJPEG をお互いに変更できるように改良。

Modified Paths:
--------------
    trunk/src/swf_tag.c
    trunk/src/swf_tag_jpeg.c
    trunk/src/swf_tag_lossless.c


-------------- next part --------------
Modified: trunk/src/swf_tag.c
===================================================================
--- trunk/src/swf_tag.c	2008-10-14 18:13:43 UTC (rev 74)
+++ trunk/src/swf_tag.c	2008-10-14 18:15:52 UTC (rev 75)
@@ -319,30 +319,37 @@
                           unsigned char *alpha_data,
                           unsigned long alpha_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_jpeg_data: tag == NULL\n");
         return 1;
     }
-    if ((tag->tag != 6) && (tag->tag != 21) && (tag->tag != 35)) { // DefineBitsJPEG or 2 or 3
+    // 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);
-    if (tag_info && tag_info->detail_handler) {
-        swf_tag_detail_handler_t * detail_handler = tag_info->detail_handler();
-        if (detail_handler->identity) {
-            if (detail_handler->identity(tag->data, image_id, tag)) {
-                return 1;
-            }
-        }
+    detail_handler = tag_info->detail_handler();
+    if (detail_handler->identity(tag->data, image_id, tag)) {
+        return 1;
     }
-    if (! tag->detail) {
-        swf_tag_create_input_detail(tag, NULL);
+    if (tag->detail) {
+        detail_handler->destroy(tag->detail);
+        tag->detail = NULL;
     }
-    if (! tag->detail) {
-        fprintf(stderr, "swf_tag_replace_jpeg_data: Can't create tag\n");
-        return 1;
+    if (alpha_data && (alpha_data_len > 0)) {
+        tag->tag = 35;
+    } else {
+        if (tag->tag != 6) {
+            tag->tag = 21;
+        }
     }
+    tag_info = get_swf_tag_info(tag->tag);
+    detail_handler = tag_info->detail_handler();
+    tag->detail = detail_handler->create();
     result= swf_tag_jpeg_replace_jpeg_data(tag->detail, image_id,
                                            jpeg_data, jpeg_data_len,
                                            alpha_data, alpha_data_len, tag);
@@ -350,7 +357,10 @@
         free(tag->data);
         tag->data = NULL;
         tag->length = 0;
-    }
+    } else {
+        detail_handler->destroy(tag->detail);
+        tag->detail = NULL;
+    } 
     return result;
 }
 
@@ -381,36 +391,45 @@
                          unsigned char *png_data,
                          unsigned long png_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_png_data: tag == NULL\n");
         return 1;
     }
-    if ((tag->tag != 20) && (tag->tag != 36)) { // DefineBitsLossless or 2
+    // 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);
-    if (tag_info && tag_info->detail_handler) {
-        swf_tag_detail_handler_t * detail_handler = tag_info->detail_handler();
-        if (detail_handler->identity) {
-            if (detail_handler->identity(tag->data, image_id, tag)) {
-                return 1;
-            }
-        }
+    detail_handler = tag_info->detail_handler();
+    if (detail_handler->identity(tag->data, image_id, tag)) {
+        return 1;
     }
-    if (! tag->detail) {
-        swf_tag_create_input_detail(tag, NULL);
+    if (tag->detail) {
+        detail_handler->destroy(tag->detail);
+        tag->detail = NULL;
     }
-    if (! tag->detail) {
-        fprintf(stderr, "swf_tag_replace_png_data: Can't create tag\n");
-        return 1;
+    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_png_data(tag->detail, image_id,
                                               png_data, png_data_len, tag);
     if (result == 0) {
         free(tag->data);
         tag->data = NULL;
         tag->length = 0;
+    } else {
+        detail_handler->destroy(tag->detail);
+        tag->detail = NULL;
     }
     return result;
 }

Modified: trunk/src/swf_tag_jpeg.c
===================================================================
--- trunk/src/swf_tag_jpeg.c	2008-10-14 18:13:43 UTC (rev 74)
+++ trunk/src/swf_tag_jpeg.c	2008-10-14 18:15:52 UTC (rev 75)
@@ -46,9 +46,10 @@
         fprintf(stderr, "ERROR: swf_tag_jpeg_create_detail: can't calloc\n");
         return NULL;
     }
-    swf_tag_jpeg->image_id = -1;
+    swf_tag_jpeg->image_id = 0;
     swf_tag_jpeg->jpeg_data = NULL;
     swf_tag_jpeg->jpeg_data_len = 0;
+    swf_tag_jpeg->offset_to_alpha = 0;
     swf_tag_jpeg->alpha_data = NULL;
     swf_tag_jpeg->alpha_data_len = 0;
     return (void *) swf_tag_jpeg;
@@ -306,9 +307,7 @@
         fprintf(stderr, "swf_tag_jpeg_replace_jpeg_data: detail == NULL\n");
         return 1;
     }
-    if (swf_tag_jpeg->image_id != image_id) {
-        return 1;
-    }
+    swf_tag_jpeg->image_id = image_id;
     if (tag->tag == 6) { // DefineBitsJPEG
         free(swf_tag_jpeg->jpeg_data);
         swf_tag_jpeg->jpeg_data = malloc(jpeg_data_len);
@@ -329,6 +328,5 @@
             swf_tag_jpeg->alpha_data_len = alpha_data_len;
         }
     }
-
     return 0;
 }

Modified: trunk/src/swf_tag_lossless.c
===================================================================
--- trunk/src/swf_tag_lossless.c	2008-10-14 18:13:43 UTC (rev 74)
+++ trunk/src/swf_tag_lossless.c	2008-10-14 18:15:52 UTC (rev 75)
@@ -33,6 +33,16 @@
         fprintf(stderr, "swf_tag_lossless_create_detail: can't calloc swf_tag_lossless\n");
         return NULL;
     }
+    swf_tag_lossless->image_id = 0;
+    swf_tag_lossless->format = 0;
+    swf_tag_lossless->width  = 0;
+    swf_tag_lossless->height = 0;
+    swf_tag_lossless->colormap_count = 0;
+    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;
     return swf_tag_lossless;
 }
 
@@ -377,9 +387,7 @@
         fprintf(stderr, "swf_tag_lossless_replace_lossless_data: detail == NULL at line(%d)\n", __LINE__);
         return 1;
     }
-    if (swf_tag_lossless->image_id != image_id) {
-        return 1;
-    }
+    swf_tag_lossless->image_id = image_id;
     result_data = pngconv_png2lossless(png_data, png_data_len,
                                        &tag_no, &format,
                                        &width, &height,


Swfed-svn メーリングリストの案内
Back to archive index