Click here to Skip to main content
15,886,362 members
Articles / Desktop Programming / MFC

SWFLIB - a free Flash authoring library

Rate me:
Please Sign up or sign in to vote.
4.75/5 (26 votes)
18 Jul 2006CPOL2 min read 169.2K   6.5K   93  
An article on a free Flash authoring library.
// SWFBitmap.cpp: implementation of the CSWFBitmap class.
//
//////////////////////////////////////////////////////////////////////

#include "SWFBitmap.h"


CSWFBitmap::CSWFBitmap(USHORT nID, UCHAR* filename)
{
	// Init members
	m_ObjectType = SWF_OBJECT_TYPE_BITMAP;
	m_SWFStream = NULL;
	m_SWFStreamLength = 0;
	m_ID = nID;
	m_DefineBits.Header.TagCodeAndLength = (21 << 6) | 0x003F;
	m_DefineBits.CharacterID = nID;

	FILE* image = fopen((char*)filename, "rb");
	if (image != NULL)
	{
		// Calculate DefineBitsJPEG2 tag size
		int fileLength = filelength(fileno(image));
		UCHAR* pBuffer = new UCHAR[fileLength];
		fread(pBuffer, 1, fileLength, image);

		m_DefineBits.Header.Length = fileLength + 8;
		m_SWFStreamLength = sizeof(SWF_DEFINE_BITS_JPEG2_TAG) + (m_DefineBits.Header.Length-2);

		m_SWFStream = (UCHAR*)malloc(m_SWFStreamLength*sizeof(UCHAR));
		memset(m_SWFStream, 0, m_SWFStreamLength);

		// Write header and data
		UCHAR JPEGEndFlag[2] = {0xFF, 0xD9};
		UCHAR JPEGStartFlag[2] = {0xFF, 0xD8};
		memcpy(m_SWFStream, &m_DefineBits, sizeof(SWF_DEFINE_BITS_JPEG2_TAG));
		memcpy(m_SWFStream+sizeof(SWF_DEFINE_BITS_JPEG2_TAG), &JPEGEndFlag, 2);
		memcpy(m_SWFStream+sizeof(SWF_DEFINE_BITS_JPEG2_TAG)+2, &JPEGStartFlag, 2);
		memcpy(m_SWFStream+sizeof(SWF_DEFINE_BITS_JPEG2_TAG)+4, pBuffer, fileLength);
		memcpy(m_SWFStream+sizeof(SWF_DEFINE_BITS_JPEG2_TAG)+4+fileLength, &JPEGEndFlag, 2);
		fclose(image);
		delete pBuffer;
	}
}

CSWFBitmap::~CSWFBitmap()
{
	if (m_SWFStream != NULL)
	{
		delete m_SWFStream;
		m_SWFStream = NULL;
	}
}

UCHAR* CSWFBitmap::BuildSWFStream()
{
	return m_SWFStream;
}

int CSWFBitmap::GetSWFStreamLength()
{
	return m_SWFStreamLength;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Elektromehanika d.o.o. Nis
Serbia Serbia
He has a master degree in Computer Science at Faculty of Electronics in Nis (Serbia), and works as a C++/C# application developer for Windows platforms since 2001. He likes traveling, reading and meeting new people and cultures.

Comments and Discussions