A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 28

Thread: C++ SWF Generator

  1. #1
    Senior Member
    Join Date
    Jul 2008
    Posts
    128

    C++ SWF Generator

    I am trying to write a C++ program that I can call that will grab images and make them into an animation. I was wondering if anyone would be able to give me an example on how SWF is formated and how to set tags to help me with this.

  2. #2
    Lifetime Friend of Site Staff Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    http://sourceforge.net/projects/ming

    The other thing to look at is the SWF File Format documentation from Adobe.
    Last edited by Northcode; 07-17-2008 at 03:13 PM.

  3. #3
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Thanks a lot. I have been reading the SWF file format but it helps me more if I can see what they are talking about. But the ming files should help a lot thanks again.

  4. #4
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Does anyone know if the RECORDHEADER wants the length in bits or in bytes?

  5. #5
    Lifetime Friend of Site Staff Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    The lower 6 bits of the RECORDHEADER specify the number of BYTES in the tag (up to 63 bytes). If the tag length is set to 0x3f (all 1's) then the RECORDHEADER is followed by a 32bit field that specifies the length of the tag (up to 4GB).

  6. #6
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    thanks again.

  7. #7
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Sorry but I have another question. When it comes to reading in jpegs to create the jpegtable I know to read between the SOI and EOI markers. But when it comes to define bits what am I reading in? The entire file with the encoding table? or am I suppose to parse that out and just use the rest of the file as my data for the definebits tag?

  8. #8
    Lifetime Friend of Site Staff Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    You've got me there... I'd have to RTFM myself to figure that one out

  9. #9
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Would you know a site or documentation that I could read that might help me there?

  10. #10
    Lifetime Friend of Site Staff Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    There's a PHP tool called jpg2swf that converts JPEG images to SWF files. It's supposed to be standalone so it should have all the info you're looking for. If you know C++ you can probably grok PHP well enough to figure out what's going on.

  11. #11
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Once again thanks

  12. #12
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Ok so I was reading through the code that he wrote and I was stumped lol.

    Maybe you might be able to tell me whats going on.

    // TAG SHOWFRAME
    // id (1) and length (0)
    $swf.=chr(64);
    $swf.=chr(0);

    I get this part. He is using 64 because the way swf files are written out.
    since SHOWFRAME's id is 1 in binary that gives us:

    00000001
    since all headers are 2bytes (16bits) the high 10 bits are the id and the
    low 6 order bits are the length we have to shift our bits.
    so 00000001 << 6 gives us 01000000 which gives us 64. BINGO.

    But here comes the confusing part.

    // TAG PLACEOBJECT
    // id (26) and length (6)
    $swf.=chr(134);
    $swf.=chr(6);

    If we do the same thing here: id = 26 so that gives us:
    00011010 then we shift it by 6 again giving us....
    00000110 10000000
    then we tack on 6 which is 00000110.
    so lets do some bit arithmetic :P

    00000110 10000000
    | 00000000 00000110
    ----------------------
    00000110 10000110
    6 134

    so his code to my understanding should be:

    $swf.=chr(6);
    $swf.=chr(134);

    but his is reversed and I have no clue why.

    At first I thought that it might be because of flashes endianess
    being little endian.

    but that would just cause the bits to be moved around not swaping
    entire bytes. Also if that was the case why didn't he move the bytes
    around in the other part of his code?

  13. #13
    Lifetime Friend of Site Staff Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    Endianness can refer to the bit-order, but more commonly it refers to byte ordering. Boing back to the original example of the RECORDHEADER, the SWF File format SDK says this...

    The TagCodeAndLength field is a two-byte word, not a bit field of 10 bits followed by a bit field of 6 bits. The little-endian byte ordering of a SWF file makes these two layouts different.

  14. #14
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    So switching entire bytes around isn't uncommon? But why would he not be consistent with it?

  15. #15
    Lifetime Friend of Site Staff Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    It depends on whether the layout specifies two bytes or a short (16bit) struct. You don't change the byte order for individual bytes, but the bytes in a short would be reversed.

  16. #16
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Hey Tim I need your genius again :P. I'm trying to write out a RECT struct set up how its set up in an swf file.

    nbits[5] 5 bits....
    xmin[n] n bits....
    xmax[n] n bits....
    ymin[n] n bits....
    ymax[n] n bits....

    Only problem is you can't write out bits in C++ only bytes. Do you know of a way it can be done?

  17. #17
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    Is there some type of padding header that I don't know about?

  18. #18
    Lifetime Friend of Site Staff Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    You have to virtualize the bit stream you want to write. Instead of writing out a bit at a time, you build up a bit string in memory and only write it out when you have a full byte's worth of data. There are classes out there you can google that will help you with this if you don't want to write your own.

  19. #19
    Senior Member
    Join Date
    Jul 2008
    Posts
    128
    I was reading in the appendix A of the SWF specs pdf and I noticed they said that structures are padded to the byte so when reading in the next dword we don't have to worry about being in another byte. So am I suppose to byte align all of the tags as well?

  20. #20
    Lifetime Friend of Site Staff Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    Each struct is padded out to the nearest full byte (i.e. extra bits at the end of the struct that you can ignore) so when you start reading the next struct or member from the TAG it should start on a byte boundary.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center