[Swfed-svn] swfed-svn [481] - 複数の Bitmap Style を持つ Shape tag の対応

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2011年 3月 28日 (月) 21:38:48 JST


Revision: 481
          http://sourceforge.jp/projects/swfed/svn/view?view=rev&revision=481
Author:   yoya
Date:     2011-03-28 21:38:47 +0900 (Mon, 28 Mar 2011)

Log Message:
-----------
- 複数の Bitmap Style を持つ Shape tag の対応

Modified Paths:
--------------
    trunk/src/php_swfed.c
    trunk/src/swf_object.c
    trunk/src/swf_tag_shape.c
    trunk/src/swf_tag_shape.h


-------------- next part --------------
Modified: trunk/src/php_swfed.c
===================================================================
--- trunk/src/php_swfed.c	2011-03-28 07:38:26 UTC (rev 480)
+++ trunk/src/php_swfed.c	2011-03-28 12:38:47 UTC (rev 481)
@@ -700,7 +700,8 @@
 }
 
 PHP_METHOD(swfed, getShapeIdListByBitmapRef) {
-    long bitmap_id;
+    int bitmap_id;
+    int *bitmap_id_list, bitmap_id_list_num;
     swf_object_t *swf = NULL;
     swf_tag_t *tag = NULL;
     int i;
@@ -713,10 +714,20 @@
     i = 0;
     for (tag = swf->tag_head ; tag ; tag=tag->next) {
         register int tag_code = tag->tag;
-        if (isShapeTag(tag_code) && (swf_tag_shape_bitmap_get_refcid(tag) == bitmap_id)) {
-            swf_tag_shape_detail_t *swf_tag_shape = tag->detail;
-            add_index_long(return_value, i, (long) swf_tag_shape->shape_id);
-            i++;
+        if (isShapeTag(tag_code)) {
+	    bitmap_id_list = swf_tag_shape_bitmap_get_refcid_list(tag, &bitmap_id_list_num);
+	    if (bitmap_id_list) {
+	        int j;
+		for (j=0 ; j < bitmap_id_list_num ; j++) {
+		    if (bitmap_id_list[j] == bitmap_id) {
+		        swf_tag_shape_detail_t *swf_tag_shape = tag->detail;
+			add_index_long(return_value, i, (long) swf_tag_shape->shape_id);
+			i++;
+			break;
+		    }
+		}
+		free(bitmap_id_list);
+	    }
         }
     }
 }

Modified: trunk/src/swf_object.c
===================================================================
--- trunk/src/swf_object.c	2011-03-28 07:38:26 UTC (rev 480)
+++ trunk/src/swf_object.c	2011-03-28 12:38:47 UTC (rev 481)
@@ -261,12 +261,16 @@
         if (trans_table_get(refcid_trans_table, cid) == TRANS_TABLE_RESERVE_ID) {
             // no purge
             if (isShapeTag(tag->tag)) {
-                int bitmap_id = swf_tag_shape_bitmap_get_refcid(tag);
-                if (bitmap_id > 0) {
-                    trans_table_set(refcid_trans_table, bitmap_id, TRANS_TABLE_RESERVE_ID);
-                }
-            }
-            if (isSpriteTag(tag->tag)) {
+	        int *bitmap_id_list, bitmap_id_list_num;
+		bitmap_id_list = swf_tag_shape_bitmap_get_refcid_list(tag, &bitmap_id_list_num);
+		if (bitmap_id_list) {
+		    int i;
+		    for (i = 0 ; i < bitmap_id_list_num; i++) {
+                        trans_table_set(refcid_trans_table, bitmap_id_list[i], TRANS_TABLE_RESERVE_ID);
+		    }
+		    free(bitmap_id_list);
+		}
+            } else if (isSpriteTag(tag->tag)) {
                 swf_tag_t *t;
                 swf_tag_sprite_detail_t *tag_sprite;
                 tag_sprite = swf_tag_create_input_detail(tag, swf);
@@ -515,41 +519,71 @@
                               int new_width, int new_height) {
     swf_tag_t *tag = NULL;
     double width_scale = 0, height_scale = 0;
+    int *bitmap_id_list, bitmap_id_list_num;
     if (swf->shape_adjust_mode & SWFED_SHAPE_BITMAP_MATRIX_RESCALE) {
         width_scale  = (double) old_width  / new_width;
         height_scale = (double) old_height / new_height;
         for (tag = swf->tag_head ; tag ; tag=tag->next) {
             register int tag_code = tag->tag;
-            if (isShapeTag(tag_code) && (swf_tag_shape_bitmap_get_refcid(tag) == bitmap_id)) {
-                swf_tag_shape_detail_t *swf_tag_shape = tag->detail;
-
-                swf_tag_apply_shape_matrix_factor(tag, swf_tag_shape->shape_id,
-                                                  width_scale, height_scale,
-                                                  0, 0, 0, swf);
+            if (isShapeTag(tag_code)) {
+	        bitmap_id_list = swf_tag_shape_bitmap_get_refcid_list(tag, &bitmap_id_list_num);
+		if (bitmap_id_list) {
+		    int i;
+		    for (i = 0 ; i < bitmap_id_list_num ; i++) { 
+		        if (bitmap_id_list[i] == bitmap_id) {
+			    swf_tag_shape_detail_t *swf_tag_shape = tag->detail;
+			    swf_tag_apply_shape_matrix_factor(tag, swf_tag_shape->shape_id,
+							      width_scale, height_scale,
+							      0, 0, 0, swf);
+			    break;
+			}
+		    }
+		    free(bitmap_id_list);
+		}
             }
-        }
+	}
     }
     
     if (swf->shape_adjust_mode & SWFED_SHAPE_BITMAP_RECT_RESIZE) {
         width_scale  = (double) new_width  / old_width;
         height_scale = (double) new_height / old_height;
         for (tag = swf->tag_head ; tag ; tag=tag->next) {
-            register int tag_code = tag->tag;
-            if (isShapeTag(tag_code) && (swf_tag_shape_bitmap_get_refcid(tag) == bitmap_id)) {
-                swf_tag_shape_detail_t *swf_tag_shape = tag->detail;
-                swf_tag_apply_shape_rect_factor(tag, swf_tag_shape->shape_id,
-                                                width_scale, height_scale,
-                                                0, 0, swf);
-            }
-        }
+	    register int tag_code = tag->tag;
+            if (isShapeTag(tag_code)) {
+	        bitmap_id_list = swf_tag_shape_bitmap_get_refcid_list(tag, &bitmap_id_list_num);
+		if (bitmap_id_list) {
+		    int i;
+		    for (i = 0 ; i < bitmap_id_list_num ; i++) { 
+		        if (bitmap_id_list[i] == bitmap_id) {
+			    swf_tag_shape_detail_t *swf_tag_shape = tag->detail;
+			    swf_tag_apply_shape_rect_factor(tag, swf_tag_shape->shape_id,
+							    width_scale, height_scale,
+							    0, 0, swf);
+			    break;
+			}
+		    }
+		    free(bitmap_id_list);
+		}
+	    }
+	}
     }
     if (swf->shape_adjust_mode & SWFED_SHAPE_BITMAP_TYPE_TILLED) {
         for (tag = swf->tag_head ; tag ; tag=tag->next) {
             register int tag_code = tag->tag;
-            if (isShapeTag(tag_code) && (swf_tag_shape_bitmap_get_refcid(tag) == bitmap_id)) {
-                swf_tag_shape_detail_t *swf_tag_shape = tag->detail;
-                swf_tag_apply_shape_type_tilled(tag, swf_tag_shape->shape_id, swf);
-            }
+            if (isShapeTag(tag_code)) {
+	        bitmap_id_list = swf_tag_shape_bitmap_get_refcid_list(tag, &bitmap_id_list_num);
+		if (bitmap_id_list) {
+		    int i;
+		    for (i = 0 ; i < bitmap_id_list_num ; i++) { 
+		      fprintf(stderr, "adjust_shape_bitmap: i=%d/%d bimap_id_list[i]=%d\n", i, bitmap_id_list_num, bitmap_id_list[i]);
+		        if (bitmap_id_list[i] == bitmap_id) {
+			    swf_tag_shape_detail_t *swf_tag_shape = tag->detail;
+			    swf_tag_apply_shape_type_tilled(tag, swf_tag_shape->shape_id, swf);
+			}
+		    }
+		    free(bitmap_id_list);
+		}
+	    }
         }
     }
     return 0;
@@ -1152,11 +1186,19 @@
                   }
               }
               if (isShapeTag(tag_no)) {
-                  int  bitmap_id = swf_tag_shape_bitmap_get_refcid(tag);
-                  if (bitmap_id > 0) {
-                      int to_bitmap_id = trans_table_get(cid_trans_table, bitmap_id);
-                      swf_tag_shape_bitmap_replace_refcid(tag, to_bitmap_id);
-                  }
+		  int *bitmap_id_list, bitmap_id_list_num;
+		  bitmap_id_list = swf_tag_shape_bitmap_get_refcid_list(tag, &bitmap_id_list_num);
+		  if (bitmap_id_list) {
+		      int i;
+		      for (i = 0 ; i < bitmap_id_list_num; i++) {
+		          int bitmap_id = bitmap_id_list[i];
+			  int to_bitmap_id = trans_table_get(cid_trans_table, bitmap_id);
+			  if ((to_bitmap_id > 0) && (bitmap_id != to_bitmap_id)) {
+			      swf_tag_shape_bitmap_replace_refcid_list(tag, bitmap_id, to_bitmap_id);
+			  }
+		      }
+		      free(bitmap_id_list);
+		  }
               } else if (isSpriteTag(tag_no)){
                   swf_tag_sprite_detail_t *s;
                   s = swf_tag_create_input_detail(tag, swf);

Modified: trunk/src/swf_tag_shape.c
===================================================================
--- trunk/src/swf_tag_shape.c	2011-03-28 07:38:26 UTC (rev 480)
+++ trunk/src/swf_tag_shape.c	2011-03-28 12:38:47 UTC (rev 481)
@@ -149,57 +149,99 @@
     return 0; // always 0
 }
 
-int swf_tag_shape_bitmap_get_refcid(swf_tag_t *tag) {
+int *
+swf_tag_shape_bitmap_get_refcid_list(swf_tag_t *tag, int *cid_list_num) {
     swf_tag_shape_detail_t *swf_tag_shape;
     int i, ret;
+    int *cid_list, cid_list_alloc;
+    swf_styles_t *styles = NULL;
+    swf_shape_record_t *shape_records = NULL;
+
     if (tag == NULL) {
         fprintf(stderr, "swf_tag_shape_bitmap_get_refcid: tag == NULL\n");
-        return -1;
+        return NULL;
     }
     if (! isShapeTag(tag->tag)) {
         fprintf(stderr, "swf_tag_shape_bitmap_get_refcid: ! isShapeTag(%d)\n",
                 tag->tag);
-        return -1;
+        return NULL;
     }
     if (tag->detail == NULL) {
         tag->detail = swf_tag_shape_create_detail();
         swf_tag_shape = (swf_tag_shape_detail_t *) tag->detail;
-        swf_tag_shape->_parse_condition = SWF_TAG_SHAPE_PARSE_CONDITION_BITMAP;
+	//        swf_tag_shape->_parse_condition = SWF_TAG_SHAPE_PARSE_CONDITION_BITMAP;
         ret = swf_tag_shape_input_detail(tag, NULL);
         if (ret) {
             swf_tag_shape_destroy_detail(tag);
-            return -1; // no shape bitmap
+            return NULL; // no shape bitmap
         }
     } else {
         swf_tag_shape = (swf_tag_shape_detail_t *) tag->detail;
     }
     //
-    for (i = 0 ; i < swf_tag_shape->shape_with_style.styles.fill_styles.count ; i++) {
-        swf_fill_style_t *fill_style;
-        fill_style = &(swf_tag_shape->shape_with_style.styles.fill_styles.fill_style[i]);
-        if (fill_style == NULL) {
-            fprintf(stderr, "swf_tag_shape_bitmap_get_refcid: fill_style == NULL i=%d\n", i);
-            return -1; // Illegal!!!
-        }
-        switch (fill_style->type) {
-          case 0x40: // tilled  bitmap fill with smoothed edges
-          case 0x41: // clipped bitmap fill with smoothed edges
-          case 0x42: // tilled  bitmap fill with hard edges
-          case 0x43: // clipped bitmap fill with hard edges
-            if (fill_style->bitmap.bitmap_ref != 0xffff) {
-                return fill_style->bitmap.bitmap_ref;
-            }
-            break;
-          default:
-            break;
-        }
+    *cid_list_num = 0;
+    cid_list_alloc = 10;
+    cid_list = malloc(sizeof(int) * cid_list_alloc);
+
+    styles = &(swf_tag_shape->shape_with_style.styles);
+    shape_records = &(swf_tag_shape->shape_with_style.shape_records);
+    while (1) {
+        for (i = 0 ; i < styles->fill_styles.count ; i++) {
+	    swf_fill_style_t *fill_style;
+	    fill_style = &(styles->fill_styles.fill_style[i]);
+	    if (fill_style == NULL) {
+              fprintf(stderr, "swf_tag_shape_bitmap_get_refcid: fill_style == NULL i=%d\n", i);
+	        free(cid_list);
+		return NULL; // Illegal!!!
+	    }
+	    switch (fill_style->type) {
+              case 0x40: // tilled  bitmap fill with smoothed edges
+              case 0x41: // clipped bitmap fill with smoothed edges
+              case 0x42: // tilled  bitmap fill with hard edges
+              case 0x43: // clipped bitmap fill with hard edges
+		if (fill_style->bitmap.bitmap_ref != 0xffff) {
+	          if (cid_list_alloc <= *cid_list_num) {
+		    cid_list_alloc *= 2;
+		    realloc(cid_list, cid_list_alloc);
+		  }
+		  cid_list[*cid_list_num] = fill_style->bitmap.bitmap_ref;
+		  *cid_list_num  = (*cid_list_num)  + 1;
+		}
+		break;
+              default:
+		break;
+	    }
+	}
+	// new style を探す
+	for ( ; shape_records ; shape_records = shape_records->next) {
+	    if ((shape_records->first_6bits) && 
+		((shape_records->first_6bits & 0x20) == 0)) {
+		if (shape_records->shape.shape_setup.shape_has_new_styles) {
+		    styles = &(shape_records->shape.shape_setup.styles);
+		    break;
+		}
+	    }
+	}
+	if (shape_records) {
+	    shape_records = shape_records->next; // next
+	} else {
+	    break; // finish
+	}
     }
-    return -1; // not found
+
+    if (*cid_list_num == 0) {
+        free(cid_list);
+	return NULL;
+    }
+    return cid_list; // not found
 }
 
-int swf_tag_shape_bitmap_replace_refcid(swf_tag_t *tag, int cid) {
+int swf_tag_shape_bitmap_replace_refcid_list(swf_tag_t *tag, int from_cid, int to_cid) {
     swf_tag_shape_detail_t *swf_tag_shape;
     int i, ret;
+    swf_styles_t *styles = NULL;
+    swf_shape_record_t *shape_records = NULL;
+
     if (tag == NULL) {
         fprintf(stderr, "swf_tag_shape_bitmap_replace_refcid: tag == NULL\n");
         return 1;
@@ -221,32 +263,52 @@
     } else {
         swf_tag_shape = (swf_tag_shape_detail_t *) tag->detail;
     }
-    //
-    for (i = 0 ; i < swf_tag_shape->shape_with_style.styles.fill_styles.count ; i++) {
-        swf_fill_style_t *fill_style;
-        fill_style = &(swf_tag_shape->shape_with_style.styles.fill_styles.fill_style[i]);
-        if (fill_style == NULL) {
-            fprintf(stderr, "swf_tag_shape_bitmap_replace_refcid: fill_style == NULL i=%d\n", i);
-            return 1; // Illegal!!!
-        }
-        switch (fill_style->type) {
-          case 0x40: // tilled  bitmap fill with smoothed edges
-          case 0x41: // clipped bitmap fill with smoothed edges
-          case 0x42: // tilled  bitmap fill with hard edges
-          case 0x43: // clipped bitmap fill with hard edges
-            if (fill_style->bitmap.bitmap_ref != 0xffff) {
-                fill_style->bitmap.bitmap_ref = cid;
-                if (tag->data) {
-                    // 内容が変わったので元データは削除
-                    free(tag->data);
-                    tag->data = NULL;
-                }
-                return 0; // success!
-            }
-            break;
-          default:
-            break;
-        }
+
+    styles = &(swf_tag_shape->shape_with_style.styles);
+    shape_records = &(swf_tag_shape->shape_with_style.shape_records);
+
+    while (1) {
+        for (i = 0 ; i < styles->fill_styles.count ; i++) {
+	    swf_fill_style_t *fill_style;
+	    fill_style = &(styles->fill_styles.fill_style[i]);
+	    if (fill_style == NULL) {
+	        fprintf(stderr, "swf_tag_shape_bitmap_replace_refcid: fill_style == NULL i=%d\n", i);
+		return 1; // Illegal!!!
+	    }
+	    switch (fill_style->type) {
+	      case 0x40: // tilled  bitmap fill with smoothed edges
+	      case 0x41: // clipped bitmap fill with smoothed edges
+	      case 0x42: // tilled  bitmap fill with hard edges
+	      case 0x43: // clipped bitmap fill with hard edges
+		if (fill_style->bitmap.bitmap_ref == from_cid) {
+		    fill_style->bitmap.bitmap_ref = to_cid;
+		    if (tag->data) {
+		        // 内容が変わったので元データは削除
+		        free(tag->data);
+			tag->data = NULL;
+		    }
+		    return 0; // success!
+		}
+		break;
+	    default:
+	      break;
+	    }
+	}
+	// new style を探す
+	for ( ; shape_records ; shape_records = shape_records->next) {
+	    if ((shape_records->first_6bits) && 
+		((shape_records->first_6bits & 0x20) == 0)) {
+		if (shape_records->shape.shape_setup.shape_has_new_styles) {
+		    styles = &(shape_records->shape.shape_setup.styles);
+		    break;
+		}
+	    }
+	}
+	if (shape_records) {
+	    shape_records = shape_records->next; // next
+	} else {
+	    break; // finish
+	}
     }
     return 1; // not found
 }
@@ -436,11 +498,15 @@
 swf_tag_shape_apply_type_tilled(void *detail, int shape_id) {
     int i, count;
     swf_tag_shape_detail_t *swf_tag_shape = (swf_tag_shape_detail_t *) detail;
+    fprintf(stderr, "swf_tag_shape_apply_type_tilled(detail, shape_id=%d)\n",
+	    shape_id);
     if (detail == NULL) {
         fprintf(stderr, "swf_tag_shape_apply_type_tilled: detail == NULL\n");
         return 1;
     }
     if (shape_id != swf_tag_shape->shape_id) {
+        fprintf(stderr, "swf_tag_shape_apply_type_tilled: shape_id(%d) != shape->shape_id(%d)\n",
+	      shape_id, swf_tag_shape->shape_id);
         return 1;
     }
     count = swf_tag_shape->shape_with_style.styles.fill_styles.count;

Modified: trunk/src/swf_tag_shape.h
===================================================================
--- trunk/src/swf_tag_shape.h	2011-03-28 07:38:26 UTC (rev 480)
+++ trunk/src/swf_tag_shape.h	2011-03-28 12:38:47 UTC (rev 481)
@@ -51,8 +51,12 @@
 extern int swf_tag_shape_input_detail(swf_tag_t *tag, struct swf_object_ *swf);
 extern int swf_tag_shape_get_cid_detail(swf_tag_t *tag);
 extern int swf_tag_shape_replace_cid_detail(swf_tag_t *tag, int id);
-extern int swf_tag_shape_bitmap_get_refcid(swf_tag_t *tag);
-extern int swf_tag_shape_bitmap_replace_refcid(swf_tag_t *tag, int cid);
+extern int *swf_tag_shape_bitmap_get_refcid_list(swf_tag_t *tag, int *cid_list_num);
+extern int swf_tag_shape_bitmap_replace_refcid_list(swf_tag_t *tag, int from_cid, int to_cid);
+// ダミー
+extern int swf_tag_shape_bitmap_get_refcid(int x);
+extern int swf_tag_shape_bitmap_replace_refcid(int y);
+// ダミーここまで
 extern unsigned char *swf_tag_shape_output_detail(swf_tag_t *tag,
                                                    unsigned long *length,
                                                    struct swf_object_ *swf);



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