Click here to Skip to main content
13,095,135 members (80,388 online)
Click here to Skip to main content

Stats

140.6K views
6.2K downloads
92 bookmarked
Posted 27 Jun 2006

SWFLIB - a free Flash authoring library

, 18 Jul 2006
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)

Share

About the Author

darkoman
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.

You may also be interested in...

Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 18 Jul 2006
Article Copyright 2006 by darkoman
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid