+#ifndef BITMAP_H\r
+#define BITMAP_H\r
+\r
+/****************************************************************************************/\r
+/* Bitmap.h */\r
+/* */\r
+/* Author: Charles Bloom */\r
+/* Description: Abstract Bitmap system */\r
+/* */\r
+/* The contents of this file are subject to the Genesis3D Public License */\r
+/* Version 1.01 (the "License"); you may not use this file except in */\r
+/* compliance with the License. You may obtain a copy of the License at */\r
+/* http://www.genesis3d.com */\r
+/* */\r
+/* Software distributed under the License is distributed on an "AS IS" */\r
+/* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See */\r
+/* the License for the specific language governing rights and limitations */\r
+/* under the License. */\r
+/* */\r
+/* The Original Code is Genesis3D, released March 25, 1999. */\r
+/* Genesis3D Version 1.1 released November 15, 1999 */\r
+/* Copyright (C) 1999 WildTangent, Inc. All Rights Reserved */\r
+/* */\r
+/****************************************************************************************/\r
+\r
+#include "BaseType.h"\r
+#include "PixelFormat.h"\r
+#include "VFile.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/***********************************************************************************/\r
+\r
+typedef struct geBitmap geBitmap;\r
+typedef struct geBitmap_Palette geBitmap_Palette;\r
+\r
+typedef struct geBitmap_Info\r
+{\r
+ int Width;\r
+ int Height;\r
+ int Stride; // stride is in *pixels* ; it is the step to the next line : Stride >= Width\r
+ gePixelFormat Format;\r
+ int MinimumMip; //*including* minimumMip == 0 often\r
+ int MaximumMip; //*including* maximumMip == nummips-1\r
+ geBoolean HasColorKey;\r
+ uint32 ColorKey; // meaningless unless HasColorKey ; the ColorKey is a Pixel in Format\r
+ geBitmap_Palette * Palette;\r
+} geBitmap_Info;\r
+\r
+/***********************************************************************************/ \r
+// Bitmap methods\r
+\r
+// see a big comment at the end of this file\r
+\r
+/************************************************************************/\r
+\r
+GENESISAPI geBitmap * GENESISCC geBitmap_Create(int Width, int Height, int MipCount, gePixelFormat Format ); \r
+GENESISAPI void GENESISCC geBitmap_CreateRef(geBitmap *Bmp);\r
+\r
+GENESISAPI geBitmap * GENESISCC geBitmap_CreateFromInfo(const geBitmap_Info * pInfo);\r
+\r
+GENESISAPI geBitmap * GENESISCC geBitmap_CreateFromFile( geVFile *F );\r
+GENESISAPI geBitmap * GENESISCC geBitmap_CreateFromFileName(const geVFile *BaseFS,const char *Name);\r
+GENESISAPI geBoolean GENESISCC geBitmap_WriteToFile( const geBitmap *Bmp, geVFile *F );\r
+GENESISAPI geBoolean GENESISCC geBitmap_WriteToFileName(const geBitmap * Bmp,const geVFile *BaseFS,const char *Name);\r
+ // BaseFS is not really const if it is a virtual file;\r
+ // it *is* const if it is a dos directory\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_Destroy(geBitmap **Bmp);\r
+ // returns whether Bmp was actually destroyed : not success/failure\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_GetInfo(const geBitmap *Bmp, geBitmap_Info *Info, geBitmap_Info *SecondaryInfo);\r
+ //LockForWrite returns data in Info's format\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_Blit(const geBitmap *Src, int SrcPositionX, int SrcPositionY,\r
+ geBitmap *Dst, int DstPositionX, int DstPositionY,\r
+ int SizeX, int SizeY );\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_BlitMip(const geBitmap * Src, int SrcMip, geBitmap * Dst, int DstMip );\r
+ // don't use this with Src == Dst, use UpdateMips instead !\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_BlitBitmap(const geBitmap * Src, geBitmap * Dst);\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_BlitBestMip(const geBitmap * Src, geBitmap * Dst);\r
+ // blits the largest mip from Src that fits in Dst\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_LockForRead( // a non-exclusive lock\r
+ const geBitmap * Bmp,\r
+ geBitmap ** Target,\r
+ int MinimumMip,\r
+ int MaximumMip,\r
+ gePixelFormat Format,\r
+ geBoolean RespectColorKey,\r
+ uint32 ColorKey);\r
+ // not really const, stores lock-count, but *data* is const\r
+ // will do a format conversion!\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_LockForReadNative(\r
+ const geBitmap * Bmp,\r
+ geBitmap ** Target,\r
+ int MinimumMip,\r
+ int MaximumMip);\r
+ // lock for read in a format that gaurantee no conversions\r
+ // then do GetInfo on the locks to see what you have!\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_LockForWrite( // an exclusive lock\r
+ geBitmap * Bmp,\r
+ geBitmap ** Target,\r
+ int MinimumMip,\r
+ int MaximumMip);\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_LockForWriteFormat(\r
+ geBitmap * Bmp,\r
+ geBitmap ** Target,\r
+ int MinimumMip,\r
+ int MaximumMip,\r
+ gePixelFormat Format);\r
+ // Format must be one of the two returned in GetInfo !!\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_UnLock(geBitmap *Bmp); // must be done on All locked mips\r
+GENESISAPI geBoolean GENESISCC geBitmap_UnLockArray(geBitmap **Locks,int Size);\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_SetFormat(geBitmap *Bmp, \r
+ gePixelFormat NewFormat, \r
+ geBoolean RespectColorKey, uint32 ColorKey,\r
+ const geBitmap_Palette * Palette);\r
+ // _SetFormat may cause you to lose color information!\r
+ // SetFormat does a conversion!\r
+ // if NewFormat is palettized and Palette is NULL, we create a palette for the bitmap!\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_SetFormatMin(geBitmap *Bmp,gePixelFormat NewFormat);\r
+ // the Min version keeps colorkey & palette from the old format\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_SetColorKey(geBitmap *Bmp, geBoolean HasColorKey, uint32 ColorKey, geBoolean Smart);\r
+ // SetColorKey discards old colorkey information!\r
+ // does not do a conversion (changes the colorkey in the current data\r
+ // if 'Smart' is on, we don't set HasColorKey to true unless it is actually used!\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_GetAverageColor(const geBitmap *Bmp,int *pR,int *pG,int *pB);\r
+ // tells you the average color; computes it and caches it out\r
+\r
+GENESISAPI geBitmap_Palette * GENESISCC geBitmap_GetPalette(const geBitmap *Bmp);\r
+GENESISAPI geBoolean GENESISCC geBitmap_SetPalette(geBitmap *Bmp, const geBitmap_Palette *Palette);\r
+ // _SetPal tries to _CreateRef your Palette, so no copy occurs & palettes may be shared\r
+ // you may _Destroy() palette after using it to set (though its bits may not be freed)\r
+ // (hence Palette is *not* const)\r
+ // Warning : SetPalette on any mip changes the palette of ALL mips !\r
+ // see Palette note at _UnLock\r
+ // _SetPal destroys the bitmap's original palette and refs the new one, \r
+ // so if you setpal with the bitmap's palette, there is no net change in ref counts (good!)\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_HasAlpha(const geBitmap * Bmp);\r
+ // returns true if bitmap has *any* type of alpha\r
+\r
+GENESISAPI geBitmap * GENESISCC geBitmap_GetAlpha(const geBitmap *Bmp);\r
+GENESISAPI geBoolean GENESISCC geBitmap_SetAlpha(geBitmap *Bmp, const geBitmap *AlphaBmp);\r
+ // we Ref the AlphaBmp, so you may destroy it after calling Set()\r
+ // it may be NULL\r
+ // there's only one Alpha per bitmap (for the top Mip) right now\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_SetGammaCorrection(geBitmap *Bmp,geFloat Gamma,geBoolean Apply);\r
+ // this Gamma does not change the *original* (system/secondary) bits\r
+ // it only affects the appearance when drawn\r
+ // note : if you write to the gamma corrected bits, you must gamma correct manually if you\r
+ // wish to fit in smoothly with the previous data\r
+ // warning : if you use this function with many different gammas, performance will suffer!\r
+ // use one global gamma for all bitmaps! try to let the engine manage gamma for you,\r
+ // via geEngine_SetGamma !\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_SetPreferredFormat(geBitmap *Bmp,gePixelFormat Format);\r
+GENESISAPI gePixelFormat GENESISCC geBitmap_GetPreferredFormat(const geBitmap *Bmp);\r
+\r
+GENESISAPI void * GENESISCC geBitmap_GetBits(geBitmap *Bmp); // works only on a Lock()\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_RefreshMips(geBitmap *Bmp); // rebuilds mips; *tries* to be smart & not overwrite manually-fixed mips\r
+ // RefreshMips does *not* build mips that don't exist\r
+GENESISAPI geBoolean GENESISCC geBitmap_UpdateMips(geBitmap *Bmp,int SourceMip,int TargetMip); \r
+ // will create the target if it doesn't exist;\r
+ // will overwrite manually-fixed mips!\r
+GENESISAPI geBoolean GENESISCC geBitmap_SetMipCount(geBitmap *Bmp,int Count);\r
+ // creates or destroys to match the new count\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_ClearMips(geBitmap *Bmp); // Destroy all mips (except the first) !\r
+ // use with care! this is not polite!\r
+\r
+// Shortcuts\r
+GENESISAPI int GENESISCC geBitmap_Width(const geBitmap *Bitmap);\r
+GENESISAPI int GENESISCC geBitmap_Height(const geBitmap *Bitmap);\r
+GENESISAPI uint32 GENESISCC geBitmap_MipBytes(const geBitmap * Bitmap,int mip);\r
+\r
+/**\r
+*\r
+* if Bitmap is a lock for read, functions that modify it return failure\r
+* if Bitmap is a lock for write, functions that modify it attempt to\r
+* modify the owner of the lock\r
+*\r
+* warning : if you lock multiple mips for write, and then modify one of the mips\r
+* (such as via SetPalette) it may affect the owner and all sibling mips!\r
+* doing different SetPalettes with different palettes on different locked mips \r
+* has undefined behavior!\r
+*\r
+**/\r
+\r
+#ifdef _DEBUG\r
+\r
+GENESISAPI uint32 GENESISCC geBitmap_Debug_GetCount(void);\r
+\r
+GENESISAPI uint32 GENESISCC geBitmap_Debug_GetRefs(void);\r
+ // assert this is zero before you shutdown !\r
+\r
+#endif\r
+\r
+/***********************************************************************************/\r
+\r
+typedef enum\r
+{\r
+ GE_BITMAP_STREAMING_ERROR=0,\r
+ GE_BITMAP_STREAMING_NOT,\r
+ GE_BITMAP_STREAMING_STARTED,\r
+ GE_BITMAP_STREAMING_IDLE,\r
+ GE_BITMAP_STREAMING_CHANGED,\r
+ GE_BITMAP_STREAMING_DATADONE,\r
+ GE_BITMAP_STREAMING_DONE,\r
+} geBitmap_StreamingStatus;\r
+\r
+GENESISAPI geBitmap_StreamingStatus GENESISCC geBitmap_GetStreamingStatus(const geBitmap *Bmp);\r
+\r
+ /** on a file which is streaming, the sequence of returns looks like :\r
+\r
+ GE_BITMAP_STREAMING_IDLE\r
+ GE_BITMAP_STREAMING_CHANGED\r
+ GE_BITMAP_STREAMING_IDLE\r
+ GE_BITMAP_STREAMING_IDLE\r
+ GE_BITMAP_STREAMING_CHANGED\r
+ ...\r
+ GE_BITMAP_STREAMING_DONE\r
+ GE_BITMAP_STREAMING_NOT\r
+ GE_BITMAP_STREAMING_NOT\r
+ GE_BITMAP_STREAMING_NOT\r
+ ...\r
+\r
+ Status >= GE_BITMAP_STREAMING_STARTED means streaming has started & is in progress\r
+\r
+ the user should never see _STARTED or _DATADONE\r
+\r
+ ***/\r
+\r
+/***********************************************************************************/\r
+\r
+// palette methods :\r
+\r
+GENESISAPI geBitmap_Palette * GENESISCC geBitmap_Palette_Create(gePixelFormat Format,int Size);\r
+\r
+GENESISAPI geBitmap_Palette * GENESISCC geBitmap_Palette_CreateCopy(const geBitmap_Palette *Palette);\r
+\r
+GENESISAPI geBitmap_Palette * GENESISCC geBitmap_Palette_CreateFromFile(geVFile *F);\r
+\r
+GENESISAPI geBitmap_Palette * GENESISCC geBitmap_Palette_CreateFromBitmap(geBitmap * Bmp,geBoolean Slow);\r
+ // does GetPalette, and if NULL, then\r
+ // it create an optimal palette for a\r
+ // non-palettized bitmap\r
+ // (this is a create, you must destroy later!)\r
+ // put Slow == TRUE for higher quality & slower\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_Palette_SortColors(geBitmap_Palette * P,geBoolean Slower);\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_Palette_CreateRef(geBitmap_Palette *Palette);\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_Palette_Destroy(geBitmap_Palette ** ppPalette);\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_Palette_WriteToFile(const geBitmap_Palette *Palette,geVFile *F);\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_Palette_SetFormat(geBitmap_Palette * Palette,gePixelFormat Format);\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_Palette_Copy(const geBitmap_Palette * Src,geBitmap_Palette * Target);\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_Palette_GetInfo(const geBitmap_Palette *P,geBitmap_Info *Into);\r
+ // get the info as if it were a bitmap; Into->Height == 1\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_Palette_Lock(geBitmap_Palette *Palette, void **pBits, gePixelFormat *pFormat,int *pSize);\r
+ // pFormat & pSize are optional\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_Palette_UnLock(geBitmap_Palette *Palette);\r
+ // palette unlock does NOT notify the bitmap that the palette has changed.\r
+ // call Bitmap_SetPalette() with the same palette pointer \r
+ // to tell the bitmap that it must to some processing\r
+ // (don't worry, it won't duplicate it or copy it onto itself)\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_Palette_GetData(const geBitmap_Palette *P, void *Into,gePixelFormat Format,int Colors);\r
+GENESISAPI geBoolean GENESISCC geBitmap_Palette_SetData( geBitmap_Palette *P,const void *From,gePixelFormat Format,int Colors);\r
+ // does Lock/UnLock for you\r
+ // From and Into are arrays of Colors*gePixelFormat_BytesPerPel bytes\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_Palette_SetEntryColor( geBitmap_Palette *P,int Color,int R,int G,int B,int A);\r
+GENESISAPI geBoolean GENESISCC geBitmap_Palette_GetEntryColor(const geBitmap_Palette *P,int Color,int *R,int *G,int *B,int *A);\r
+ // Set/Get does Lock/Unlock for you ; these are slow! do not use these to work on all the colors!\r
+\r
+GENESISAPI geBoolean GENESISCC geBitmap_Palette_SetEntry( geBitmap_Palette *P,int Color,uint32 Pixel);\r
+GENESISAPI geBoolean GENESISCC geBitmap_Palette_GetEntry(const geBitmap_Palette *P,int Color,uint32 *Pixel);\r
+\r
+/***********************************************************************************/\r
+\r
+/************************************************************************\r
+\r
+A brief tutorial on the Bitmap system, by Charles Bloom, cbloom@wildtangent.com\r
+\r
+The Bitmap is a smart wrapper for complex functionality. You give it hints to\r
+the opaque Bitmap object, and it tries its best to follow those hints, but it\r
+may not always do so. The Bitmap is the owner of its bits; you must Lock the\r
+bitmap to get permission to touch those bits, and UnLock to tell the bitmap\r
+you are done. The format may change between two Locks. Bitmaps can also be\r
+multiply owned, so you should account for the fact that others may touch your\r
+bitmap between your uses.\r
+\r
+The Bitmap contains one or two pixel-sets representing an image. The "primary" is\r
+a fast-blitting version of the image, and the "secondary" is a storage version\r
+(eventually wavelet compressed) which can be used to rebuild the primary if it is\r
+freed or damaged. Both cary a generalized format.\r
+\r
+Let's do an example. I want to load a bitmap, set it up for drawing with the\r
+genesis Engine, and then blit some interactive stuff into it.\r
+\r
+************************************************************************/\r
+\r
+#if 0\r
+// {\r
+//-----------------------------------------------------------------------------\r
+\r
+void Init(geEngine * Engine);\r
+void Shutdown(void);\r
+void Draw(void);\r
+void DrawPolite(void);\r
+\r
+static geBitmap * myBM = NULL;\r
+static geEngine * myEngine = NULL;\r
+\r
+void Init(geEngine * Engine)\r
+{\r
+geBoolean success;\r
+geBitmap_Info Info;\r
+\r
+ myEngine = Engine; // this is not looked well upon; for ease of demonstration only!\r
+ assert(Engine);\r
+\r
+ myBM = geBitmap_CreateFromFileName(NULL,"mybitmap.bmp");\r
+\r
+ // CreateFromFile can load windows BMP files, or custom GeBm files.\r
+\r
+ assert(myBM);\r
+\r
+ // get the main info; I don't care about the secondary, so leave it NULL\r
+\r
+ success = geBitmap_GetInfo(myBM,&Info,NULL);\r
+ assert(success);\r
+\r
+ // make sure I loaded a bitmap in the format I understand !\r
+\r
+ if ( Info.Format == GE_PIXELFORMAT_8BIT_PAL )\r
+ {\r
+ // I want palette index 255 to act as transparency, so I must use SetColorKey\r
+\r
+ success = geBitmap_SetColorKey(myBM,GE_TRUE,255);\r
+ assert(success);\r
+\r
+ // just for fun, let's modify the palette:\r
+ if (1)\r
+ {\r
+ geBitmap_Palette * Pal;\r
+\r
+ // get the palette ; I don't care if its primary or secondary, so\r
+ /// I don't use the Info.Palette field\r
+\r
+ Pal = geBitmap_GetPalette(myBM);\r
+ assert(Pal);\r
+\r
+ // I'm only fiddling one entry, so don't bother with a full Lock() UnLock()\r
+ // sequence on the palette\r
+\r
+ // make palette index zero bright red; we use alpha = 255 for opaque\r
+\r
+ success = geBitmap_Palette_SetEntryColor(Pal,0,255,0,0,255);\r
+ assert(success);\r
+\r
+ // tell the bitmap system you've changed the palette; this function\r
+ // is smart enough to not do unecessary copies or whatever.\r
+\r
+ success = geBitmap_SetPalette(myBM,Pal);\r
+ assert(success);\r
+ }\r
+\r
+ }\r
+ else\r
+ {\r
+ // otherwise, treat black as transparent, in whatever format I have\r
+\r
+ success = geBitmap_SetColorKey(myBM,GE_TRUE,gePixelFormat_ComposePixel(Info.Format,0,0,0,0));\r
+ assert(success);\r
+ } \r
+\r
+ // note that I did NOT use SetFormat. SetFormat may do a conversion, and since the original\r
+ // bitmap was created without colorkey, it would have been converted to a new format but\r
+ // kept its property of having no colorkey!\r
+ // (SetFormat will fiddle the bits and whatever way necessary to keep bitmaps as visually similar\r
+ // as possible)\r
+\r
+ // I want to fiddle the fast format in 565 later, so cue the bitmap to try to give me that format.\r
+\r
+ success = geBitmap_SetPreferredFormat(myBM,GE_PIXELFORMAT_16BIT_565_RGB);\r
+ assert(success);\r
+\r
+ // Add it to the engine so it can be used for drawing.\r
+\r
+ success = geEngine_AddBitmap(myEngine,myBM);\r
+ assert(success);\r
+}\r
+\r
+void Shutdown(void)\r
+{\r
+geBoolean WasDestroyed;\r
+\r
+ assert(myBM);\r
+ \r
+ // clean up\r
+\r
+ geEngine_RemoveBitmap(myEngine,myBM);\r
+\r
+ WasDestroyed = geBitmap_Destroy(&myBM);\r
+\r
+ // someone else might have done _CreateRef on our bitmap,\r
+ // so we can't be sure it's actually destroyed.\r
+ // this code is still ready to be run again with a new call to Init()\r
+\r
+ //assert(WasDestroyed);\r
+\r
+ myBM = NULL;\r
+ myEngine = NULL;\r
+}\r
+\r
+void Draw(void)\r
+{\r
+geBitmap * Lock;\r
+geBoolean success;\r
+geBitmap_Info Info;\r
+uint16 *bits,*bptr;\r
+int x,y;\r
+\r
+ // lets fiddle the bits.\r
+ // we need to lock the bitmap for write.\r
+ // LockForWrite is an exclusive lock, unlike LockForRead which is non-blocking\r
+ // request our favorite format, and only lock Mip 0 (the full size bitmap)\r
+\r
+ success = geBitmap_LockForWriteFormat(myBM,&Lock,0,0,GE_PIXELFORMAT_16BIT_565_RGB);\r
+ if ( ! success )\r
+ {\r
+ // well, we tried to be nice; if we were very polite, we would do a LockForWrite\r
+ // here, and try to fiddle the bits in whatever format we got; However, we aren't\r
+ // that polite, so we just do a _SetFormat\r
+ //\r
+ // note that we are destroying the original bitmap by changing its format\r
+ // we should only do this if we are going to draw into the bitmap\r
+\r
+ success = geBitmap_SetFormat(myBM,GE_PIXELFORMAT_16BIT_565_RGB,GE_TRUE,0,NULL);\r
+ assert(success);\r
+\r
+ // now we should be able to get the bits we want, *but* they may not be the\r
+ // primary (fast) format; oh well, it's the best we can do...\r
+ // (if you must have the fastest bits, then use only _LockForWrite, never LockForWriteFormat,\r
+ // which might have to do a conversion)\r
+\r
+ success = geBitmap_LockForWriteFormat(myBM,&Lock,0,0,GE_PIXELFORMAT_16BIT_565_RGB);\r
+ assert(success);\r
+ }\r
+\r
+ // now Lock is our bitmap in 565\r
+ // we do a GetInfo because the Lock's info could be different than\r
+ // the original bitmap's (particularly the Palette & the Stride)\r
+\r
+ success = geBitmap_GetInfo(Lock,&Info,NULL);\r
+ assert(success);\r
+\r
+ // you can only call _GetBits on a locked bitmap\r
+\r
+ bits = geBitmap_GetBits(Lock);\r
+ assert( bits );\r
+\r
+ bptr = bits;\r
+ for(y=0; y < Info.Height; y++)\r
+ {\r
+ for(x=0; x < Info.Width; x++)\r
+ {\r
+ uint16 R,G,B;\r
+ // make a silly 565 gradient\r
+ R = x & 0x1F;\r
+ G = x & 0x3F;\r
+ B = y & 0x1F;\r
+\r
+ *bptr++ = (R<<11) + (G<<5) + B;\r
+ }\r
+\r
+ // note that bptr is a word pointer, and Stride is in pixels :\r
+\r
+ bptr += Info.Stride - Info.Width;\r
+ }\r
+ bits = bptr = NULL;\r
+\r
+ // you call Unlock on all the mips you locked - not on the original bitmap!\r
+\r
+ success = geBitmap_UnLock(Lock);\r
+ assert(success);\r
+\r
+ // now, we only fiddled the full-size Mip, and there might be more,\r
+ // so lets percolate the changes into the smaller mips:\r
+\r
+ success = geBitmap_RefreshMips(myBM);\r
+ assert(success);\r
+\r
+ // a null rect means use the whole bitmap;\r
+ // Engine_DrawBitmap blits a 2d decal to the framebuffer (fast)\r
+\r
+ success = geEngine_DrawBitmap(myEngine,myBM,NULL,0,0);\r
+ assert(success);\r
+\r
+}\r
+\r
+void DrawPolite(void)\r
+{\r
+geBitmap * Lock;\r
+geBoolean success;\r
+geBitmap_Info Info;\r
+void *bits;\r
+int x,y;\r
+\r
+ // this function does the same thing as Draw() , but is more polite\r
+ // lock in the fastest format (whatever it is)\r
+ // because we did SetPreferred, this should be 565_RGB, but might not be\r
+\r
+ success = geBitmap_LockForWrite(myBM,&Lock,0,0);\r
+ assert(success);\r
+\r
+ success = geBitmap_GetInfo(Lock,&Info,NULL);\r
+ assert(success);\r
+\r
+ bits = geBitmap_GetBits(Lock);\r
+ assert( bits );\r
+\r
+ if ( Info.Format == GE_PIXELFORMAT_16BIT_565_RGB )\r
+ {\r
+ uint16 *wptr;\r
+\r
+ // our favorite format\r
+\r
+ wptr = bits;\r
+ for(y=0; y < Info.Height; y++)\r
+ {\r
+ for(x=0; x < Info.Width; x++)\r
+ {\r
+ uint16 R,G,B;\r
+ // make a silly 565 gradient\r
+ R = x & 0x1F;\r
+ G = x & 0x3F;\r
+ B = y & 0x1F;\r
+\r
+ *wptr++ = (R<<11) + (G<<5) + B;\r
+ }\r
+ wptr += Info.Stride - Info.Width;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ uint8 * bptr;\r
+\r
+ // oh well, do our best\r
+ // bitmaps must have had a good reason to not give us the format we preferred,\r
+\r
+ bptr = bits;\r
+ for(y=0; y < Info.Height; y++)\r
+ {\r
+ for(x=0; x < Info.Width; x++)\r
+ {\r
+ uint32 R,G,B;\r
+\r
+ // put a color in any format\r
+\r
+ R = (x & 0x1F)<<3;\r
+ G = (x & 0x3F)<<2;\r
+ B = (y & 0x1F)<<3;\r
+\r
+ // we use alpha of 255 for opaque\r
+\r
+ gePixelFormat_PutColor(Info.Format,&bptr,R,G,B,255);\r
+ }\r
+\r
+ bptr += (Info.Stride - Info.Width) * gePixelFormat_BytesPerPel(Info.Format);\r
+ }\r
+ }\r
+ bits = NULL;\r
+\r
+ // same as before:\r
+\r
+ success = geBitmap_UnLock(Lock);\r
+ assert(success);\r
+\r
+ success = geBitmap_RefreshMips(myBM);\r
+ assert(success);\r
+\r
+ success = geEngine_DrawBitmap(myEngine,myBM,NULL,0,0);\r
+ assert(success);\r
+\r
+}\r
+\r
+// end tutorial on the Bitmap system\r
+//-----------------------------------------------------------------------------\r
+// }\r
+\r
+/***********************************************************************************/\r
+\r
+#endif\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif\r
+\r
+\r