00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #define GL_GLEXT_PROTOTYPES
00021
00022 #include "swftypes.h"
00023 #include "scripting/abc.h"
00024 #include "logger.h"
00025 #include <string.h>
00026 #include <algorithm>
00027 #include <stdlib.h>
00028 #include <math.h>
00029 #include "swf.h"
00030 #include "backends/geometry.h"
00031 #include "backends/rendering.h"
00032 #include "scripting/class.h"
00033 #include "exceptions.h"
00034 #include "compat.h"
00035
00036 using namespace std;
00037 using namespace lightspark;
00038
00039 extern TLSDATA SystemState* sys;
00040 extern TLSDATA RenderThread* rt;
00041 extern TLSDATA ParseThread* pt;
00042
00043 tiny_string multiname::qualifiedString() const
00044 {
00045 assert_and_throw(ns.size()==1);
00046 assert_and_throw(name_type==NAME_STRING);
00047
00048 if(false && ns[0].name=="")
00049 return name_s;
00050 else
00051 {
00052 tiny_string ret=ns[0].name;
00053 ret+="::";
00054 ret+=name_s;
00055 return ret;
00056 }
00057 }
00058
00059 std::ostream& lightspark::operator<<(std::ostream& s, const QName& r)
00060 {
00061 s << r.ns << ':' << r.name;
00062 return s;
00063 }
00064
00065 std::ostream& lightspark::operator<<(std::ostream& s, const tiny_string& r)
00066 {
00067 s << r.buf;
00068 return s;
00069 }
00070
00071 std::ostream& lightspark::operator<<(std::ostream& s, const multiname& r)
00072 {
00073 for(unsigned int i=0;i<r.ns.size();i++)
00074 {
00075 string prefix;
00076 switch(r.ns[i].kind)
00077 {
00078 case 0x08:
00079 prefix="ns:";
00080 break;
00081 case 0x16:
00082 prefix="pakns:";
00083 break;
00084 case 0x17:
00085 prefix="pakintns:";
00086 break;
00087 case 0x18:
00088 prefix="protns:";
00089 break;
00090 case 0x19:
00091 prefix="explns:";
00092 break;
00093 case 0x1a:
00094 prefix="staticprotns:";
00095 break;
00096 case 0x05:
00097 prefix="privns:";
00098 break;
00099 }
00100 s << '[' << prefix << r.ns[i].name << "] ";
00101 }
00102 if(r.name_type==multiname::NAME_INT)
00103 s << r.name_i;
00104 else if(r.name_type==multiname::NAME_NUMBER)
00105 s << r.name_d;
00106 else if(r.name_type==multiname::NAME_STRING)
00107 s << r.name_s;
00108 else
00109 s << r.name_o;
00110 return s;
00111 }
00112
00113 lightspark::RECT::RECT()
00114 {
00115 }
00116
00117 lightspark::RECT::RECT(int a, int b, int c, int d):Xmin(a),Xmax(b),Ymin(c),Ymax(d)
00118 {
00119 }
00120
00121 std::ostream& lightspark::operator<<(std::ostream& s, const RECT& r)
00122 {
00123 s << '{' << (int)r.Xmin << ',' << r.Xmax << ',' << r.Ymin << ',' << r.Ymax << '}';
00124 return s;
00125 }
00126
00127 ostream& lightspark::operator<<(ostream& s, const STRING& t)
00128 {
00129 for(unsigned int i=0;i<t.String.size();i++)
00130 s << t.String[i];
00131 return s;
00132 }
00133
00134 std::ostream& operator<<(std::ostream& s, const RGBA& r)
00135 {
00136 s << "RGBA <" << (int)r.Red << ',' << (int)r.Green << ',' << (int)r.Blue << ',' << (int)r.Alpha << '>';
00137 return s;
00138 }
00139
00140 std::ostream& operator<<(std::ostream& s, const RGB& r)
00141 {
00142 s << "RGB <" << (int)r.Red << ',' << (int)r.Green << ',' << (int)r.Blue << '>';
00143 return s;
00144 }
00145
00146 void MATRIX::get4DMatrix(float matrix[16]) const
00147 {
00148 memset(matrix,0,sizeof(float)*16);
00149 matrix[0]=ScaleX;
00150 matrix[1]=RotateSkew0;
00151
00152 matrix[4]=RotateSkew1;
00153 matrix[5]=ScaleY;
00154
00155 matrix[10]=1;
00156
00157 matrix[12]=TranslateX;
00158 matrix[13]=TranslateY;
00159 matrix[15]=1;
00160 }
00161
00162 void MATRIX::multiply2D(number_t xin, number_t yin, number_t& xout, number_t& yout) const
00163 {
00164 xout=xin*ScaleX + yin*RotateSkew1 + TranslateX;
00165 yout=xin*RotateSkew0 + yin*ScaleY + TranslateY;
00166 }
00167
00168 void MATRIX::getTranslation(int& x, int& y) const
00169 {
00170 x=TranslateX;
00171 y=TranslateY;
00172 }
00173
00174 std::ostream& operator<<(std::ostream& s, const MATRIX& r)
00175 {
00176 s << "| " << r.ScaleX << ' ' << r.RotateSkew0 << " |" << std::endl;
00177 s << "| " << r.RotateSkew1 << ' ' << r.ScaleY << " |" << std::endl;
00178 s << "| " << (int)r.TranslateX << ' ' << (int)r.TranslateY << " |" << std::endl;
00179 return s;
00180 }
00181
00182 std::istream& lightspark::operator>>(std::istream& stream, STRING& v)
00183 {
00184 v.String.clear();
00185 UI8 c;
00186 do
00187 {
00188 stream >> c;
00189 if(c==0)
00190 break;
00191 v.String.push_back(c);
00192 }
00193 while(c!=0);
00194 return stream;
00195 }
00196
00197 std::istream& lightspark::operator>>(std::istream& stream, RECT& v)
00198 {
00199 BitStream s(stream);
00200 int nbits=UB(5,s);
00201 v.Xmin=SB(nbits,s);
00202 v.Xmax=SB(nbits,s);
00203 v.Ymin=SB(nbits,s);
00204 v.Ymax=SB(nbits,s);
00205 return stream;
00206 }
00207
00208 std::istream& lightspark::operator>>(std::istream& s, RGB& v)
00209 {
00210 s >> v.Red >> v.Green >> v.Blue;
00211 return s;
00212 }
00213
00214 std::istream& lightspark::operator>>(std::istream& s, RGBA& v)
00215 {
00216 s >> v.Red >> v.Green >> v.Blue >> v.Alpha;
00217 return s;
00218 }
00219
00220 void LINESTYLEARRAY::appendStyles(const LINESTYLEARRAY& r)
00221 {
00222 unsigned int count = LineStyleCount + r.LineStyleCount;
00223 assert_and_throw(version!=-1);
00224
00225 assert_and_throw(r.version==version);
00226 if(version<4)
00227 LineStyles.insert(LineStyles.end(),r.LineStyles.begin(),r.LineStyles.end());
00228 else
00229 LineStyles2.insert(LineStyles2.end(),r.LineStyles2.begin(),r.LineStyles2.end());
00230 LineStyleCount = count;
00231 }
00232
00233 std::istream& lightspark::operator>>(std::istream& s, LINESTYLEARRAY& v)
00234 {
00235 assert_and_throw(v.version!=-1);
00236 s >> v.LineStyleCount;
00237 if(v.LineStyleCount==0xff)
00238 LOG(LOG_ERROR,_("Line array extended not supported"));
00239 if(v.version<4)
00240 {
00241 for(int i=0;i<v.LineStyleCount;i++)
00242 {
00243 LINESTYLE tmp;
00244 tmp.version=v.version;
00245 s >> tmp;
00246 v.LineStyles.push_back(tmp);
00247 }
00248 }
00249 else
00250 {
00251 for(int i=0;i<v.LineStyleCount;i++)
00252 {
00253 LINESTYLE2 tmp;
00254 s >> tmp;
00255 v.LineStyles2.push_back(tmp);
00256 }
00257 }
00258 return s;
00259 }
00260
00261 std::istream& lightspark::operator>>(std::istream& s, MORPHLINESTYLEARRAY& v)
00262 {
00263 s >> v.LineStyleCount;
00264 if(v.LineStyleCount==0xff)
00265 LOG(LOG_ERROR,_("Line array extended not supported"));
00266 v.LineStyles=new MORPHLINESTYLE[v.LineStyleCount];
00267 for(int i=0;i<v.LineStyleCount;i++)
00268 {
00269 s >> v.LineStyles[i];
00270 }
00271 return s;
00272 }
00273
00274 void FILLSTYLEARRAY::appendStyles(const FILLSTYLEARRAY& r)
00275 {
00276 assert_and_throw(version!=-1);
00277 unsigned int count = FillStyleCount + r.FillStyleCount;
00278
00279 FillStyles.insert(FillStyles.end(),r.FillStyles.begin(),r.FillStyles.end());
00280 FillStyleCount = count;
00281 }
00282
00283 std::istream& lightspark::operator>>(std::istream& s, FILLSTYLEARRAY& v)
00284 {
00285 assert_and_throw(v.version!=-1);
00286 s >> v.FillStyleCount;
00287 if(v.FillStyleCount==0xff)
00288 LOG(LOG_ERROR,_("Fill array extended not supported"));
00289
00290 v.FillStyles.resize(v.FillStyleCount);
00291 list<FILLSTYLE>::iterator it=v.FillStyles.begin();
00292 for(;it!=v.FillStyles.end();it++)
00293 {
00294 it->version=v.version;
00295 s >> *it;
00296 }
00297 return s;
00298 }
00299
00300 std::istream& lightspark::operator>>(std::istream& s, MORPHFILLSTYLEARRAY& v)
00301 {
00302 s >> v.FillStyleCount;
00303 if(v.FillStyleCount==0xff)
00304 LOG(LOG_ERROR,_("Fill array extended not supported"));
00305 v.FillStyles=new MORPHFILLSTYLE[v.FillStyleCount];
00306 for(int i=0;i<v.FillStyleCount;i++)
00307 {
00308 s >> v.FillStyles[i];
00309 }
00310 return s;
00311 }
00312
00313 std::istream& lightspark::operator>>(std::istream& s, SHAPE& v)
00314 {
00315 BitStream bs(s);
00316 v.NumFillBits=UB(4,bs);
00317 v.NumLineBits=UB(4,bs);
00318 do
00319 {
00320 v.ShapeRecords.push_back(SHAPERECORD(&v,bs));
00321 }
00322 while(v.ShapeRecords.back().TypeFlag || v.ShapeRecords.back().StateNewStyles || v.ShapeRecords.back().StateLineStyle ||
00323 v.ShapeRecords.back().StateFillStyle1 || v.ShapeRecords.back().StateFillStyle0 ||
00324 v.ShapeRecords.back().StateMoveTo);
00325 return s;
00326 }
00327
00328 std::istream& lightspark::operator>>(std::istream& s, SHAPEWITHSTYLE& v)
00329 {
00330 v.FillStyles.version=v.version;
00331 v.LineStyles.version=v.version;
00332 s >> v.FillStyles >> v.LineStyles;
00333 BitStream bs(s);
00334 v.NumFillBits=UB(4,bs);
00335 v.NumLineBits=UB(4,bs);
00336 do
00337 {
00338 v.ShapeRecords.push_back(SHAPERECORD(&v,bs));
00339 }
00340 while(v.ShapeRecords.back().TypeFlag || v.ShapeRecords.back().StateNewStyles || v.ShapeRecords.back().StateLineStyle ||
00341 v.ShapeRecords.back().StateFillStyle1 || v.ShapeRecords.back().StateFillStyle0 ||
00342 v.ShapeRecords.back().StateMoveTo);
00343 return s;
00344 }
00345
00346 istream& lightspark::operator>>(istream& s, LINESTYLE2& v)
00347 {
00348 s >> v.Width;
00349 BitStream bs(s);
00350 v.StartCapStyle=UB(2,bs);
00351 v.JointStyle=UB(2,bs);
00352 v.HasFillFlag=UB(1,bs);
00353 v.NoHScaleFlag=UB(1,bs);
00354 v.NoVScaleFlag=UB(1,bs);
00355 v.PixelHintingFlag=UB(1,bs);
00356 UB(5,bs);
00357 v.NoClose=UB(1,bs);
00358 v.EndCapStyle=UB(2,bs);
00359 if(v.JointStyle==2)
00360 s >> v.MiterLimitFactor;
00361 if(v.HasFillFlag)
00362 s >> v.FillType;
00363 else
00364 s >> v.Color;
00365
00366 return s;
00367 }
00368
00369 istream& lightspark::operator>>(istream& s, LINESTYLE& v)
00370 {
00371 s >> v.Width;
00372 if(v.version==2 || v.version==1)
00373 {
00374 RGB tmp;
00375 s >> tmp;
00376 v.Color=tmp;
00377 }
00378 else
00379 s >> v.Color;
00380 return s;
00381 }
00382
00383 istream& lightspark::operator>>(istream& s, MORPHLINESTYLE& v)
00384 {
00385 s >> v.StartWidth >> v.EndWidth >> v.StartColor >> v.EndColor;
00386 return s;
00387 }
00388
00389 std::istream& lightspark::operator>>(std::istream& in, TEXTRECORD& v)
00390 {
00391 BitStream bs(in);
00392 v.TextRecordType=UB(1,bs);
00393 v.StyleFlagsReserved=UB(3,bs);
00394 if(v.StyleFlagsReserved)
00395 LOG(LOG_ERROR,_("Reserved bits not so reserved"));
00396 v.StyleFlagsHasFont=UB(1,bs);
00397 v.StyleFlagsHasColor=UB(1,bs);
00398 v.StyleFlagsHasYOffset=UB(1,bs);
00399 v.StyleFlagsHasXOffset=UB(1,bs);
00400 if(!v.TextRecordType)
00401 return in;
00402 if(v.StyleFlagsHasFont)
00403 in >> v.FontID;
00404 if(v.StyleFlagsHasColor)
00405 {
00406 RGB t;
00407 in >> t;
00408 v.TextColor=t;
00409 }
00410 if(v.StyleFlagsHasXOffset)
00411 in >> v.XOffset;
00412 if(v.StyleFlagsHasYOffset)
00413 in >> v.YOffset;
00414 if(v.StyleFlagsHasFont)
00415 in >> v.TextHeight;
00416 in >> v.GlyphCount;
00417 v.GlyphEntries.clear();
00418 for(int i=0;i<v.GlyphCount;i++)
00419 {
00420 v.GlyphEntries.push_back(GLYPHENTRY(&v,bs));
00421 }
00422
00423 return in;
00424 }
00425
00426 std::istream& lightspark::operator>>(std::istream& s, GRADRECORD& v)
00427 {
00428 s >> v.Ratio;
00429 if(v.version==1 || v.version==2)
00430 {
00431 RGB tmp;
00432 s >> tmp;
00433 v.Color=tmp;
00434 }
00435 else
00436 s >> v.Color;
00437
00438 return s;
00439 }
00440
00441 std::istream& lightspark::operator>>(std::istream& s, GRADIENT& v)
00442 {
00443 BitStream bs(s);
00444 v.SpreadMode=UB(2,bs);
00445 v.InterpolationMode=UB(2,bs);
00446 v.NumGradient=UB(4,bs);
00447 GRADRECORD gr;
00448 gr.version=v.version;
00449 for(int i=0;i<v.NumGradient;i++)
00450 {
00451 s >> gr;
00452 v.GradientRecords.push_back(gr);
00453 }
00454 sort(v.GradientRecords.begin(),v.GradientRecords.end());
00455 return s;
00456 }
00457
00458 std::istream& lightspark::operator>>(std::istream& s, FOCALGRADIENT& v)
00459 {
00460 BitStream bs(s);
00461 v.SpreadMode=UB(2,bs);
00462 v.InterpolationMode=UB(2,bs);
00463 v.NumGradient=UB(4,bs);
00464 GRADRECORD gr;
00465 gr.version=v.version;
00466 for(int i=0;i<v.NumGradient;i++)
00467 {
00468 s >> gr;
00469 v.GradientRecords.push_back(gr);
00470 }
00471 sort(v.GradientRecords.begin(),v.GradientRecords.end());
00472
00473 s.read((char*)&v.FocalPoint,2);
00474 return s;
00475 }
00476
00477 inline RGBA medianColor(const RGBA& a, const RGBA& b, float factor)
00478 {
00479 return RGBA(a.Red+(b.Red-a.Red)*factor,
00480 a.Green+(b.Green-a.Green)*factor,
00481 a.Blue+(b.Blue-a.Blue)*factor,
00482 a.Alpha+(b.Alpha-a.Alpha)*factor);
00483 }
00484
00485 void FILLSTYLE::setVertexData(arrayElem* elem)
00486 {
00487 if(FillStyleType==0x00)
00488 {
00489
00490 elem->colors[0]=1;
00491 elem->colors[1]=0;
00492 elem->colors[2]=0;
00493
00494 elem->texcoord[0]=float(Color.Red)/256.0f;
00495 elem->texcoord[1]=float(Color.Green)/256.0f;
00496 elem->texcoord[2]=float(Color.Blue)/256.0f;
00497 elem->texcoord[3]=float(Color.Alpha)/256.0f;
00498 }
00499 else if(FillStyleType==0x10)
00500 {
00501
00502 elem->colors[0]=0;
00503 elem->colors[1]=1;
00504 elem->colors[2]=0;
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535 }
00536 else
00537 {
00538 LOG(LOG_NOT_IMPLEMENTED,_("Reverting to fixed function"));
00539 elem->colors[0]=1;
00540 elem->colors[1]=0;
00541 elem->colors[2]=0;
00542
00543 elem->texcoord[0]=0.5;
00544 elem->texcoord[1]=0.5;
00545 elem->texcoord[2]=0;
00546 elem->texcoord[3]=1;
00547 }
00548 }
00549
00550 void FILLSTYLE::setFragmentProgram() const
00551 {
00552
00553
00554 struct color_entry
00555 {
00556 float r,g,b,a;
00557 };
00558
00559
00560 rt->dataTex.bind();
00561
00562 if(FillStyleType==0x00)
00563 {
00564
00565 glColor4f(1,0,0,0);
00566 glTexCoord4f(float(Color.Red)/256.0f,
00567 float(Color.Green)/256.0f,
00568 float(Color.Blue)/256.0f,
00569 float(Color.Alpha)/256.0f);
00570 }
00571 else if(FillStyleType==0x10)
00572 {
00573
00574
00575 #if 0
00576 color_entry buffer[256];
00577 unsigned int grad_index=0;
00578 RGBA color_l(0,0,0,1);
00579 int index_l=0;
00580 RGBA color_r(Gradient.GradientRecords[0].Color);
00581 int index_r=Gradient.GradientRecords[0].Ratio;
00582
00583 glColor4f(0,1,0,0);
00584
00585 for(int i=0;i<256;i++)
00586 {
00587 float dist=i-index_l;
00588 dist/=(index_r-index_l);
00589 RGBA c=medianColor(color_l,color_r,dist);
00590 buffer[i].r=float(c.Red)/256.0f;
00591 buffer[i].g=float(c.Green)/256.0f;
00592 buffer[i].b=float(c.Blue)/256.0f;
00593 buffer[i].a=1;
00594
00595 assert_and_throw(grad_index<Gradient.GradientRecords.size());
00596 if(Gradient.GradientRecords[grad_index].Ratio==i)
00597 {
00598 color_l=color_r;
00599 index_l=index_r;
00600 color_r=Gradient.GradientRecords[grad_index].Color;
00601 index_r=Gradient.GradientRecords[grad_index].Ratio;
00602 grad_index++;
00603 }
00604 }
00605
00606 glBindTexture(GL_TEXTURE_2D,rt->data_tex);
00607 glTexImage2D(GL_TEXTURE_2D,0,4,256,1,0,GL_RGBA,GL_FLOAT,buffer);
00608 #else
00609 RGBA color_r(Gradient.GradientRecords[0].Color);
00610 #endif
00611
00612
00613 glColor4f(1,0,0,0);
00614 glTexCoord4f(float(color_r.Red)/256.0f,
00615 float(color_r.Green)/256.0f,
00616 float(color_r.Blue)/256.0f,
00617 float(color_r.Alpha)/256.0f);
00618 }
00619 else
00620 {
00621 LOG(LOG_NOT_IMPLEMENTED,_("Style not implemented"));
00622 FILLSTYLE::fixedColor(0.5,0.5,0);
00623 }
00624 }
00625
00626 void FILLSTYLE::fixedColor(float r, float g, float b)
00627 {
00628
00629 rt->dataTex.bind();
00630
00631
00632
00633 glColor4f(1,0,0,0);
00634 glTexCoord4f(r,g,b,1);
00635 }
00636
00637 std::istream& lightspark::operator>>(std::istream& s, FILLSTYLE& v)
00638 {
00639 s >> v.FillStyleType;
00640 if(v.FillStyleType==0x00)
00641 {
00642 if(v.version==1 || v.version==2)
00643 {
00644 RGB tmp;
00645 s >> tmp;
00646 v.Color=tmp;
00647 }
00648 else
00649 s >> v.Color;
00650 }
00651 else if(v.FillStyleType==0x10 || v.FillStyleType==0x12 || v.FillStyleType==0x13)
00652 {
00653 s >> v.GradientMatrix;
00654 v.Gradient.version=v.version;
00655 v.FocalGradient.version=v.version;
00656 if(v.FillStyleType==0x13)
00657 s >> v.FocalGradient;
00658 else
00659 s >> v.Gradient;
00660 }
00661 else if(v.FillStyleType==0x41 || v.FillStyleType==0x42 || v.FillStyleType==0x43)
00662 {
00663 s >> v.BitmapId >> v.BitmapMatrix;
00664 }
00665 else
00666 {
00667 LOG(LOG_ERROR,_("Not supported fill style ") << (int)v.FillStyleType << _("... Aborting"));
00668 throw ParseException("Not supported fill style");
00669 }
00670 return s;
00671 }
00672
00673
00674 std::istream& lightspark::operator>>(std::istream& s, MORPHFILLSTYLE& v)
00675 {
00676 s >> v.FillStyleType;
00677 if(v.FillStyleType==0x00)
00678 {
00679 s >> v.StartColor >> v.EndColor;
00680 }
00681 else if(v.FillStyleType==0x10 || v.FillStyleType==0x12)
00682 {
00683 s >> v.StartGradientMatrix >> v.EndGradientMatrix;
00684 s >> v.NumGradients;
00685 UI8 t;
00686 RGBA t2;
00687 for(int i=0;i<v.NumGradients;i++)
00688 {
00689 s >> t >> t2;
00690 v.StartRatios.push_back(t);
00691 v.StartColors.push_back(t2);
00692 s >> t >> t2;
00693 v.EndRatios.push_back(t);
00694 v.EndColors.push_back(t2);
00695 }
00696 }
00697 else
00698 {
00699 LOG(LOG_ERROR,_("Not supported fill style ") << (int)v.FillStyleType << _("... Aborting"));
00700 }
00701 return s;
00702 }
00703
00704 GLYPHENTRY::GLYPHENTRY(TEXTRECORD* p,BitStream& bs):parent(p)
00705 {
00706 GlyphIndex = UB(parent->parent->GlyphBits,bs);
00707 GlyphAdvance = SB(parent->parent->AdvanceBits,bs);
00708 }
00709
00710 SHAPERECORD::SHAPERECORD(SHAPE* p,BitStream& bs):parent(p),TypeFlag(false),StateNewStyles(false),StateLineStyle(false),StateFillStyle1(false),
00711 StateFillStyle0(false),StateMoveTo(false),MoveDeltaX(0),MoveDeltaY(0),DeltaX(0),DeltaY(0)
00712 {
00713 TypeFlag = UB(1,bs);
00714 if(TypeFlag)
00715 {
00716 StraightFlag=UB(1,bs);
00717 NumBits=UB(4,bs);
00718 if(StraightFlag)
00719 {
00720
00721 GeneralLineFlag=UB(1,bs);
00722 if(!GeneralLineFlag)
00723 VertLineFlag=UB(1,bs);
00724
00725 if(GeneralLineFlag || !VertLineFlag)
00726 {
00727 DeltaX=SB(NumBits+2,bs);
00728 }
00729 if(GeneralLineFlag || VertLineFlag)
00730 {
00731 DeltaY=SB(NumBits+2,bs);
00732 }
00733 }
00734 else
00735 {
00736
00737 ControlDeltaX=SB(NumBits+2,bs);
00738 ControlDeltaY=SB(NumBits+2,bs);
00739 AnchorDeltaX=SB(NumBits+2,bs);
00740 AnchorDeltaY=SB(NumBits+2,bs);
00741
00742 }
00743 }
00744 else
00745 {
00746 StateNewStyles = UB(1,bs);
00747 StateLineStyle = UB(1,bs);
00748 StateFillStyle1 = UB(1,bs);
00749 StateFillStyle0 = UB(1,bs);
00750 StateMoveTo = UB(1,bs);
00751 if(StateMoveTo)
00752 {
00753 MoveBits = UB(5,bs);
00754 MoveDeltaX = SB(MoveBits,bs);
00755 MoveDeltaY = SB(MoveBits,bs);
00756 }
00757 if(StateFillStyle0)
00758 {
00759 FillStyle0=UB(parent->NumFillBits,bs)+p->fillOffset;
00760 }
00761 if(StateFillStyle1)
00762 {
00763 FillStyle1=UB(parent->NumFillBits,bs)+p->fillOffset;
00764 }
00765 if(StateLineStyle)
00766 {
00767 LineStyle=UB(parent->NumLineBits,bs)+p->lineOffset;
00768 }
00769 if(StateNewStyles)
00770 {
00771 SHAPEWITHSTYLE* ps=dynamic_cast<SHAPEWITHSTYLE*>(parent);
00772 if(ps==NULL)
00773 throw ParseException("Malformed SWF file");
00774 bs.pos=0;
00775 FILLSTYLEARRAY a;
00776 a.version=ps->FillStyles.version;
00777 bs.f >> a;
00778 p->fillOffset=ps->FillStyles.FillStyleCount;
00779 ps->FillStyles.appendStyles(a);
00780
00781 LINESTYLEARRAY b;
00782 b.version=ps->LineStyles.version;
00783 bs.f >> b;
00784 p->lineOffset=ps->LineStyles.LineStyleCount;
00785 ps->LineStyles.appendStyles(b);
00786
00787 parent->NumFillBits=UB(4,bs);
00788 parent->NumLineBits=UB(4,bs);
00789 }
00790 }
00791 }
00792
00793 std::istream& lightspark::operator>>(std::istream& stream, CXFORMWITHALPHA& v)
00794 {
00795 BitStream bs(stream);
00796 v.HasAddTerms=UB(1,bs);
00797 v.HasMultTerms=UB(1,bs);
00798 v.NBits=UB(4,bs);
00799 if(v.HasMultTerms)
00800 {
00801 v.RedMultTerm=SB(v.NBits,bs);
00802 v.GreenMultTerm=SB(v.NBits,bs);
00803 v.BlueMultTerm=SB(v.NBits,bs);
00804 v.AlphaMultTerm=SB(v.NBits,bs);
00805 }
00806 if(v.HasAddTerms)
00807 {
00808 v.RedAddTerm=SB(v.NBits,bs);
00809 v.GreenAddTerm=SB(v.NBits,bs);
00810 v.BlueAddTerm=SB(v.NBits,bs);
00811 v.AlphaAddTerm=SB(v.NBits,bs);
00812 }
00813 return stream;
00814 }
00815
00816 std::istream& lightspark::operator>>(std::istream& stream, MATRIX& v)
00817 {
00818 BitStream bs(stream);
00819 int HasScale=UB(1,bs);
00820 if(HasScale)
00821 {
00822 int NScaleBits=UB(5,bs);
00823 v.ScaleX=FB(NScaleBits,bs);
00824 v.ScaleY=FB(NScaleBits,bs);
00825 }
00826 int HasRotate=UB(1,bs);
00827 if(HasRotate)
00828 {
00829 int NRotateBits=UB(5,bs);
00830 v.RotateSkew0=FB(NRotateBits,bs);
00831 v.RotateSkew1=FB(NRotateBits,bs);
00832 }
00833 int NTranslateBits=UB(5,bs);
00834 v.TranslateX=SB(NTranslateBits,bs)/20;
00835 v.TranslateY=SB(NTranslateBits,bs)/20;
00836 return stream;
00837 }
00838
00839 std::istream& lightspark::operator>>(std::istream& stream, BUTTONRECORD& v)
00840 {
00841 assert_and_throw(v.buttonVersion==2);
00842 BitStream bs(stream);
00843
00844 UB(2,bs);
00845 v.ButtonHasBlendMode=UB(1,bs);
00846 v.ButtonHasFilterList=UB(1,bs);
00847 v.ButtonStateHitTest=UB(1,bs);
00848 v.ButtonStateDown=UB(1,bs);
00849 v.ButtonStateOver=UB(1,bs);
00850 v.ButtonStateUp=UB(1,bs);
00851
00852 if(v.isNull())
00853 return stream;
00854
00855 stream >> v.CharacterID >> v.PlaceDepth >> v.PlaceMatrix >> v.ColorTransform;
00856
00857 if(v.ButtonHasFilterList)
00858 stream >> v.FilterList;
00859
00860 if(v.ButtonHasBlendMode)
00861 stream >> v.BlendMode;
00862
00863 return stream;
00864 }
00865
00866 std::istream& lightspark::operator>>(std::istream& stream, FILTERLIST& v)
00867 {
00868 stream >> v.NumberOfFilters;
00869 v.Filters.resize(v.NumberOfFilters);
00870
00871 for(int i=0;i<v.NumberOfFilters;i++)
00872 stream >> v.Filters[i];
00873
00874 return stream;
00875 }
00876
00877 std::istream& lightspark::operator>>(std::istream& stream, FILTER& v)
00878 {
00879 stream >> v.FilterID;
00880 switch(v.FilterID)
00881 {
00882 case 0:
00883 stream >> v.DropShadowFilter;
00884 break;
00885 case 1:
00886 stream >> v.BlurFilter;
00887 break;
00888 case 2:
00889 stream >> v.GlowFilter;
00890 break;
00891 case 3:
00892 stream >> v.BevelFilter;
00893 break;
00894 case 4:
00895 stream >> v.GradientGlowFilter;
00896 break;
00897 case 5:
00898 stream >> v.ConvolutionFilter;
00899 break;
00900 case 6:
00901 stream >> v.ColorMatrixFilter;
00902 break;
00903 case 7:
00904 stream >> v.GradientBevelFilter;
00905 break;
00906 default:
00907 LOG(LOG_ERROR,_("Unsupported Filter Id ") << (int)v.FilterID);
00908 throw ParseException("Unsupported Filter Id");
00909 }
00910 return stream;
00911 }
00912
00913 std::istream& lightspark::operator>>(std::istream& stream, GLOWFILTER& v)
00914 {
00915 stream >> v.GlowColor;
00916 stream >> v.BlurX;
00917 stream >> v.BlurY;
00918 stream >> v.Strength;
00919 BitStream bs(stream);
00920 v.InnerGlow = UB(1,bs);
00921 v.Knockout = UB(1,bs);
00922 v.CompositeSource = UB(1,bs);
00923 UB(5,bs);
00924
00925 return stream;
00926 }
00927
00928 std::istream& lightspark::operator>>(std::istream& stream, DROPSHADOWFILTER& v)
00929 {
00930 stream >> v.DropShadowColor;
00931 stream >> v.BlurX;
00932 stream >> v.BlurY;
00933 stream >> v.Angle;
00934 stream >> v.Distance;
00935 stream >> v.Strength;
00936 BitStream bs(stream);
00937 v.InnerShadow = UB(1,bs);
00938 v.Knockout = UB(1,bs);
00939 v.CompositeSource = UB(1,bs);
00940 UB(5,bs);
00941
00942 return stream;
00943 }
00944
00945 std::istream& lightspark::operator>>(std::istream& stream, BLURFILTER& v)
00946 {
00947 stream >> v.BlurX;
00948 stream >> v.BlurY;
00949 BitStream bs(stream);
00950 v.Passes = UB(5,bs);
00951 UB(3,bs);
00952
00953 return stream;
00954 }
00955
00956 std::istream& lightspark::operator>>(std::istream& stream, BEVELFILTER& v)
00957 {
00958 stream >> v.ShadowColor;
00959 stream >> v.HighlightColor;
00960 stream >> v.BlurX;
00961 stream >> v.BlurY;
00962 stream >> v.Angle;
00963 stream >> v.Distance;
00964 stream >> v.Strength;
00965 BitStream bs(stream);
00966 v.InnerShadow = UB(1,bs);
00967 v.Knockout = UB(1,bs);
00968 v.CompositeSource = UB(1,bs);
00969 v.OnTop = UB(1,bs);
00970 UB(4,bs);
00971
00972 return stream;
00973 }
00974
00975 std::istream& lightspark::operator>>(std::istream& stream, GRADIENTGLOWFILTER& v)
00976 {
00977 stream >> v.NumColors;
00978 for(int i = 0; i < v.NumColors; i++)
00979 {
00980 RGBA color;
00981 stream >> color;
00982 v.GradientColors.push_back(color);
00983 }
00984 for(int i = 0; i < v.NumColors; i++)
00985 {
00986 UI8 ratio;
00987 stream >> ratio;
00988 v.GradientRatio.push_back(ratio);
00989 }
00990 stream >> v.BlurX;
00991 stream >> v.BlurY;
00992 stream >> v.Strength;
00993 BitStream bs(stream);
00994 v.InnerGlow = UB(1,bs);
00995 v.Knockout = UB(1,bs);
00996 v.CompositeSource = UB(1,bs);
00997 UB(5,bs);
00998
00999 return stream;
01000 }
01001
01002 std::istream& lightspark::operator>>(std::istream& stream, CONVOLUTIONFILTER& v)
01003 {
01004 stream >> v.MatrixX;
01005 stream >> v.MatrixY;
01006 stream >> v.Divisor;
01007 stream >> v.Bias;
01008 for(int i = 0; i < v.MatrixX * v.MatrixY; i++)
01009 {
01010 FLOAT f;
01011 stream >> f;
01012 v.Matrix.push_back(f);
01013 }
01014 stream >> v.DefaultColor;
01015 BitStream bs(stream);
01016 v.Clamp = UB(1,bs);
01017 v.PreserveAlpha = UB(1,bs);
01018 UB(6,bs);
01019
01020 return stream;
01021 }
01022
01023 std::istream& lightspark::operator>>(std::istream& stream, COLORMATRIXFILTER& v)
01024 {
01025 for (int i = 0; i < 20; i++)
01026 stream >> v.Matrix[i];
01027
01028 return stream;
01029 }
01030
01031 std::istream& lightspark::operator>>(std::istream& stream, GRADIENTBEVELFILTER& v)
01032 {
01033 stream >> v.NumColors;
01034 for(int i = 0; i < v.NumColors; i++)
01035 {
01036 RGBA color;
01037 stream >> color;
01038 v.GradientColors.push_back(color);
01039 }
01040 for(int i = 0; i < v.NumColors; i++)
01041 {
01042 UI8 ratio;
01043 stream >> ratio;
01044 v.GradientRatio.push_back(ratio);
01045 }
01046 stream >> v.BlurX;
01047 stream >> v.BlurY;
01048 stream >> v.Angle;
01049 stream >> v.Distance;
01050 stream >> v.Strength;
01051 BitStream bs(stream);
01052 v.InnerShadow = UB(1,bs);
01053 v.Knockout = UB(1,bs);
01054 v.CompositeSource = UB(1,bs);
01055 v.OnTop = UB(1,bs);
01056 UB(4,bs);
01057
01058 return stream;
01059 }
01060
01061 std::istream& lightspark::operator>>(std::istream& s, CLIPEVENTFLAGS& v)
01062 {
01063 if(pt->version<=5)
01064 {
01065 UI16 t;
01066 s >> t;
01067 v.toParse=t;
01068 }
01069 else
01070 {
01071 s >> v.toParse;
01072 }
01073 return s;
01074 }
01075
01076 bool CLIPEVENTFLAGS::isNull()
01077 {
01078 return toParse==0;
01079 }
01080
01081 std::istream& lightspark::operator>>(std::istream& s, CLIPACTIONRECORD& v)
01082 {
01083 s >> v.EventFlags;
01084 if(v.EventFlags.isNull())
01085 return s;
01086 s >> v.ActionRecordSize;
01087 LOG(LOG_NOT_IMPLEMENTED,_("Skipping ") << v.ActionRecordSize << _(" of action data"));
01088 ignore(s,v.ActionRecordSize);
01089 return s;
01090 }
01091
01092 bool CLIPACTIONRECORD::isLast()
01093 {
01094 return EventFlags.isNull();
01095 }
01096
01097 std::istream& lightspark::operator>>(std::istream& s, CLIPACTIONS& v)
01098 {
01099 s >> v.Reserved >> v.AllEventFlags;
01100 while(1)
01101 {
01102 CLIPACTIONRECORD t;
01103 s >> t;
01104 if(t.isLast())
01105 break;
01106 v.ClipActionRecords.push_back(t);
01107 }
01108 return s;
01109 }
01110
01111 ASObject* lightspark::abstract_d(number_t i)
01112 {
01113 Number* ret=getVm()->number_manager->get<Number>();
01114 ret->val=i;
01115 return ret;
01116 }
01117
01118 ASObject* lightspark::abstract_b(bool i)
01119 {
01120 return Class<Boolean>::getInstanceS(i);
01121 }
01122
01123 ASObject* lightspark::abstract_i(intptr_t i)
01124 {
01125 Integer* ret=getVm()->int_manager->get<Integer>();
01126 ret->val=i;
01127 return ret;
01128 }
01129
01130 void lightspark::stringToQName(const tiny_string& tmp, tiny_string& name, tiny_string& ns)
01131 {
01132
01133 for(int i=tmp.len()-1;i>0;i--)
01134 {
01135 if(tmp[i]==':')
01136 {
01137 assert_and_throw(tmp[i-1]==':');
01138 ns=tmp.substr(0,i-1);
01139 name=tmp.substr(i+1,tmp.len());
01140 return;
01141 }
01142 }
01143
01144 name=tmp;
01145 ns="";
01146 }
01147