00001 #ifndef BITMAP_H
00002 #define BITMAP_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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;
00044 gePixelFormat Format;
00045 int MinimumMip;
00046 int MaximumMip;
00047 geBoolean HasColorKey;
00048 uint32 ColorKey;
00049 geBitmap_Palette * Palette;
00050 } geBitmap_Info;
00051
00052
00053
00054
00055
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
00069
00070
00071 GENESISAPI geBoolean GENESISCC geBitmap_Destroy(geBitmap **Bmp);
00072
00073
00074 GENESISAPI geBoolean GENESISCC geBitmap_GetInfo(const geBitmap *Bmp, geBitmap_Info *Info, geBitmap_Info *SecondaryInfo);
00075
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
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
00088
00089 GENESISAPI geBoolean GENESISCC geBitmap_LockForRead(
00090 const geBitmap * Bmp,
00091 geBitmap ** Target,
00092 int MinimumMip,
00093 int MaximumMip,
00094 gePixelFormat Format,
00095 geBoolean RespectColorKey,
00096 uint32 ColorKey);
00097
00098
00099
00100 GENESISAPI geBoolean GENESISCC geBitmap_LockForReadNative(
00101 const geBitmap * Bmp,
00102 geBitmap ** Target,
00103 int MinimumMip,
00104 int MaximumMip);
00105
00106
00107
00108 GENESISAPI geBoolean GENESISCC geBitmap_LockForWrite(
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
00121
00122 GENESISAPI geBoolean GENESISCC geBitmap_UnLock(geBitmap *Bmp);
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
00130
00131
00132
00133 GENESISAPI geBoolean GENESISCC geBitmap_SetFormatMin(geBitmap *Bmp,gePixelFormat NewFormat);
00134
00135
00136 GENESISAPI geBoolean GENESISCC geBitmap_SetColorKey(geBitmap *Bmp, geBoolean HasColorKey, uint32 ColorKey, geBoolean Smart);
00137
00138
00139
00140
00141 GENESISAPI geBoolean GENESISCC geBitmap_GetAverageColor(const geBitmap *Bmp,int *pR,int *pG,int *pB);
00142
00143
00144 GENESISAPI geBitmap_Palette * GENESISCC geBitmap_GetPalette(const geBitmap *Bmp);
00145 GENESISAPI geBoolean GENESISCC geBitmap_SetPalette(geBitmap *Bmp, const geBitmap_Palette *Palette);
00146
00147
00148
00149
00150
00151
00152
00153
00154 GENESISAPI geBoolean GENESISCC geBitmap_HasAlpha(const geBitmap * Bmp);
00155
00156
00157 GENESISAPI geBitmap * GENESISCC geBitmap_GetAlpha(const geBitmap *Bmp);
00158 GENESISAPI geBoolean GENESISCC geBitmap_SetAlpha(geBitmap *Bmp, const geBitmap *AlphaBmp);
00159
00160
00161
00162
00163 GENESISAPI geBoolean GENESISCC geBitmap_SetGammaCorrection(geBitmap *Bmp,geFloat Gamma,geBoolean Apply);
00164
00165
00166
00167
00168
00169
00170
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);
00176
00177 GENESISAPI geBoolean GENESISCC geBitmap_RefreshMips(geBitmap *Bmp);
00178
00179 GENESISAPI geBoolean GENESISCC geBitmap_UpdateMips(geBitmap *Bmp,int SourceMip,int TargetMip);
00180
00181
00182 GENESISAPI geBoolean GENESISCC geBitmap_SetMipCount(geBitmap *Bmp,int Count);
00183
00184
00185 GENESISAPI geBoolean GENESISCC geBitmap_ClearMips(geBitmap *Bmp);
00186
00187
00188
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
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
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
00262
00263
00264
00265
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
00281
00282 GENESISAPI geBoolean GENESISCC geBitmap_Palette_Lock(geBitmap_Palette *Palette, void **pBits, gePixelFormat *pFormat,int *pSize);
00283
00284
00285 GENESISAPI geBoolean GENESISCC geBitmap_Palette_UnLock(geBitmap_Palette *Palette);
00286
00287
00288
00289
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
00294
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
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
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
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;
00345 assert(Engine);
00346
00347 myBM = geBitmap_CreateFromFileName(NULL,"mybitmap.bmp");
00348
00349
00350
00351 assert(myBM);
00352
00353
00354
00355 success = geBitmap_GetInfo(myBM,&Info,NULL);
00356 assert(success);
00357
00358
00359
00360 if ( Info.Format == GE_PIXELFORMAT_8BIT_PAL )
00361 {
00362
00363
00364 success = geBitmap_SetColorKey(myBM,GE_TRUE,255);
00365 assert(success);
00366
00367
00368 if (1)
00369 {
00370 geBitmap_Palette * Pal;
00371
00372
00374
00375 Pal = geBitmap_GetPalette(myBM);
00376 assert(Pal);
00377
00378
00379
00380
00381
00382
00383 success = geBitmap_Palette_SetEntryColor(Pal,0,255,0,0,255);
00384 assert(success);
00385
00386
00387
00388
00389 success = geBitmap_SetPalette(myBM,Pal);
00390 assert(success);
00391 }
00392
00393 }
00394 else
00395 {
00396
00397
00398 success = geBitmap_SetColorKey(myBM,GE_TRUE,gePixelFormat_ComposePixel(Info.Format,0,0,0,0));
00399 assert(success);
00400 }
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410 success = geBitmap_SetPreferredFormat(myBM,GE_PIXELFORMAT_16BIT_565_RGB);
00411 assert(success);
00412
00413
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
00426
00427 geEngine_RemoveBitmap(myEngine,myBM);
00428
00429 WasDestroyed = geBitmap_Destroy(&myBM);
00430
00431
00432
00433
00434
00435
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
00450
00451
00452
00453
00454 success = geBitmap_LockForWriteFormat(myBM,&Lock,0,0,GE_PIXELFORMAT_16BIT_565_RGB);
00455 if ( ! success )
00456 {
00457
00458
00459
00460
00461
00462
00463
00464 success = geBitmap_SetFormat(myBM,GE_PIXELFORMAT_16BIT_565_RGB,GE_TRUE,0,NULL);
00465 assert(success);
00466
00467
00468
00469
00470
00471
00472 success = geBitmap_LockForWriteFormat(myBM,&Lock,0,0,GE_PIXELFORMAT_16BIT_565_RGB);
00473 assert(success);
00474 }
00475
00476
00477
00478
00479
00480 success = geBitmap_GetInfo(Lock,&Info,NULL);
00481 assert(success);
00482
00483
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
00495 R = x & 0x1F;
00496 G = x & 0x3F;
00497 B = y & 0x1F;
00498
00499 *bptr++ = (R<<11) + (G<<5) + B;
00500 }
00501
00502
00503
00504 bptr += Info.Stride - Info.Width;
00505 }
00506 bits = bptr = NULL;
00507
00508
00509
00510 success = geBitmap_UnLock(Lock);
00511 assert(success);
00512
00513
00514
00515
00516 success = geBitmap_RefreshMips(myBM);
00517 assert(success);
00518
00519
00520
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
00536
00537
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
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
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
00575
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
00585
00586 R = (x & 0x1F)<<3;
00587 G = (x & 0x3F)<<2;
00588 B = (y & 0x1F)<<3;
00589
00590
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
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
00614
00615
00616
00617
00618
00619 #endif
00620 #ifdef __cplusplus
00621 }
00622 #endif
00623
00624
00625 #endif
00626
00627