Click here to Skip to main content
Click here to Skip to main content
 

SWFLIB - a free Flash authoring library

By , 18 Jul 2006
 
samplemovie.zip
SampleMovie.swf
swflibreference.zip
SWFLIB - Programmers Reference.pdf
swflib_library.zip
swflib.dsp
swflib.dsw
swflib_reference.zip
SWFLIB - Programmers Reference.pdf
swflib_samplemovies.zip
SWF Sample Movies
Sample1.swf
Sample2.swf
Sample3.swf
Sample4.swf
Sample5.swf
swflib_testproject.zip
bm128.jpg
res
SWFLIB TestProject.ico
Sample1.swf
Sample2.swf
Sample3.swf
Sample4.swf
Sample5.swf
SWFLIB TestProject.clw
SWFLIB TestProject.dsp
SWFLIB TestProject.dsw
// 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 use 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)

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.

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