+static int parametersChange(history_t* history, int frame)
+{
+ int willChange = 0;
+
+ willChange = willChange || history_change(history, frame, "x");
+ willChange = willChange || history_change(history, frame, "y");
+ willChange = willChange || history_change(history, frame, "scalex");
+ willChange = willChange || history_change(history, frame, "scaley");
+ willChange = willChange || history_change(history, frame, "cxform.r0");
+ willChange = willChange || history_change(history, frame, "cxform.g0");
+ willChange = willChange || history_change(history, frame, "cxform.b0");
+ willChange = willChange || history_change(history, frame, "cxform.a0");
+ willChange = willChange || history_change(history, frame, "cxform.r1");
+ willChange = willChange || history_change(history, frame, "cxform.g1");
+ willChange = willChange || history_change(history, frame, "cxform.b1");
+ willChange = willChange || history_change(history, frame, "cxform.a1");
+ willChange = willChange || history_change(history, frame, "rotate");
+ willChange = willChange || history_change(history, frame, "shear");
+ willChange = willChange || history_change(history, frame, "pivot.x");
+ willChange = willChange || history_change(history, frame, "pivot.y");
+ willChange = willChange || history_change(history, frame, "pin.x");
+ willChange = willChange || history_change(history, frame, "pin.y");
+ willChange = willChange || history_change(history, frame, "blendmode");
+ willChange = willChange || history_changeFilter(history, frame);
+
+ return willChange;
+}
+
+static void free_filterlist(FILTERLIST* f_list)
+{
+ int i;
+ for (i = 0; i < f_list->num; i++)
+ {
+ if (f_list->filter[i]->type == FILTERTYPE_GRADIENTGLOW)
+ gradient_free(((FILTER_GRADIENTGLOW*)f_list->filter[i])->gradient);
+ free(f_list->filter[i]);
+ }
+ free(f_list);
+}
+
+static void readParameters(history_t* history, parameters_t* p, int frame)
+{
+ p->x = history_value(history, frame, "x");
+ p->y = history_value(history, frame, "y");
+ p->scalex = history_value(history, frame, "scalex");
+ p->scaley = history_value(history, frame, "scaley");
+ p->cxform.r0 = history_value(history, frame, "cxform.r0");
+ p->cxform.g0 = history_value(history, frame, "cxform.g0");
+ p->cxform.b0 = history_value(history, frame, "cxform.b0");
+ p->cxform.a0 = history_value(history, frame, "cxform.a0");
+ p->cxform.r1 = history_value(history, frame, "cxform.r1");
+ p->cxform.g1 = history_value(history, frame, "cxform.g1");
+ p->cxform.b1 = history_value(history, frame, "cxform.b1");
+ p->cxform.a1 = history_value(history, frame, "cxform.a1");
+ p->rotate = history_rotateValue(history, frame);
+ p->shear = history_value(history, frame, "shear");
+ p->pivot.x = history_value(history, frame, "pivot.x");
+ p->pivot.y = history_value(history, frame, "pivot.y");
+ p->pin.x = history_value(history, frame, "pin.x");
+ p->pin.y = history_value(history, frame, "pin.y");
+ p->blendmode = history_value(history, frame, "blendmode");
+ p->filters = history_filterValue(history, frame);
+}
+
+void setPlacement(TAG*tag, U16 id, U16 depth, MATRIX m, char*name, parameters_t*p, char move)
+{
+ SWFPLACEOBJECT po;
+ FILTERLIST flist;
+ swf_GetPlaceObject(NULL, &po);
+ po.id = id;
+ po.depth = depth;
+ po.matrix = m;
+ po.cxform = p->cxform;
+ po.name = name;
+ po.move = move;
+ if(move)
+ po.id = 0;
+ if(p->blendmode) {
+ po.blendmode = p->blendmode;
+ }
+ if (p->filters)
+ po.filters = p->filters;
+ swf_SetPlaceObject(tag, &po);
+}
+
+static void writeInstance(instance_t* i)
+{
+ parameters_t p;
+ MATRIX m;
+ int frame = i->history->firstFrame;
+ TAG* tag = i->history->firstTag;
+ history_processFlags(i->history);
+ while (frame < currentframe)
+ {
+ frame++;
+ while (tag->id != ST_SHOWFRAME)
+ tag = tag->next;
+ if (parametersChange(i->history, frame))
+ {
+ readParameters(i->history, &p, frame);
+ m = s_instancepos(i->character->size, &p);
+
+ if(p.blendmode || p.filters)
+ tag = swf_InsertTag(tag, ST_PLACEOBJECT3);
+ else
+ tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
+ setPlacement(tag, 0, i->depth, m, 0, &p, 1);
+ if (p.filters)
+ free_filterlist(p.filters);
+ }
+ else
+ tag = tag->next;
+ }
+}
+
+void dumpSWF(SWF*swf)
+{
+ TAG* tag = swf->firstTag;
+ printf("vvvvvvvvvvvvvvvvvvvvv\n");
+ while(tag) {
+ printf("%8d %s\n", tag->len, swf_TagGetName(tag));
+ tag = tag->next;
+ }
+ printf("^^^^^^^^^^^^^^^^^^^^^\n");
+}
+