Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

bitmap.h

Go to the documentation of this file.
00001 #ifndef BITMAP_H
00002 #define BITMAP_H
00003 
00004 /****************************************************************************************/
00005 /*  Bitmap.h                                                                            */
00006 /*                                                                                      */
00007 /*  Author: Charles Bloom                                                               */
00008 /*  Description:  Abstract Bitmap system                                                */
00009 /*                                                                                      */
00010 /*  The contents of this file are subject to the Genesis3D Public License               */
00011 /*  Version 1.01 (the "License"); you may not use this file except in                   */
00012 /*  compliance with the License. You may obtain a copy of the License at                */
00013 /*  http://www.genesis3d.com                                                            */
00014 /*                                                                                      */
00015 /*  Software distributed under the License is distributed on an "AS IS"                 */
00016 /*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
00017 /*  the License for the specific language governing rights and limitations              */
00018 /*  under the License.                                                                  */
00019 /*                                                                                      */
00020 /*  The Original Code is Genesis3D, released March 25, 1999.                            */
00021 /*  Genesis3D Version 1.1 released November 15, 1999                                 */
00022 /*  Copyright (C) 1999 WildTangent, Inc. All Rights Reserved           */
00023 /*                                                                                      */
00024 /****************************************************************************************/
00025 
00026 #include "basetype.h"
00027 #include "pixelformat.h"
00028 #include "vfile.h"
00029 
00030 #ifdef __cplusplus
00031 extern "C" {
00032 #endif
00033 
00034 /***********************************************************************************/
00035 
00036 typedef struct geBitmap                 geBitmap;
00037 typedef struct geBitmap_Palette geBitmap_Palette;
00038 
00039 typedef struct geBitmap_Info
00040 {
00041         int                                             Width;
00042         int                                             Height;
00043         int                                             Stride;         // stride is in *pixels* ; it is the step to the next line : Stride >= Width
00044         gePixelFormat                   Format;
00045         int                                             MinimumMip;     //*including* minimumMip == 0 often
00046         int                                             MaximumMip;     //*including* maximumMip == nummips-1
00047         geBoolean                               HasColorKey;
00048         uint32                                  ColorKey;       // meaningless unless HasColorKey ; the ColorKey is a Pixel in Format
00049         geBitmap_Palette *              Palette;
00050 } geBitmap_Info;
00051 
00052 /***********************************************************************************/           
00053 // Bitmap methods
00054 
00055 // see a big comment at the end of this file
00056 
00057 /************************************************************************/
00058 
00059 GENESISAPI geBitmap *   GENESISCC       geBitmap_Create(int Width, int Height, int MipCount, gePixelFormat Format ); 
00060 GENESISAPI void                 GENESISCC       geBitmap_CreateRef(geBitmap *Bmp);
00061 
00062 GENESISAPI geBitmap *   GENESISCC       geBitmap_CreateFromInfo(const geBitmap_Info * pInfo);
00063 
00064 GENESISAPI geBitmap *   GENESISCC       geBitmap_CreateFromFile( geVFile *F );
00065 GENESISAPI geBitmap *   GENESISCC       geBitmap_CreateFromFileName(const geVFile *BaseFS,const char *Name);
00066 GENESISAPI geBoolean    GENESISCC       geBitmap_WriteToFile( const geBitmap *Bmp, geVFile *F );
00067 GENESISAPI geBoolean    GENESISCC       geBitmap_WriteToFileName(const geBitmap * Bmp,const geVFile *BaseFS,const char *Name);
00068                                                                                 // BaseFS is not really const if it is a virtual file;
00069                                                                                 //  it *is* const if it is a dos directory
00070 
00071 GENESISAPI geBoolean    GENESISCC       geBitmap_Destroy(geBitmap **Bmp);
00072         // returns whether Bmp was actually destroyed : not success/failure
00073 
00074 GENESISAPI geBoolean    GENESISCC       geBitmap_GetInfo(const geBitmap *Bmp, geBitmap_Info *Info, geBitmap_Info *SecondaryInfo);
00075         //LockForWrite returns data in Info's format
00076 
00077 GENESISAPI geBoolean    GENESISCC       geBitmap_Blit(const     geBitmap *Src, int SrcPositionX, int SrcPositionY,
00078                                                                                 geBitmap *Dst, int DstPositionX, int DstPositionY,
00079                                                                                 int SizeX, int SizeY );
00080 
00081 GENESISAPI geBoolean    GENESISCC       geBitmap_BlitMip(const geBitmap * Src, int SrcMip, geBitmap * Dst, int DstMip );
00082                                                                                 // don't use this with Src == Dst, use UpdateMips instead !
00083 
00084 GENESISAPI geBoolean    GENESISCC       geBitmap_BlitBitmap(const geBitmap * Src, geBitmap * Dst);
00085 
00086 GENESISAPI geBoolean    GENESISCC       geBitmap_BlitBestMip(const geBitmap * Src, geBitmap * Dst);
00087                                                                                 // blits the largest mip from Src that fits in Dst
00088 
00089 GENESISAPI geBoolean    GENESISCC       geBitmap_LockForRead(           // a non-exclusive lock
00090         const geBitmap *        Bmp,
00091         geBitmap **                     Target,
00092         int                                     MinimumMip,
00093         int                                     MaximumMip,
00094         gePixelFormat           Format,
00095         geBoolean                       RespectColorKey,
00096         uint32                          ColorKey);
00097                                                                         // not really const, stores lock-count, but *data* is const
00098                                                                         // will do a format conversion!
00099 
00100 GENESISAPI geBoolean    GENESISCC       geBitmap_LockForReadNative(
00101         const geBitmap *        Bmp,
00102         geBitmap **                     Target,
00103         int                                     MinimumMip,
00104         int                                     MaximumMip);
00105                                                                         // lock for read in a format that gaurantee no conversions
00106                                                                         // then do GetInfo on the locks to see what you have!
00107 
00108 GENESISAPI geBoolean    GENESISCC       geBitmap_LockForWrite(  // an exclusive lock
00109         geBitmap *                      Bmp,
00110         geBitmap **                     Target,
00111         int                                     MinimumMip,
00112         int                                     MaximumMip);
00113 
00114 GENESISAPI geBoolean    GENESISCC       geBitmap_LockForWriteFormat(
00115         geBitmap *                      Bmp,
00116         geBitmap **                     Target,
00117         int                                     MinimumMip,
00118         int                                     MaximumMip,
00119         gePixelFormat           Format);
00120                                                                         // Format must be one of the two returned in GetInfo !!
00121 
00122 GENESISAPI geBoolean    GENESISCC       geBitmap_UnLock(geBitmap *Bmp); // must be done on All locked mips
00123 GENESISAPI geBoolean    GENESISCC       geBitmap_UnLockArray(geBitmap **Locks,int Size);
00124 
00125 GENESISAPI geBoolean    GENESISCC       geBitmap_SetFormat(geBitmap *Bmp, 
00126                                                         gePixelFormat NewFormat, 
00127                                                         geBoolean RespectColorKey, uint32 ColorKey,
00128                                                         const geBitmap_Palette * Palette);
00129         // _SetFormat may cause you to lose color information!
00130         // SetFormat does a conversion!
00131         // if NewFormat is palettized and Palette is NULL, we create a palette for the bitmap!
00132 
00133 GENESISAPI geBoolean    GENESISCC       geBitmap_SetFormatMin(geBitmap *Bmp,gePixelFormat NewFormat);
00134                                                                 // the Min version keeps colorkey & palette from the old format
00135 
00136 GENESISAPI geBoolean    GENESISCC       geBitmap_SetColorKey(geBitmap *Bmp, geBoolean HasColorKey, uint32 ColorKey, geBoolean Smart);
00137         // SetColorKey discards old colorkey information!
00138         //      does not do a conversion (changes the colorkey in the current data
00139         // if 'Smart' is on, we don't set HasColorKey to true unless it is actually used!
00140 
00141 GENESISAPI geBoolean    GENESISCC       geBitmap_GetAverageColor(const geBitmap *Bmp,int *pR,int *pG,int *pB);
00142         // tells you the average color; computes it and caches it out
00143 
00144 GENESISAPI geBitmap_Palette *   GENESISCC       geBitmap_GetPalette(const geBitmap *Bmp);
00145 GENESISAPI geBoolean                    GENESISCC       geBitmap_SetPalette(geBitmap *Bmp, const geBitmap_Palette *Palette);
00146         // _SetPal tries to _CreateRef your Palette, so no copy occurs & palettes may be shared
00147         // you may _Destroy() palette after using it to set (though its bits may not be freed)
00148         //      (hence Palette is *not* const)
00149         // Warning : SetPalette on any mip changes the palette of ALL mips !
00150         // see Palette note at _UnLock
00151         // _SetPal destroys the bitmap's original palette and refs the new one, 
00152         //              so if you setpal with the bitmap's palette, there is no net change in ref counts (good!)
00153 
00154 GENESISAPI geBoolean    GENESISCC       geBitmap_HasAlpha(const geBitmap * Bmp);
00155         // returns true if bitmap has *any* type of alpha
00156 
00157 GENESISAPI geBitmap *   GENESISCC       geBitmap_GetAlpha(const geBitmap *Bmp);
00158 GENESISAPI geBoolean    GENESISCC       geBitmap_SetAlpha(geBitmap *Bmp, const geBitmap *AlphaBmp);
00159         // we Ref the AlphaBmp, so you may destroy it after calling Set()
00160         // it may be NULL
00161         // there's only one Alpha per bitmap (for the top Mip) right now
00162 
00163 GENESISAPI geBoolean    GENESISCC       geBitmap_SetGammaCorrection(geBitmap *Bmp,geFloat Gamma,geBoolean Apply);
00164         // this Gamma does not change the *original* (system/secondary) bits
00165         //      it only affects the appearance when drawn
00166         // note : if you write to the gamma corrected bits, you must gamma correct manually if you
00167         //      wish to fit in smoothly with the previous data
00168         // warning : if you use this function with many different gammas, performance will suffer!
00169         //      use one global gamma for all bitmaps!  try to let the engine manage gamma for you,
00170         //      via geEngine_SetGamma !
00171 
00172 GENESISAPI geBoolean            GENESISCC       geBitmap_SetPreferredFormat(geBitmap *Bmp,gePixelFormat Format);
00173 GENESISAPI gePixelFormat        GENESISCC       geBitmap_GetPreferredFormat(const geBitmap *Bmp);
00174 
00175 GENESISAPI void *               GENESISCC       geBitmap_GetBits(geBitmap *Bmp);        // works only on a Lock()
00176 
00177 GENESISAPI geBoolean    GENESISCC       geBitmap_RefreshMips(geBitmap *Bmp);    // rebuilds mips; *tries* to be smart & not overwrite manually-fixed mips
00178                                                                                                 // RefreshMips does *not* build mips that don't exist
00179 GENESISAPI geBoolean    GENESISCC       geBitmap_UpdateMips(geBitmap *Bmp,int SourceMip,int TargetMip); 
00180                                                                                                 // will create the target if it doesn't exist;
00181                                                                                                 // will overwrite manually-fixed mips!
00182 GENESISAPI geBoolean    GENESISCC       geBitmap_SetMipCount(geBitmap *Bmp,int Count);
00183                                                                                                 // creates or destroys to match the new count
00184 
00185 GENESISAPI geBoolean    GENESISCC       geBitmap_ClearMips(geBitmap *Bmp);      // Destroy all mips (except the first) !
00186                                                                                                 // use with care! this is not polite!
00187 
00188 // Shortcuts
00189 GENESISAPI int                  GENESISCC       geBitmap_Width(const geBitmap *Bitmap);
00190 GENESISAPI int                  GENESISCC       geBitmap_Height(const geBitmap *Bitmap);
00191 GENESISAPI uint32               GENESISCC       geBitmap_MipBytes(const geBitmap * Bitmap,int mip);
00192 
00206 #ifdef _DEBUG
00207 
00208 GENESISAPI uint32               GENESISCC       geBitmap_Debug_GetCount(void);
00209 
00210 GENESISAPI uint32               GENESISCC       geBitmap_Debug_GetRefs(void);
00211         // assert this is zero before you shutdown !
00212 
00213 #endif
00214 
00215 /***********************************************************************************/
00216 
00217 typedef enum
00218 {
00219         GE_BITMAP_STREAMING_ERROR=0,
00220         GE_BITMAP_STREAMING_NOT,
00221         GE_BITMAP_STREAMING_STARTED,
00222         GE_BITMAP_STREAMING_IDLE,
00223         GE_BITMAP_STREAMING_CHANGED,
00224         GE_BITMAP_STREAMING_DATADONE,
00225         GE_BITMAP_STREAMING_DONE,
00226 } geBitmap_StreamingStatus;
00227 
00228 GENESISAPI geBitmap_StreamingStatus GENESISCC geBitmap_GetStreamingStatus(const geBitmap *Bmp);
00229 
00250 /***********************************************************************************/
00251 
00252 // palette methods :
00253 
00254 GENESISAPI geBitmap_Palette *   GENESISCC       geBitmap_Palette_Create(gePixelFormat Format,int Size);
00255 
00256 GENESISAPI geBitmap_Palette *   GENESISCC       geBitmap_Palette_CreateCopy(const geBitmap_Palette *Palette);
00257 
00258 GENESISAPI geBitmap_Palette *   GENESISCC       geBitmap_Palette_CreateFromFile(geVFile *F);
00259 
00260 GENESISAPI geBitmap_Palette *   GENESISCC       geBitmap_Palette_CreateFromBitmap(geBitmap * Bmp,geBoolean Slow);
00261                                                                                                 // does GetPalette, and if NULL, then
00262                                                                                                 // it create an optimal palette for a
00263                                                                                                 //      non-palettized bitmap
00264                                                                                                 //      (this is a create, you must destroy later!)
00265                                                                                                 // put Slow == TRUE for higher quality & slower
00266 
00267 GENESISAPI geBoolean            GENESISCC       geBitmap_Palette_SortColors(geBitmap_Palette * P,geBoolean Slower);
00268 
00269 GENESISAPI geBoolean            GENESISCC       geBitmap_Palette_CreateRef(geBitmap_Palette *Palette);
00270 
00271 GENESISAPI geBoolean            GENESISCC       geBitmap_Palette_Destroy(geBitmap_Palette ** ppPalette);
00272 
00273 GENESISAPI geBoolean            GENESISCC       geBitmap_Palette_WriteToFile(const geBitmap_Palette *Palette,geVFile *F);
00274 
00275 GENESISAPI geBoolean            GENESISCC       geBitmap_Palette_SetFormat(geBitmap_Palette * Palette,gePixelFormat Format);
00276 
00277 GENESISAPI geBoolean            GENESISCC       geBitmap_Palette_Copy(const geBitmap_Palette * Src,geBitmap_Palette * Target);
00278 
00279 GENESISAPI geBoolean            GENESISCC       geBitmap_Palette_GetInfo(const  geBitmap_Palette *P,geBitmap_Info *Into);
00280                                                                                                 // get the info as if it were a bitmap; Into->Height == 1
00281 
00282 GENESISAPI geBoolean            GENESISCC       geBitmap_Palette_Lock(geBitmap_Palette *Palette, void **pBits, gePixelFormat *pFormat,int *pSize);
00283                                                                                                 // pFormat & pSize are optional
00284 
00285 GENESISAPI geBoolean            GENESISCC       geBitmap_Palette_UnLock(geBitmap_Palette *Palette);
00286                                                                                         // palette unlock does NOT notify the bitmap that the palette has changed.
00287                                                                                         // call Bitmap_SetPalette() with the same palette pointer 
00288                                                                                         //      to tell the bitmap that it must to some processing
00289                                                                                         // (don't worry, it won't duplicate it or copy it onto itself)
00290 
00291 GENESISAPI geBoolean            GENESISCC       geBitmap_Palette_GetData(const geBitmap_Palette *P,      void *Into,gePixelFormat Format,int Colors);
00292 GENESISAPI geBoolean            GENESISCC       geBitmap_Palette_SetData(      geBitmap_Palette *P,const void *From,gePixelFormat Format,int Colors);
00293                                                                                         // does Lock/UnLock for you
00294                                                                                         // From and Into are arrays of Colors*gePixelFormat_BytesPerPel bytes
00295 
00296 GENESISAPI geBoolean            GENESISCC       geBitmap_Palette_SetEntryColor(      geBitmap_Palette *P,int Color,int R,int G,int B,int A);
00297 GENESISAPI geBoolean            GENESISCC       geBitmap_Palette_GetEntryColor(const geBitmap_Palette *P,int Color,int *R,int *G,int *B,int *A);
00298                                                                                         // Set/Get does Lock/Unlock for you ; these are slow! do not use these to work on all the colors!
00299 
00300 GENESISAPI geBoolean            GENESISCC       geBitmap_Palette_SetEntry(      geBitmap_Palette *P,int Color,uint32 Pixel);
00301 GENESISAPI geBoolean            GENESISCC       geBitmap_Palette_GetEntry(const geBitmap_Palette *P,int Color,uint32 *Pixel);
00302 
00303 /***********************************************************************************/
00304 
00305 /************************************************************************
00306 
00307 A brief tutorial on the Bitmap system, by Charles Bloom, cbloom@wildtangent.com
00308 
00309 The Bitmap is a smart wrapper for complex functionality.  You give it hints to
00310 the opaque Bitmap object, and it tries its best to follow those hints, but it
00311 may not always do so.  The Bitmap is the owner of its bits; you must Lock the
00312 bitmap to get permission to touch those bits, and UnLock to tell the bitmap
00313 you are done.  The format may change between two Locks.  Bitmaps can also be
00314 multiply owned, so you should account for the fact that others may touch your
00315 bitmap between your uses.
00316 
00317 The Bitmap contains one or two pixel-sets representing an image.  The "primary" is
00318 a fast-blitting version of the image, and the "secondary" is a storage version
00319 (eventually wavelet compressed) which can be used to rebuild the primary if it is
00320 freed or damaged.  Both cary a generalized format.
00321 
00322 Let's do an example.  I want to load a bitmap, set it up for drawing with the
00323 genesis Engine, and then blit some interactive stuff into it.
00324 
00325 ************************************************************************/
00326 
00327 #if 0
00328 // {
00329 //-----------------------------------------------------------------------------
00330 
00331 void Init(geEngine * Engine);
00332 void Shutdown(void);
00333 void Draw(void);
00334 void DrawPolite(void);
00335 
00336 static geBitmap * myBM = NULL;
00337 static geEngine * myEngine = NULL;
00338 
00339 void Init(geEngine * Engine)
00340 {
00341 geBoolean success;
00342 geBitmap_Info Info;
00343 
00344         myEngine = Engine;      // this is not looked well upon; for ease of demonstration only!
00345         assert(Engine);
00346 
00347         myBM = geBitmap_CreateFromFileName(NULL,"mybitmap.bmp");
00348 
00349         // CreateFromFile can load windows BMP files, or custom GeBm files.
00350 
00351         assert(myBM);
00352 
00353         // get the main info; I don't care about the secondary, so leave it NULL
00354 
00355         success = geBitmap_GetInfo(myBM,&Info,NULL);
00356         assert(success);
00357 
00358         // make sure I loaded a bitmap in the format I understand !
00359 
00360         if ( Info.Format == GE_PIXELFORMAT_8BIT_PAL )
00361         {
00362                 // I want palette index 255 to act as transparency, so I must use SetColorKey
00363 
00364                 success = geBitmap_SetColorKey(myBM,GE_TRUE,255);
00365                 assert(success);
00366 
00367                 // just for fun, let's modify the palette:
00368                 if (1)
00369                 {
00370                 geBitmap_Palette * Pal;
00371 
00372                         // get the palette ; I don't care if its primary or secondary, so
00374 
00375                         Pal = geBitmap_GetPalette(myBM);
00376                         assert(Pal);
00377 
00378                         // I'm only fiddling one entry, so don't bother with a full Lock() UnLock()
00379                         //  sequence on the palette
00380 
00381                         // make palette index zero bright red; we use alpha = 255 for opaque
00382 
00383                         success = geBitmap_Palette_SetEntryColor(Pal,0,255,0,0,255);
00384                         assert(success);
00385 
00386                         // tell the bitmap system you've changed the palette; this function
00387                         //  is smart enough to not do unecessary copies or whatever.
00388 
00389                         success = geBitmap_SetPalette(myBM,Pal);
00390                         assert(success);
00391                 }
00392 
00393         }
00394         else
00395         {
00396                 // otherwise, treat black as transparent, in whatever format I have
00397 
00398                 success = geBitmap_SetColorKey(myBM,GE_TRUE,gePixelFormat_ComposePixel(Info.Format,0,0,0,0));
00399                 assert(success);
00400         }       
00401 
00402         // note that I did NOT use SetFormat.  SetFormat may do a conversion, and since the original
00403         //      bitmap was created without colorkey, it would have been converted to a new format but
00404         //      kept its property of having no colorkey!
00405         // (SetFormat will fiddle the bits and whatever way necessary to keep bitmaps as visually similar
00406         //              as possible)
00407 
00408         // I want to fiddle the fast format in 565 later, so cue the bitmap to try to give me that format.
00409 
00410         success = geBitmap_SetPreferredFormat(myBM,GE_PIXELFORMAT_16BIT_565_RGB);
00411         assert(success);
00412 
00413         // Add it to the engine so it can be used for drawing.
00414 
00415         success = geEngine_AddBitmap(myEngine,myBM);
00416         assert(success);
00417 }
00418 
00419 void Shutdown(void)
00420 {
00421 geBoolean WasDestroyed;
00422 
00423         assert(myBM);
00424         
00425         // clean up
00426 
00427         geEngine_RemoveBitmap(myEngine,myBM);
00428 
00429         WasDestroyed = geBitmap_Destroy(&myBM);
00430 
00431         // someone else might have done _CreateRef on our bitmap,
00432         //  so we can't be sure it's actually destroyed.
00433         // this code is still ready to be run again with a new call to Init()
00434 
00435         //assert(WasDestroyed);
00436 
00437         myBM = NULL;
00438         myEngine = NULL;
00439 }
00440 
00441 void Draw(void)
00442 {
00443 geBitmap * Lock;
00444 geBoolean success;
00445 geBitmap_Info Info;
00446 uint16 *bits,*bptr;
00447 int x,y;
00448 
00449         // lets fiddle the bits.
00450         // we need to lock the bitmap for write.
00451         //      LockForWrite is an exclusive lock, unlike LockForRead which is non-blocking
00452         // request our favorite format, and only lock Mip 0 (the full size bitmap)
00453 
00454         success = geBitmap_LockForWriteFormat(myBM,&Lock,0,0,GE_PIXELFORMAT_16BIT_565_RGB);
00455         if ( ! success )
00456         {
00457                 // well, we tried to be nice; if we were very polite, we would do a LockForWrite
00458                 // here, and try to fiddle the bits in whatever format we got; However, we aren't
00459                 // that polite, so we just do a _SetFormat
00460                 //
00461                 // note that we are destroying the original bitmap by changing its format
00462                 // we should only do this if we are going to draw into the bitmap
00463 
00464                 success = geBitmap_SetFormat(myBM,GE_PIXELFORMAT_16BIT_565_RGB,GE_TRUE,0,NULL);
00465                 assert(success);
00466 
00467                 // now we should be able to get the bits we want, *but* they may not be the
00468                 // primary (fast) format; oh well, it's the best we can do...
00469                 // (if you must have the fastest bits, then use only _LockForWrite, never LockForWriteFormat,
00470                 // which might have to do a conversion)
00471 
00472                 success = geBitmap_LockForWriteFormat(myBM,&Lock,0,0,GE_PIXELFORMAT_16BIT_565_RGB);
00473                 assert(success);
00474         }
00475 
00476         // now Lock is our bitmap in 565
00477         // we do a GetInfo because the Lock's info could be different than
00478         //      the original bitmap's (particularly the Palette & the Stride)
00479 
00480         success = geBitmap_GetInfo(Lock,&Info,NULL);
00481         assert(success);
00482 
00483         // you can only call _GetBits on a locked bitmap
00484 
00485         bits = geBitmap_GetBits(Lock);
00486         assert( bits );
00487 
00488         bptr = bits;
00489         for(y=0; y < Info.Height; y++)
00490         {
00491                 for(x=0; x < Info.Width; x++)
00492                 {
00493                 uint16 R,G,B;
00494                         // make a silly 565 gradient
00495                         R = x & 0x1F;
00496                         G = x & 0x3F;
00497                         B = y & 0x1F;
00498 
00499                         *bptr++ = (R<<11) + (G<<5) + B;
00500                 }
00501 
00502                 // note that bptr is a word pointer, and Stride is in pixels :
00503 
00504                 bptr += Info.Stride -  Info.Width;
00505         }
00506         bits = bptr = NULL;
00507 
00508         // you call Unlock on all the mips you locked - not on the original bitmap!
00509 
00510         success = geBitmap_UnLock(Lock);
00511         assert(success);
00512 
00513         // now, we only fiddled the full-size Mip, and there might be more,
00514         //  so lets percolate the changes into the smaller mips:
00515 
00516         success = geBitmap_RefreshMips(myBM);
00517         assert(success);
00518 
00519         // a null rect means use the whole bitmap;
00520         // Engine_DrawBitmap blits a 2d decal to the framebuffer (fast)
00521 
00522         success = geEngine_DrawBitmap(myEngine,myBM,NULL,0,0);
00523         assert(success);
00524 
00525 }
00526 
00527 void DrawPolite(void)
00528 {
00529 geBitmap * Lock;
00530 geBoolean success;
00531 geBitmap_Info Info;
00532 void *bits;
00533 int x,y;
00534 
00535         // this function does the same thing as Draw() , but is more polite
00536         // lock in the fastest format (whatever it is)
00537         // because we did SetPreferred, this should be 565_RGB, but might not be
00538 
00539         success = geBitmap_LockForWrite(myBM,&Lock,0,0);
00540         assert(success);
00541 
00542         success = geBitmap_GetInfo(Lock,&Info,NULL);
00543         assert(success);
00544 
00545         bits = geBitmap_GetBits(Lock);
00546         assert( bits );
00547 
00548         if ( Info.Format == GE_PIXELFORMAT_16BIT_565_RGB )
00549         {
00550         uint16 *wptr;
00551 
00552                 // our favorite format
00553 
00554                 wptr = bits;
00555                 for(y=0; y < Info.Height; y++)
00556                 {
00557                         for(x=0; x < Info.Width; x++)
00558                         {
00559                         uint16 R,G,B;
00560                                 // make a silly 565 gradient
00561                                 R = x & 0x1F;
00562                                 G = x & 0x3F;
00563                                 B = y & 0x1F;
00564 
00565                                 *wptr++ = (R<<11) + (G<<5) + B;
00566                         }
00567                         wptr += Info.Stride -  Info.Width;
00568                 }
00569         }
00570         else
00571         {
00572         uint8 * bptr;
00573 
00574                 // oh well, do our best
00575                 // bitmaps must have had a good reason to not give us the format we preferred,
00576 
00577                 bptr = bits;
00578                 for(y=0; y < Info.Height; y++)
00579                 {
00580                         for(x=0; x < Info.Width; x++)
00581                         {
00582                         uint32 R,G,B;
00583 
00584                                 // put a color in any format
00585 
00586                                 R = (x & 0x1F)<<3;
00587                                 G = (x & 0x3F)<<2;
00588                                 B = (y & 0x1F)<<3;
00589 
00590                                 // we use alpha of 255 for opaque
00591 
00592                                 gePixelFormat_PutColor(Info.Format,&bptr,R,G,B,255);
00593                         }
00594 
00595                         bptr += (Info.Stride -  Info.Width) * gePixelFormat_BytesPerPel(Info.Format);
00596                 }
00597         }
00598         bits = NULL;
00599 
00600         // same as before:
00601 
00602         success = geBitmap_UnLock(Lock);
00603         assert(success);
00604 
00605         success = geBitmap_RefreshMips(myBM);
00606         assert(success);
00607 
00608         success = geEngine_DrawBitmap(myEngine,myBM,NULL,0,0);
00609         assert(success);
00610 
00611 }
00612 
00613 // end tutorial on the Bitmap system
00614 //-----------------------------------------------------------------------------
00615 // }
00616 
00617 /***********************************************************************************/
00618 
00619 #endif
00620 #ifdef __cplusplus
00621 }
00622 #endif
00623 
00624 
00625 #endif
00626 
00627 

Generated on Tue Sep 30 12:35:17 2003 for GTestAndEngine by doxygen 1.3.2