Made to Order Software Corporation Logo

libsswf: SSWF -- A complete library to generate Flash animations

Version 1.8.5

Summary

SSWF, a C++ library

The SSWF library is freesoftware created to generate Flash animations without having to worry about the format specification of SWF which can be quite cumbersome!

(To download, check out the Links to libraries and tools necessary to build SSWF pages)

Especially, it hides from you the need to know whether you should use a DefineFont or DefineFont2. Depending on the information that you put in a TagFont object, the library will know which of DefineFont or DefineFont2 will be required for your movie.

The library also takes care of selecting different tags depending on the version of the output movie. For instance, the ProtectDebug tag can only be used with version 5. Before version 5, you need a Protect tag and after, you need a ProtectDebug2. Similarly, since version 8 you need a FileAttributes tag at the very beginning of the movie.

Because the available version of the player may be constrained, you can also specify what minimum and maximum version of a movie you want.

At this time SSWF supports all of version 7, except the Video and the streaming sound tags. It can also create a proper version 8 by adding the FileAttributes and the Import2 instead of Import as required by the specification. Other version 8 tags will come soon.

To get started, look inside the samples directory. It includes samples of SSWF and C++ code. The SSWF compiler can be looked at (especially the sswf_save.c++ file) as a good example on how to use the SSWF library.

SSWF is a C++ library ready to be used on your Unix system. It also includes a set of pre-compiled libraries which run under Microsoft Windows. Though, I do not offer support for Visual Studio, many have successfully compiled the library with it. So it is possible. Once in a while I do check to see whether cl likes my code. In general, it does. Note that all the code works perfectly with g++ and should work with any compatible compiler.

The packages I offer work on the following platforms:

  • Linux RedHat
  • Linux Debian
  • Linux on Power (IBM) [support till 1.7.4]
  • Linux slackware
  • IRIX 6.5
  • Mac OS/X (10.3 with fink or not)
  • MS-Windows
For the systems I support, you need absolutly no patches.

Some people out there made the library work for:

  • FreeBSD
  • Gentoo

SSWF is also a C library

Since version 1.7.5, C programmers can also use the library. It includes a sub-library which allows C programs to link against the SSWF library. It is called libsswf_c.{a,so,dylib}.

You may have a look at the C samples in:

samples/c-samples/...

The C programmers are invited to look inside the header file:

include/sswf/libsswf_c.h

This lists all the available enumerations, structures and functions one needs to create an SSWF movie. The use is very object oriented. The main thing is that all the objects need to be created on the heap and destroyed once done with them. It may be a bit tedious, but that's why you should maybe consider using C++ one day...

The following shows you how to create a TagHeader, set the minimum version and add a Sprite to it before saving the program.

 #include       <sswf/libsswf_c.h>

 ...

 struct SSWF_TagHeader  *header;
 struct SSWF_TagSprite  *sprite;
 struct SSWF_Data       *data;
 void                   *buffer;
 size_t                 size;

 header = sswf_tag_header_create();
 sswf_tag_header_set_minimum_version(header, 5);

 sprite = sswf_tag_sprite_create(sswf_tag_header_cast_tag_base(header));
 ... -- initialize the sprite

 ... -- add other objects

 data = sswf_data_create();
 sswf_tag_header_save(header, data);
 sswf_data_read(data, &buffer, &size);
 f = fopen("a.swf", "w");
 fwrite(buffer, 1, size, f);
 fclose(f);

 sswf_tag_header_destroy(header);

As you can see, this is pretty straight forward, just somewhat more text to type (feel free to copy & paste!)

The naming convention is as follow:

  • Objects
Objects get SSWF_ prepended. These are all viewed as opaque structures. You only can use pointers to objects.

  • Enumerations
The enumerations get sswf_ prepended. In C, they are not in attached to any specific object so you can use them directly. Since their name include the object and/or what they are supposed to be used for, there is no name clash.

  • Structures
Like enumerations, structures get sswf_ prepended. These structures are used to pass more complex data to some objects. Like the enumerations, structures are not attached to any specific object.

All of these structures can be put on the stack. You are responsible to initialize them properly (just like their counter part in C++).

  • Functions
Just as expected, all the functions cannot be attached to a specific object in C. Thus, the name of the function includes the name of the object in lower case after the prepended 'sswf_'. Then follows the name of the function as found in the corresponding object.

The cpp-to-c generator creates several special functions to (1) create, (2) destroy and (3) cast the object pointers. The cast is very important since C casting can result in the wrong C++ pointer.

The parameters to each function is either kept the same (standard C type such as int, char, etc.), tweaked to work in C (i.e. the C++ library makes use of the type bool which is transformed to an int in the C library.) or, for objects, enumerations and structures, are renamed with their C name.

The result looks like this:

 <return type> sswf_<class name>_<function>(<parameters>);

I suggest you look at a few object in the C and the C++ headers to compare. It is rather easy to see what happens to the names.

The C++ constructor is transformed into:

 void sswf_<class name>_create(<parameters>);

The C++ destructor is transformed into:

 void sswf_<class name>_destroy(ClassName *ojbect);

The casts (which are only static casts in C++, thought I have to use reinterpret from the C pointer to the C++ pointer and vice versa!):

 <inherited class name>
              sswf_<class name>_cast_<inherited class name>(<class name>);

Once you understand how this works, you can read the C++ documentation even when you are working with the C library. In the first code sample, I use sswf_tag_sprite_create() which is the Constructor of the sswf::TagSprite object.

IMPORTANT NOTE:
The tags will delete all the memory that they allocate in a totally automated way. However, in C you will need to explicitly delete objects (with their sswf_..._destroy() corresponding function.)

Other software

I also wrote and offer a few other software as defined here on the Other software by the same author page.


Generated on Wed Mar 18 15:13:55 2009 for libsswf by  doxygen 1.5.5