Made to Order Software Corporation Logo

encoding

Alan Turing Centenary

Starting tomorrow, Jun 23, 2012, many countries are to celebrate the centeray birth year of Alan Turing. Alan created the Turing machine concepts and formalized algorithm and computation that are now in use in all our computers (including your portable phone and your electronic watch.)

He actually participated to the creation of the first electronic computer during second world war in England. His algorithms and knowledge of cryptography gave him the necessary skills to crack the encoding of the German Enigma Machine (a form of printer that would encode messages with a level of complexity too ...

VideoFrame

Tag Info
Tag Number: 
61
Tag Type: 
Define
Tag Flash Version: 
6
Brief Description: 

Show the specified video frame of a movie.

Tag Structure: 
struct swf_startsound {
	swf_tag			f_tag;		/* 61 */
	unsigned short		f_video_id_ref;
	unsigned short		f_frame;
	unsigned char		f_video_data[variable size];
};

The VideoFrame tag is used to render one frame. It includes the data of exactly one video frame to be drawn on the screen.

The f_object_id_ref parameter is a reference to a DefineVideoStream.

DefineEditText

Tag Info
Tag Number: 
37
Tag Type: 
Define
Tag Flash Version: 
4
Brief Description: 

An edit text enables the end users to enter text in a Flash window.

Tag Structure: 
struct swf_defineedittext {
	swf_tag			f_tag;		/* 37 */
	unsigned short		f_edit_id;
	swf_rect		f_rect;
	unsigned		f_edit_has_text : 1;
	unsigned		f_edit_word_wrap : 1;
	unsigned		f_edit_multiline : 1;
	unsigned		f_edit_password : 1;
	unsigned		f_edit_readonly : 1;
	unsigned		f_edit_has_color : 1;
	unsigned		f_edit_has_max_length : 1;
	unsigned		f_edit_has_font : 1;
	if(version >= 6) {
		unsigned		f_edit_reserved : 1;
		unsigned		f_edit_auto_size : 1;
	}
	else {
		unsigned		f_edit_reserved : 2;
	}
	unsigned		f_edit_has_layout : 1;
	unsigned		f_edit_no_select : 1;
	unsigned		f_edit_border : 1;
	unsigned		f_edit_reserved : 1;
	unsigned		f_edit_html : 1;
	unsigned		f_edit_use_outlines : 1;
	if(f_edit_has_font) {
		unsigned short		f_edit_font_id_ref;
		unsigned short		f_edit_font_height;
	}
	if(f_edit_has_color) {
		swf_rgba		f_edit_color;
	}
	if(f_edit_has_max_length) {
		unsigned short		f_edit_max_length;
	}
	if(f_edit_has_layout) {
		unsigned char		f_edit_align;
		unsigned short		f_edit_left_margin;
		unsigned short		f_edit_right_margin;
		signed short		f_edit_indent;
		signed short		f_edit_leading;
	}
	string			f_edit_variable_name;
	if(f_edit_has_text) {
		string			f_edit_initial_text;
	}
};

Additional interactivity has been added in V4.0 of the SWF format. This is given by the use of edit boxes offering the end users a way to enter text as if the SWF movie was in fact an interactive form.

The text is defined in a variable (accessible in action scripts). It can be dynamically assigned and retrieved. It is legal to have an empty string as the variable name (not dynamically accessible).

Since version 8, the text drawn by a DefineEditText tag can be tweaked by adding a CSMTextSettings tag.

The f_edit_word_wrap flag will be set to true (1) in order to have words going beyond the ...

Appendix A — The geometry in SWF — Edges

Edges are used to define a shape vector based and also coordinates where images need to be drawn. The edges are always coordinates from where ever your last point was to where ever you want the next point to be (a little like a turtle in LOGO).

DefineSound

Tag Info
Tag Number: 
14
Tag Type: 
Define
Tag Flash Version: 
2
Brief Description: 

Declare a sound effect. This tag defines sound samples that can later be played back using either a StartSound or a DefineButtonSound. Note that the same DefineSound block can actually include multiple sound files and only part of the entire sound can be played back as required.

Tag Structure: 
struct swf_definesound {
	swf_tag			f_tag;		/* 14 */
	unsigned short		f_sound_id;
	unsigned		f_sound_format : 4;
	unsigned		f_sound_rate : 2;
	unsigned		f_sound_is_16bits : 1;
	unsigned		f_sound_is_stereo : 1;
	unsigned long		f_sound_samples_count;
	unsigned char		f_sound_data[<variable size>];
};

A DefineSound tag declares a set of samples of a sound effect or a music.

The sound samples can be compressed or not, stereo or not and 8 or 16 bits. The different modes are not all available in version 2, although the same tag is used in newer versions with additional capabilities.

The f_sound_is_16bits is always set to 1 (16bits samples) if the samples are compressed (neither Rawnor Uncompressed).

The f_sound_rate represents the rate at which the samples are defined. The rate at which it will be played on the target computers may differ. The following equation can be used to determine the ...

DefineFontInfo

Tag Info
Tag Number: 
13
Tag Type: 
Define
Tag Flash Version: 
1
Brief Description: 

Information about a previously defined font. Includes the font style, a map and the font name.

Tag Structure: 
struct swf_definefontinfo {
	swf_tag			f_tag;		/* 13 or 62 */
	unsigned short		f_font_info_id_ref;
	unsigned char		f_font_info_name_length;
	unsigned char		f_font_info_name[f_name_length];
	if(version >= 7 && f_tag.f_tag == DefineFontInfo2) {
		unsigned		f_font_info_reserved : 2;
		unsigned		f_font_info_small_text : 1;
		unsigned		f_font_info_reserved : 2;
	}
	else if(version >= 6 && f_tag.f_tag == DefineFontInfo2) {
		unsigned		f_font_info_reserved : 5;
	}
	else {
		unsigned		f_font_info_reserved : 2;
		unsigned		f_font_info_unicode : 1;
		unsigned		f_font_info_shiftjis : 1;
		unsigned		f_font_info_ansii : 1;
	}
	unsigned		f_font_info_italic : 1;
	unsigned		f_font_info_bold : 1;
	unsigned		f_font_info_wide : 1;	/* always 1 in v6.x+ */
	if(version >= 6 && f_tag.f_tag == DefineFontInfo2) {
		unsigned char		f_font_info_language;
	}
	if(f_font_info_wide) {
		unsigned short		f_font_info_map[f_font_glyphs_count];
	}
	else {
		unsigned char		f_font_info_map[f_font_glyphs_count];
	}
};

A DefineFontInfo tag will be used to complete the definition of a DefineFont tag. It uses the exact same identifier (f_font_info_id_ref = f_font_id). You must have the corresponding font definition appearing before the DefineFontInfo since it will use the number of glyphs defined in the DefineFont to know the size of the map definition in the DefineFontInfo tag.

When it looks like it perfectly matches an existing system font, the plugin may use that system font (as long as no rotation is used, it will work fine.) It is also possible to force the use of the system font by declaring an empty ...

JPEGTables

Tag Info
Tag Number: 
8
Tag Type: 
Define
Tag Flash Version: 
1
Brief Description: 

Define the tables used to compress/decompress all the SWF 1.0 JPEG images (See also DefineBitsJPEG.)

Tag Structure: 
struct swf_jpegtables {
	swf_tag			f_tag;		/* 8 */
	unsigned char		f_encoding_tables[<variable size>];
};

The JPEGTables tag is used to define the encoding tables of the JPEG images defined using the DefineBitsJPEG tag.

There can be only one JPEGTables tag in a valid SWF file. And it should be defined before any DefineBitsJPEG tag.

The content of this tag is the JPEG encoding tables defined by the 0xFF 0xDB and 0xFF 0xC4 tags. The f_encoding_tables buffed must start with 0xFF 0xD8 (SOI) and end with 0xFF 0xD9 (EOI).

Note that the player of SWF better enforces the correctness of this tag since version 8.

DefineBitsJPEG

Tag Info
Tag Number: 
6
Tag Type: 
Define
Tag Flash Version: 
1
Brief Description: 

Define a JPEG bit stream.

Tag Structure: 
struct swf_definebitsjpeg {
	swf_long_tag		f_tag;		/* 6, 21, 35 or 90 */
	unsigned short		f_image_id;
	if(f_tag == DefineBitsJPEG3 + f_tag == DefineBitsJPEG4) {
		/* sizeof(f_encoding_tables) + sizeof(f_image_data) + 2 when JPEG4 */
		unsigned long		f_offset_to_alpha;
	}
	if(f_tag == DefineBitsJPEG4) {
		unsigned short fixed	f_deblocking_filter_parameter;
	}
	if(f_tag != DefineBitsJPEG) {
		/* when DefineBitsJPEG, use JPEGTables instead */
		unsigned char		f_encoding_tables[<variable size>];
	}
	unsigned char		f_image_data[<variable size>];
	if(f_tag == DefineBitsJPEG3 || f_tag == DefineBitsJPEG41) {
		unsigned char		f_alpha[<variable size>];
	}
};
  • 1. JPEG4 optionally accepts the f_alpha field. [To be verified]

These tags define an image saved using the JPEG compression scheme.

DefineBitsJPEG (V1.0) does not include the encoding tables which are defined in the unique JPEGTables tag instead. All the DefineBitsJPEG of an SWF file use the only JPEGTables tag. Yes... This means you need a tool that is capable of reusing the same tables over and over again to make sure that all your DefineBitsJPEGs work properly (or use it just once.)

The other tags incorporate their own version of the JPEG encoding tables.

The DefineBitsJPEG3 and DefineBitsJPEG4 support an alpha channel bit plane (8 bits.) ...

Change the encoding of a Postgres database

Ever wondered how you could change the encoding of one of your Postgres database?

I have had that problem several times, and in most cases people tell you to:

  1. Dump your database, may have to use –encoding on the command line
  2. Drop the existing database (or rename it)
  3. Create a new database with the proper encoding
  4. Restore the database

The problem is that there is no support for altering the encoding of a database. The ALTER DATABASE does not include that option. And since it should be really rare, it makes sense.

Now, there is an easier way ...