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

bitmap.c File Reference

#include <math.h>
#include <time.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "basetype.h"
#include "getypes.h"
#include "ram.h"
#include "vfile.h"
#include "ErrorLog.h"
#include "Log.h"
#include "mempool.h"
#include "bitmap.h"
#include "bitmap._h"
#include "bitmap.__h"
#include "bitmap_blitdata.h"
#include "bitmap_gamma.h"
#include "palcreate.h"
#include "palettize.h"

Go to the source code of this file.

Compounds

struct  BITMAPFILEHEADER
struct  BITMAPINFOHEADER
struct  RGBQUAD
struct  TGAHEADER

Defines

#define allocate(ptr)   ptr = geRam_Allocate(sizeof(*ptr))
#define clear(ptr)   memset(ptr,0,sizeof(*ptr))
#define SHIFT_R_ROUNDUP(val, shift)   (((val)+(1<<(shift)) - 1)>>(shift))
#define Debug(x)
#define MAX_DRIVER_FORMATS   (100)
#define GEBM_TAG   ((geBmTag_t)0x6D426547)
#define GEBM_VERSION   (((uint32)GEBM_VERSION_MAJOR<<4) + (uint32)GEBM_VERSION_MINOR)
#define VERSION_MAJOR(Version)   (((Version)>>4)&0x0F)
#define VERSION_MINOR(Version)   ((Version)&0x0F)
#define MIP_MASK   (0xF)
#define MIP_FLAG_COMPRESSED   (1<<4)
#define MIP_FLAG_PAETH_FILTERED   (1<<5)
#define INFO_FLAG_WH_ARE_LOG2   (1<<0)
#define INFO_FLAG_HAS_CK   (1<<1)
#define INFO_FLAG_HAS_ALPHA   (1<<2)
#define INFO_FLAG_HAS_PAL   (1<<3)
#define INFO_FLAG_IF_NOT_LOG2_ARE_BYTE   (1<<5)
#define PALETTE_INFO_FORMAT_MASK   (0x1F)
#define PALETTE_INFO_FLAG_SIZE256   (1<<5)
#define PALETTE_INFO_FLAG_COMPRESS   (1<<6)

Typedefs

typedef uint32 geBmTag_t
typedef TGAHEADER TGAHEADER

Functions

void geBitmap_Start (void)
void geBitmap_Stop (void)
geBitmapgeBitmap_Create_Base (void)
void geBitmap_Destroy_Base (geBitmap *Bmp)
GENESISAPI void GENESISCC geBitmap_CreateRef (geBitmap *Bmp)
GENESISAPI geBitmap *GENESISCC geBitmap_Create (int Width, int Height, int MipCount, gePixelFormat Format)
GENESISAPI geBitmap *GENESISCC geBitmap_CreateFromInfo (const geBitmap_Info *pInfo)
GENESISAPI geBoolean GENESISCC geBitmap_Destroy (geBitmap **Bmp)
geBoolean geBitmap_AllocSystemMip (geBitmap *Bmp, int mip)
geBoolean geBitmap_AllocPalette (geBitmap *Bmp, gePixelFormat Format, DRV_Driver *Driver)
GENESISAPI geBoolean GENESISCC geBitmap_LockForWrite (geBitmap *Bmp, geBitmap **Target, int MinimumMip, int MaximumMip)
GENESISAPI geBoolean GENESISCC geBitmap_LockForWriteFormat (geBitmap *Bmp, geBitmap **Target, int MinimumMip, int MaximumMip, gePixelFormat Format)
GENESISAPI geBoolean GENESISCC geBitmap_LockForReadNative (const geBitmap *iBmp, geBitmap **Target, int MinimumMip, int MaximumMip)
GENESISAPI geBoolean GENESISCC geBitmap_LockForRead (const geBitmap *iBmp, geBitmap **Target, int MinimumMip, int MaximumMip, gePixelFormat Format, geBoolean HasColorKey, uint32 ColorKey)
geBoolean geBitmap_UnLockArray_NoChange (geBitmap **Locks, int Size)
GENESISAPI geBoolean GENESISCC geBitmap_UnLockArray (geBitmap **Locks, int Size)
geBoolean geBitmap_UnLock_Internal (geBitmap *Bmp, geBoolean Apply)
GENESISAPI geBoolean GENESISCC geBitmap_UnLock (geBitmap *Bmp)
geBoolean geBitmap_UnLock_NoChange (geBitmap *Bmp)
GENESISAPI void *GENESISCC geBitmap_GetBits (geBitmap *Bmp)
geBitmapgeBitmap_CreateLock_CopyInfo (geBitmap *BmpSrc, int LockCnt, int mip)
void geBitmap_MakeMipInfo (geBitmap_Info *Src, int mip, geBitmap_Info *Target)
geBitmapgeBitmap_CreateLockFromMip (geBitmap *Src, int mip, gePixelFormat Format, geBoolean HasColorKey, uint32 ColorKey, int LockCnt)
geBitmapgeBitmap_CreateLockFromMipSystem (geBitmap *Src, int mip, int LockCnt)
geBitmapgeBitmap_CreateLockFromMipOnDriver (geBitmap *Src, int mip, int LockCnt)
geBoolean EnumPFCB (geRDriver_PixelFormat *pFormat, void *Context)
int NumBitsOn (uint32 val)
geBoolean IsInArray (uint32 Val, uint32 *Array, int Len)
geBoolean geBitmap_ChooseDriverFormat (gePixelFormat SeekFormat1, gePixelFormat SeekFormat2, geBoolean SeekCK, geBoolean SeekAlpha, geBoolean SeekSeparates, uint32 SeekFlags, geRDriver_PixelFormat *DriverFormatsArray, int ArrayLen, geRDriver_PixelFormat *pTarget)
geRDriver_THandlegeBitmap_CreateTHandle (DRV_Driver *Driver, int Width, int Height, int NumMipLevels, gePixelFormat SeekFormat1, gePixelFormat SeekFormat2, geBoolean SeekCK, geBoolean SeekAlpha, geBoolean SeekSeparates, uint32 DriverFlags)
GENESISAPI geBoolean GENESISCC geBitmap_HasAlpha (const geBitmap *Bmp)
geBoolean BITMAP_GENESIS_INTERNAL geBitmap_AttachToDriver (geBitmap *Bmp, DRV_Driver *Driver, uint32 DriverFlags)
geBoolean geBitmap_FixDriverFlags (uint32 *pFlags)
geBoolean BITMAP_GENESIS_INTERNAL geBitmap_SetDriverFlags (geBitmap *Bmp, uint32 Flags)
geBoolean BITMAP_GENESIS_INTERNAL geBitmap_DetachDriver (geBitmap *Bmp, geBoolean DoUpdate)
geBoolean GENESISCC geBitmap_SetGammaCorrection_DontChange (geBitmap *Bmp, geFloat Gamma)
GENESISAPI geBoolean GENESISCC geBitmap_SetGammaCorrection (geBitmap *Bmp, geFloat Gamma, geBoolean Apply)
geRDriver_THandle *BITMAP_GENESIS_INTERNAL geBitmap_GetTHandle (const geBitmap *Bmp)
geBoolean geBitmap_Update_SystemToDriver (geBitmap *Bmp)
geBoolean geBitmap_Update_DriverToSystem (geBitmap *Bmp)
GENESISAPI geBoolean GENESISCC geBitmap_RefreshMips (geBitmap *Bmp)
GENESISAPI geBoolean GENESISCC geBitmap_UpdateMips (geBitmap *Bmp, int fm, int to)
geBoolean geBitmap_UpdateMips_System (geBitmap *Bmp, int fm, int to)
geBoolean geBitmap_UpdateMips_Data (geBitmap_Info *FmInfo, void *FmBits, geBitmap_Info *ToInfo, void *ToBits)
GENESISAPI geBoolean GENESISCC geBitmap_ClearMips (geBitmap *Bmp)
GENESISAPI geBoolean GENESISCC geBitmap_SetMipCount (geBitmap *Bmp, int Count)
geBoolean geBitmap_MakeSystemMips (geBitmap *Bmp, int low, int high)
GENESISAPI uint32 GENESISCC geBitmap_MipBytes (const geBitmap *Bmp, int mip)
GENESISAPI geBoolean GENESISCC geBitmap_GetInfo (const geBitmap *Bmp, geBitmap_Info *Info, geBitmap_Info *SecondaryInfo)
geBoolean geBitmap_MakeDriverLockInfo (geBitmap *Bmp, int mip, geBitmap_Info *Into)
GENESISAPI int GENESISCC geBitmap_Width (const geBitmap *Bmp)
GENESISAPI int GENESISCC geBitmap_Height (const geBitmap *Bmp)
GENESISAPI geBoolean GENESISCC geBitmap_Blit (const geBitmap *Src, int SrcPositionX, int SrcPositionY, geBitmap *Dst, int DstPositionX, int DstPositionY, int SizeX, int SizeY)
GENESISAPI geBoolean GENESISCC geBitmap_BlitBitmap (const geBitmap *Src, geBitmap *Dst)
GENESISAPI geBoolean GENESISCC geBitmap_BlitBestMip (const geBitmap *Src, geBitmap *Dst)
GENESISAPI geBoolean GENESISCC geBitmap_BlitMip (const geBitmap *Src, int SrcMip, geBitmap *Dst, int DstMip)
geBoolean geBitmap_BlitMipRect (const geBitmap *Src, int SrcMip, int SrcX, int SrcY, geBitmap *Dst, int DstMip, int DstX, int DstY, int SizeX, int SizeY)
GENESISAPI geBoolean GENESISCC geBitmap_SetFormatMin (geBitmap *Bmp, gePixelFormat NewFormat)
GENESISAPI geBoolean GENESISCC geBitmap_SetFormat (geBitmap *Bmp, gePixelFormat NewFormat, geBoolean HasColorKey, uint32 ColorKey, const geBitmap_Palette *Palette)
GENESISAPI geBoolean GENESISCC geBitmap_SetColorKey (geBitmap *Bmp, geBoolean HasColorKey, uint32 ColorKey, geBoolean Smart)
geBoolean geBitmap_UsesColorKey (const geBitmap *Bmp)
GENESISAPI geBoolean GENESISCC geBitmap_SetPalette (geBitmap *Bmp, const geBitmap_Palette *Palette)
GENESISAPI geBitmap_Palette
*GENESISCC 
geBitmap_GetPalette (const geBitmap *Bmp)
GENESISAPI geBitmap *GENESISCC geBitmap_GetAlpha (const geBitmap *Bmp)
GENESISAPI geBoolean GENESISCC geBitmap_SetAlpha (geBitmap *Bmp, const geBitmap *AlphaBmp)
GENESISAPI geBoolean GENESISCC geBitmap_SetPreferredFormat (geBitmap *Bmp, gePixelFormat Format)
GENESISAPI gePixelFormat GENESISCC geBitmap_GetPreferredFormat (const geBitmap *Bmp)
GENESISAPI geBitmap *GENESISCC geBitmap_CreateFromFileName (const geVFile *BaseFS, const char *Name)
GENESISAPI geBoolean GENESISCC geBitmap_WriteToFileName (const geBitmap *Bmp, const geVFile *BaseFS, const char *Name)
geBoolean geBitmap_ReadFromBMP (geBitmap *Bmp, geVFile *F)
geBoolean geBitmap_IsTGA (geVFile *F)
geBoolean geBitmap_ReadFromTGA (geBitmap *Bmp, geVFile *File)
GENESISAPI geBitmap *GENESISCC geBitmap_CreateFromFile (geVFile *F)
GENESISAPI geBoolean GENESISCC geBitmap_WriteToFile (const geBitmap *Bmp, geVFile *F)
geBoolean geBitmap_ReadInfo (geBitmap *Bmp, geVFile *F)
geBoolean geBitmap_WriteInfo (const geBitmap *Bmp, geVFile *F)
geBoolean geBitmap_Palette_BlitData (gePixelFormat SrcFormat, const void *SrcData, const geBitmap_Palette *SrcPal, gePixelFormat DstFormat, void *DstData, const geBitmap_Palette *DstPal, int Pixels)
GENESISAPI geBitmap_Palette
*GENESISCC 
geBitmap_Palette_Create (gePixelFormat Format, int Size)
GENESISAPI geBoolean GENESISCC geBitmap_Palette_CreateRef (geBitmap_Palette *P)
GENESISAPI geBitmap_Palette
*GENESISCC 
geBitmap_Palette_CreateFromBitmap (geBitmap *Bmp, geBoolean Slow)
geBitmap_Palette *BITMAP_GENESIS_INTERNAL geBitmap_Palette_CreateFromDriver (DRV_Driver *Driver, gePixelFormat Format, int Size)
GENESISAPI geBitmap_Palette
*GENESISCC 
geBitmap_Palette_CreateCopy (const geBitmap_Palette *Palette)
GENESISAPI geBoolean GENESISCC geBitmap_Palette_Destroy (geBitmap_Palette **ppPalette)
GENESISAPI geBoolean GENESISCC geBitmap_Palette_Lock (geBitmap_Palette *P, void **pBits, gePixelFormat *pFormat, int *pSize)
GENESISAPI geBoolean GENESISCC geBitmap_Palette_UnLock (geBitmap_Palette *P)
GENESISAPI geBoolean GENESISCC geBitmap_Palette_SetFormat (geBitmap_Palette *P, gePixelFormat Format)
GENESISAPI geBoolean GENESISCC geBitmap_Palette_GetData (const geBitmap_Palette *P, void *Into, gePixelFormat Format, int Size)
GENESISAPI geBoolean GENESISCC geBitmap_Palette_GetInfo (const geBitmap_Palette *P, geBitmap_Info *pInfo)
GENESISAPI geBoolean GENESISCC geBitmap_Palette_SetData (geBitmap_Palette *P, const void *From, gePixelFormat Format, int Colors)
GENESISAPI geBoolean GENESISCC geBitmap_Palette_Copy (const geBitmap_Palette *Fm, geBitmap_Palette *To)
GENESISAPI geBoolean GENESISCC geBitmap_Palette_SetEntryColor (geBitmap_Palette *P, int Color, int R, int G, int B, int A)
GENESISAPI geBoolean GENESISCC geBitmap_Palette_GetEntryColor (const geBitmap_Palette *P, int Color, int *R, int *G, int *B, int *A)
GENESISAPI geBoolean GENESISCC geBitmap_Palette_SetEntry (geBitmap_Palette *P, int Color, uint32 Pixel)
GENESISAPI geBoolean GENESISCC geBitmap_Palette_GetEntry (const geBitmap_Palette *P, int Color, uint32 *Pixel)
GENESISAPI geBitmap_Palette
*GENESISCC 
geBitmap_Palette_CreateFromFile (geVFile *F)
GENESISAPI geBoolean GENESISCC geBitmap_Palette_WriteToFile (const geBitmap_Palette *P, geVFile *F)
geBoolean geBitmap_IsValid (const geBitmap *Bmp)
geBoolean geBitmap_Info_IsValid (const geBitmap_Info *Info)
geBoolean geBitmap_Palette_IsValid (const geBitmap_Palette *Pal)
GENESISAPI geBoolean GENESISCC geBitmap_GetAverageColor (const geBitmap *Bmp, int *pR, int *pG, int *pB)

Variables

int BitmapInit_RefCount = 0
MemPoolBitmapPool = NULL


Define Documentation

#define allocate ptr   )     ptr = geRam_Allocate(sizeof(*ptr))
 

Definition at line 81 of file bitmap.c.

Referenced by geBitmap_Palette_Create(), and geBitmap_Palette_CreateFromDriver().

#define clear ptr   )     memset(ptr,0,sizeof(*ptr))
 

Definition at line 82 of file bitmap.c.

Referenced by geBitmap_AttachToDriver(), geBitmap_Palette_Create(), and geBitmap_Palette_CreateFromDriver().

#define Debug  ) 
 

Definition at line 97 of file bitmap.c.

Referenced by geBitmap_Create_Base(), geBitmap_CreateRef(), geBitmap_Destroy(), geBitmap_Destroy_Base(), Hash_Add(), Hash_Create(), Hash_DeleteNode(), and Hash_Destroy().

#define GEBM_TAG   ((geBmTag_t)0x6D426547)
 

Definition at line 3731 of file bitmap.c.

Referenced by geBitmap_CreateFromFile(), and geBitmap_WriteToFile().

#define GEBM_VERSION   (((uint32)GEBM_VERSION_MAJOR<<4) + (uint32)GEBM_VERSION_MINOR)
 

Definition at line 3734 of file bitmap.c.

Referenced by geBitmap_CreateFromFile(), and geBitmap_WriteToFile().

#define INFO_FLAG_HAS_ALPHA   (1<<2)
 

Definition at line 4533 of file bitmap.c.

Referenced by geBitmap_ReadInfo(), and geBitmap_WriteInfo().

#define INFO_FLAG_HAS_CK   (1<<1)
 

Definition at line 4532 of file bitmap.c.

Referenced by geBitmap_ReadInfo(), and geBitmap_WriteInfo().

#define INFO_FLAG_HAS_PAL   (1<<3)
 

Definition at line 4534 of file bitmap.c.

Referenced by geBitmap_ReadInfo(), and geBitmap_WriteInfo().

#define INFO_FLAG_IF_NOT_LOG2_ARE_BYTE   (1<<5)
 

Definition at line 4536 of file bitmap.c.

Referenced by geBitmap_ReadInfo(), and geBitmap_WriteInfo().

#define INFO_FLAG_WH_ARE_LOG2   (1<<0)
 

Definition at line 4531 of file bitmap.c.

Referenced by geBitmap_ReadInfo(), and geBitmap_WriteInfo().

#define MAX_DRIVER_FORMATS   (100)
 

Definition at line 1082 of file bitmap.c.

Referenced by geBitmap_ChooseDriverFormat(), and geBitmap_CreateTHandle().

#define MIP_FLAG_COMPRESSED   (1<<4)
 

Definition at line 3739 of file bitmap.c.

Referenced by geBitmap_CreateFromFile(), and geBitmap_WriteToFile().

#define MIP_FLAG_PAETH_FILTERED   (1<<5)
 

Definition at line 3740 of file bitmap.c.

Referenced by geBitmap_CreateFromFile().

#define MIP_MASK   (0xF)
 

Definition at line 3738 of file bitmap.c.

Referenced by geBitmap_CreateFromFile(), and geBitmap_WriteToFile().

#define PALETTE_INFO_FLAG_COMPRESS   (1<<6)
 

Definition at line 5379 of file bitmap.c.

Referenced by geBitmap_Palette_CreateFromFile().

#define PALETTE_INFO_FLAG_SIZE256   (1<<5)
 

Definition at line 5378 of file bitmap.c.

Referenced by geBitmap_Palette_CreateFromFile(), and geBitmap_Palette_WriteToFile().

#define PALETTE_INFO_FORMAT_MASK   (0x1F)
 

Definition at line 5377 of file bitmap.c.

Referenced by geBitmap_Palette_CreateFromFile().

#define SHIFT_R_ROUNDUP val,
shift   )     (((val)+(1<<(shift)) - 1)>>(shift))
 

Definition at line 84 of file bitmap.c.

Referenced by geBitmap_BlitBestMip(), geBitmap_MakeMipInfo(), geBitmap_MipBytes(), geBitmap_UpdateMips_System(), and geBitmap_WriteToFile().

#define VERSION_MAJOR Version   )     (((Version)>>4)&0x0F)
 

Definition at line 3735 of file bitmap.c.

Referenced by geBitmap_CreateFromFile().

#define VERSION_MINOR Version   )     ((Version)&0x0F)
 

Definition at line 3736 of file bitmap.c.


Typedef Documentation

typedef uint32 geBmTag_t
 

Definition at line 3730 of file bitmap.c.

Referenced by geBitmap_CreateFromFile(), and geBitmap_WriteToFile().

typedef struct TGAHEADER TGAHEADER
 


Function Documentation

geBoolean EnumPFCB geRDriver_PixelFormat pFormat,
void *  Context
[static]
 

Definition at line 1084 of file bitmap.c.

References GE_TRUE, and geBoolean.

Referenced by geBitmap_CreateTHandle().

01085 {
01086 geRDriver_PixelFormat **pDriverFormatsPtr;
01087         pDriverFormatsPtr = Context;
01088         **pDriverFormatsPtr = *pFormat;
01089         (*pDriverFormatsPtr) += 1;
01090 return GE_TRUE;
01091 }

geBoolean geBitmap_AllocPalette geBitmap Bmp,
gePixelFormat  Format,
DRV_Driver Driver
 

Definition at line 327 of file bitmap.c.

References geBitmap_Info::ColorKey, geBitmap_Palette::ColorKey, geBitmap_Palette::ColorKeyIndex, geBitmap_Palette::DriverHandle, geBitmap::DriverHandle, geBitmap::DriverInfo, geBitmap_Palette::Format, geBitmap_Info::Format, GE_FALSE, GE_PIXELFORMAT_32BIT_ARGB, GE_PIXELFORMAT_32BIT_XRGB, GE_PIXELFORMAT_8BIT_PAL, GE_TRUE, geBitmap_Palette_Create(), geBitmap_Palette_CreateCopy(), geBitmap_Palette_CreateFromDriver(), geBoolean, geErrorLog_AddString, gePixelFormat_HasGoodAlpha(), gePixelFormat_IsRaw(), geBitmap_Palette::HasColorKey, geBitmap_Info::HasColorKey, geBitmap::Info, NULL, geBitmap_Info::Palette, and DRV_Driver::THandle_SetPalette.

Referenced by geBitmap_BlitData_Sub(), and geBitmap_SetPalette().

00328 {
00329 geBitmap_Info * BmpInfo;
00330         assert(Bmp);
00331 
00332         if ( Driver )
00333                 BmpInfo = &(Bmp->DriverInfo);
00334         else
00335                 BmpInfo = &(Bmp->Info);
00336 
00337         if ( ! gePixelFormat_IsRaw(Format) )
00338                 Format = GE_PIXELFORMAT_32BIT_XRGB;
00339 
00340         if ( ! BmpInfo->Palette )
00341         {
00342                 assert( BmpInfo->Format == GE_PIXELFORMAT_8BIT_PAL );
00343 
00344                 if ( Driver )
00345                 {
00346                 geBoolean BmpHasAlpha;
00347                         
00348                         BmpHasAlpha = GE_FALSE;
00349                         if ( gePixelFormat_HasGoodAlpha(Bmp->Info.Format) )
00350                                 BmpHasAlpha = GE_TRUE;
00351                         else if ( Bmp->Info.Palette && gePixelFormat_HasGoodAlpha(Bmp->Info.Palette->Format) )
00352                                 BmpHasAlpha = GE_TRUE;
00353 
00354                         if ( BmpHasAlpha || (Bmp->Info.HasColorKey && ! Bmp->DriverInfo.HasColorKey ) )
00355                                 Format = GE_PIXELFORMAT_32BIT_ARGB;
00356 
00357                         BmpInfo->Palette = geBitmap_Palette_CreateFromDriver(Driver,Format,256);
00358                 }
00359                 else
00360                 {                       
00361                         BmpInfo->Palette = geBitmap_Palette_Create(Format,256);
00362                 }
00363         }
00364 
00365         if ( ! BmpInfo->Palette )
00366                 return GE_FALSE;
00367 
00368         if ( BmpInfo->HasColorKey )
00369         {
00370                 if ( ! BmpInfo->Palette->HasColorKey )
00371                 {
00372                         BmpInfo->Palette->HasColorKey = GE_TRUE;
00373                         BmpInfo->Palette->ColorKey = 1; // <>
00374                 }
00375                 BmpInfo->Palette->ColorKeyIndex = BmpInfo->ColorKey;
00376         }
00377 
00378         if ( Driver )
00379         {
00380                 assert( Bmp->DriverHandle );
00381                 assert( BmpInfo->Palette->DriverHandle );
00382                 if ( ! Driver->THandle_SetPalette(Bmp->DriverHandle,BmpInfo->Palette->DriverHandle) )
00383                 {
00384                         geErrorLog_AddString(-1,"AllocPal : THandle_SetPalette", NULL);
00385                         return GE_FALSE;
00386                 }
00387         }
00388 
00389         if ( ! Bmp->Info.Palette )
00390         {
00391                 Bmp->Info.Palette = geBitmap_Palette_CreateCopy(BmpInfo->Palette);
00392         }
00393 
00394 return GE_TRUE;
00395 }

geBoolean geBitmap_AllocSystemMip geBitmap Bmp,
int  mip
 

Definition at line 303 of file bitmap.c.

References geBitmap::Data, GE_FALSE, GE_TRUE, geBitmap_MipBytes(), geBoolean, geRam_Allocate, geBitmap::LockOwner, and NULL.

Referenced by geBitmap_CreateFromFile(), geBitmap_CreateLockFromMip(), geBitmap_MakeSystemMips(), geBitmap_ReadFromBMP(), geBitmap_ReadFromTGA(), geBitmap_SetFormat(), geBitmap_Update_DriverToSystem(), and geBitmap_UpdateMips_System().

00304 {
00305         if ( ! Bmp )
00306         {
00307                 return GE_FALSE;
00308         }
00309 
00310         if ( Bmp->LockOwner && mip != 0 ) return GE_FALSE;
00311 
00312         if ( ! Bmp->Data[mip] )
00313         {
00314         int bytes;
00315                 bytes = geBitmap_MipBytes(Bmp,mip);
00316                 if ( bytes == 0 )
00317                 {
00318                         Bmp->Data[mip] = NULL;
00319                         return GE_TRUE;
00320                 }
00321                 Bmp->Data[mip] = geRam_Allocate( bytes );
00322         }
00323 
00324 return (Bmp->Data[mip]) ? GE_TRUE : GE_FALSE;
00325 }

geBoolean BITMAP_GENESIS_INTERNAL geBitmap_AttachToDriver geBitmap Bmp,
DRV_Driver Driver,
uint32  DriverFlags
 

Definition at line 1577 of file bitmap.c.

References geBitmap::Alpha, BITMAP_GENESIS_INTERNAL, clear, geBitmap::DataOwner, geBitmap::Driver, geBitmap::DriverFlags, geBitmap::DriverHandle, geBitmap::DriverInfo, geBitmap_Info::Format, GE_FALSE, GE_TRUE, geBitmap_CreateTHandle(), geBitmap_DetachDriver(), geBitmap_HasAlpha(), geBitmap_IsValid(), geBitmap_MakeDriverLockInfo(), geBitmap_Update_SystemToDriver(), geBoolean, geErrorLog_AddString, gePixelFormat_HasGoodAlpha(), geBitmap_Info::HasColorKey, geBitmap_Info::Height, geBitmap::Info, geBitmap::LockCount, geBitmap::LockOwner, max, geBitmap_Info::MaximumMip, geBitmap_Info::MinimumMip, NULL, geBitmap::PreferredFormat, RDRIVER_PF_3D, geBitmap::SeekMipCount, DRV_Driver::THandle_Destroy, and geBitmap_Info::Width.

Referenced by BitmapList_AttachAll(), geBitmap_ClearMips(), geBitmap_SetFormat(), geBitmap_SetMipCount(), geBitmap_SetPreferredFormat(), and geBitmap_Update_SystemToDriver().

01579 {
01580 
01581         /**************
01582         * When you want to change the Driver,
01583         * I still need a copy of the old one to get the bits out
01584         * of the old THandles.  That is:
01585         * 
01586         *       AttachDriver(Bmp,Driver)
01587         *       <do stuff>
01588         *       Change Driver Entries
01589         *       AttachDriver(Bmp,Driver)
01590         * 
01591         * is forbidden!  The two different options are :
01592         * 
01593         *       1.
01594         * 
01595         *       AttachDriver(Bmp,Driver)
01596         *       <do stuff>
01597         *       DetachDriver(Bmp)
01598         *       Change Driver Entries
01599         *       AttachDriver(Bmp,Driver)
01600         * 
01601         *       2.
01602         * 
01603         *       AttachDriver(Bmp,Driver1)
01604         *       <do stuff>
01605         *       Driver2 = copy of Driver1
01606         *       Change Driver2 Entries
01607         *       AttachDriver(Bmp,Driver2)
01608         *       Free Driver1
01609         * 
01610         * This isn't so critical when just changing modes,
01611         * but is critical when changing drivers.
01612         * 
01613         ****************/
01614 
01615         assert( geBitmap_IsValid(Bmp) );
01616 
01617         if ( Bmp->LockOwner || Bmp->DataOwner || Bmp->LockCount )
01618         {
01619                 geErrorLog_AddString(-1,"AttachToDriver : not an isolated bitmap", NULL);
01620                 return GE_FALSE;
01621         }
01622 
01623         if ( Bmp->DriverHandle && Bmp->Driver == Driver )
01624         {
01625                 assert( DriverFlags == 0 || DriverFlags == Bmp->DriverFlags );
01626                 return GE_TRUE;
01627         }
01628 
01629         if ( ! geBitmap_DetachDriver(Bmp,GE_TRUE) )
01630         {
01631                 geErrorLog_AddString(-1,"AttachToDriver : detach failed", NULL);
01632                 return GE_FALSE;
01633         }
01634 
01635         if ( DriverFlags == 0 )
01636         {
01637                 DriverFlags = Bmp->DriverFlags;
01638                 if ( ! DriverFlags )
01639                 {
01640                         //      return GE_FALSE;
01641                         // ? {}
01642                         DriverFlags = RDRIVER_PF_3D;
01643                 }
01644         }
01645 
01646         if ( Driver )
01647         {
01648         int NumMipLevels;
01649         int Width,Height;
01650         geBoolean WantAlpha;
01651         geRDriver_THandle * DriverHandle;
01652 
01653 //              if ( Bmp->DriverFlags & RDRIVER_PF_COMBINE_LIGHTMAP )
01654 //                      Bmp->SeekMipCount = max(Bmp->SeekMipCount,4);
01655 
01656                 NumMipLevels = max(Bmp->SeekMipCount,(Bmp->Info.MaximumMip + 1));
01657                 if ( NumMipLevels > 4 ) NumMipLevels = 4; // {} kind of a hack, our drivers ignore mips > 4
01658 
01659                 // make sizes power-of-two and square
01660                 // {} note : must let drivers do this to correctly scale UV's 
01661                 Width   = Bmp->Info.Width;
01662                 Height  = Bmp->Info.Height;
01663 
01664                 WantAlpha = geBitmap_HasAlpha(Bmp);
01665                 if ( gePixelFormat_HasGoodAlpha(Bmp->PreferredFormat) )
01666                         WantAlpha = GE_TRUE;
01667 
01668                 assert( geBitmap_IsValid(Bmp) );
01669 
01670                 DriverHandle = geBitmap_CreateTHandle(Driver,Width,Height,NumMipLevels,
01671                         Bmp->PreferredFormat,Bmp->Info.Format,Bmp->Info.HasColorKey,
01672                         WantAlpha, (Bmp->Alpha) ? GE_TRUE : GE_FALSE,
01673                         DriverFlags);
01674 
01675                 assert( geBitmap_IsValid(Bmp) );
01676 
01677                 if ( ! DriverHandle )
01678                         return GE_FALSE;
01679 
01680                 Bmp->DriverHandle = DriverHandle;
01681                 Bmp->Driver = Driver;
01682                 Bmp->DriverFlags = DriverFlags;
01683 
01684 #ifdef _DEBUG
01685                 Bmp->DriverInfo = Bmp->Info;
01686                 assert( geBitmap_IsValid(Bmp) );
01687 #endif
01688                 clear(&(Bmp->DriverInfo));
01689 
01690                 if ( ! geBitmap_MakeDriverLockInfo(Bmp,0,&(Bmp->DriverInfo)) )
01691                 {
01692                         geErrorLog_AddString(-1,"AttachToDriver : updateinfo", NULL);
01693                         return GE_FALSE;
01694                 }
01695 
01696                 Bmp->DriverInfo.MinimumMip = 0;
01697                 Bmp->DriverInfo.MaximumMip = NumMipLevels - 1;
01698                 
01699                 assert( geBitmap_IsValid(Bmp) );
01700 
01701                 assert( geBitmap_IsValid(Bmp) );
01702 
01703                 if ( ! geBitmap_Update_SystemToDriver(Bmp) )
01704                 {
01705                         geErrorLog_AddString(-1,"AttachToDriver : Update_SystemToDriver", NULL);
01706                         Driver->THandle_Destroy(Bmp->DriverHandle);
01707                         Bmp->DriverHandle = NULL;
01708                         return GE_FALSE;
01709                 }
01710 
01711                 // {} Palette : Update_System calls Blit_Data, which should build it for us 
01712                 //              if Driver is pal & System isn't
01713         }
01714 
01715 return GE_TRUE;
01716 }

GENESISAPI geBoolean GENESISCC geBitmap_Blit const geBitmap Src,
int  SrcPositionX,
int  SrcPositionY,
geBitmap Dst,
int  DstPositionX,
int  DstPositionY,
int  SizeX,
int  SizeY
 

Definition at line 2902 of file bitmap.c.

References geBitmap_BlitMipRect(), geBitmap_IsValid(), geBoolean, GENESISAPI, GENESISCC, SizeX, and SizeY.

Referenced by geFont_DrawTextToBitmap().

02905 {
02906         assert( geBitmap_IsValid(Src) );
02907         assert( geBitmap_IsValid(Dst) );
02908         return geBitmap_BlitMipRect(Src,0,SrcPositionX,SrcPositionY,
02909                                                                 Dst,0,DstPositionX,DstPositionY,
02910                                                                 SizeX,SizeY);
02911 }

GENESISAPI geBoolean GENESISCC geBitmap_BlitBestMip const geBitmap Src,
geBitmap Dst
 

Definition at line 2921 of file bitmap.c.

References geBitmap_BlitMipRect(), geBitmap_IsValid(), geBoolean, GENESISAPI, GENESISCC, geBitmap::Info, SHIFT_R_ROUNDUP, and geBitmap_Info::Width.

02922 {
02923 int Width,Mip;
02924         assert( geBitmap_IsValid(Src) );
02925         assert( geBitmap_IsValid(Dst) );
02926         assert( Src != Dst );
02927         for(Mip=0;      (Width = SHIFT_R_ROUNDUP(Src->Info.Width,Mip)) > Dst->Info.Width ; Mip++) ;
02928         return geBitmap_BlitMipRect(Src,Mip,0,0,Dst,0,0,0,-1,-1);
02929 }

GENESISAPI geBoolean GENESISCC geBitmap_BlitBitmap const geBitmap Src,
geBitmap Dst
 

Definition at line 2913 of file bitmap.c.

References geBitmap_BlitMipRect(), geBitmap_IsValid(), geBoolean, GENESISAPI, and GENESISCC.

Referenced by BumpMap_Create(), geBitmap_BlitData_Sub(), geBitmapUtil_SetAlphaFromBrightness(), geEngine_InitFonts(), and Plasma_Create().

02914 {
02915         assert( geBitmap_IsValid(Src) );
02916         assert( geBitmap_IsValid(Dst) );
02917         assert( Src != Dst );
02918         return geBitmap_BlitMipRect(Src,0,0,0,Dst,0,0,0,-1,-1);
02919 }

GENESISAPI geBoolean GENESISCC geBitmap_BlitMip const geBitmap Src,
int  SrcMip,
geBitmap Dst,
int  DstMip
 

Definition at line 2931 of file bitmap.c.

References geBitmap_BlitMipRect(), geBitmap_IsValid(), geBoolean, GENESISAPI, and GENESISCC.

Referenced by geBitmap_CreateLockFromMip().

02932 {
02933         assert( geBitmap_IsValid(Src) );
02934         assert( geBitmap_IsValid(Dst) );
02935         return geBitmap_BlitMipRect(Src,SrcMip,0,0,Dst,DstMip,0,0,-1,-1);
02936 }

geBoolean geBitmap_BlitMipRect const geBitmap Src,
int  SrcMip,
int  SrcX,
int  SrcY,
geBitmap Dst,
int  DstMip,
int  DstX,
int  DstY,
int  SizeX,
int  SizeY
 

Definition at line 2938 of file bitmap.c.

References geBitmap::DriverHandle, geBitmap::DriverInfo, geBitmap_Info::Format, GE_FALSE, GE_TRUE, geBitmap_BlitData(), geBitmap_GetBits(), geBitmap_LockForReadNative(), geBitmap_LockForWrite(), geBitmap_UnLock(), geBoolean, geErrorLog_AddString, gePixelFormat_BytesPerPel(), geBitmap_Info::Height, geBitmap::Info, geBitmap::LockCount, geBitmap::LockOwner, min, NULL, SizeX, SizeY, geBitmap_Info::Stride, uint8, and geBitmap_Info::Width.

Referenced by geBitmap_Blit(), geBitmap_BlitBestMip(), geBitmap_BlitBitmap(), and geBitmap_BlitMip().

02941 {
02942 geBitmap * SrcLock=NULL,* DstLock=NULL;
02943 geBoolean SrcUnLock,DstUnLock;
02944 geBitmap_Info *SrcLockInfo,*DstLockInfo;
02945 uint8 *SrcBits,*DstBits;
02946         
02947         assert(Src && Dst);
02948         assert( Src != Dst );
02949         // <> if Src == Dst we could still do this, but we assert SrcMip != DstMip & be smart
02950 
02951         SrcUnLock = DstUnLock = GE_FALSE;
02952 
02953         if ( Src->LockOwner )
02954         {
02955                 assert( Src->LockOwner->LockCount );
02956                 if ( SrcMip != 0 )
02957                 {
02958                         geErrorLog_AddString(-1,"BlitMipRect : Src is a lock and mip != 0", NULL);
02959                         goto fail;
02960                 }
02961 
02962                 SrcLock = (geBitmap *)Src;
02963         }
02964         else
02965         {
02966                 if ( ! geBitmap_LockForReadNative((geBitmap *)Src,&SrcLock,SrcMip,SrcMip) )
02967                 {
02968                         geErrorLog_AddString(-1,"BlitMipRect : LockForReadNative", NULL);
02969                         goto fail;
02970                 }
02971                 SrcUnLock = GE_TRUE;
02972         }
02973 
02974         if ( Dst->LockOwner )
02975         {
02976                 if ( DstMip != 0 )
02977                         goto fail;
02978 //              if ( Dst->LockOwner->LockCount >= 0 )
02979 //                      goto fail;
02980 //              {} can't check this, cuz we use _BlitMip to create locks for read
02981                 DstLock = Dst;
02982         }
02983         else
02984         {
02985                 if ( ! geBitmap_LockForWrite(Dst,&DstLock,DstMip,DstMip) )
02986                 {
02987                         geErrorLog_AddString(-1,"BlitMipRect : LockForWrite", NULL);
02988                         goto fail;
02989                 }
02990                 DstUnLock = GE_TRUE;
02991         }
02992 
02993         Src = Dst = NULL;
02994 
02995         if ( SrcLock->DriverHandle ) 
02996                 SrcLockInfo = &(SrcLock->DriverInfo);
02997         else
02998                 SrcLockInfo = &(SrcLock->Info);
02999 
03000         if ( DstLock->DriverHandle ) 
03001                 DstLockInfo = &(DstLock->DriverInfo);
03002         else
03003                 DstLockInfo = &(DstLock->Info);
03004 
03005         if ( ! (SrcBits = geBitmap_GetBits(SrcLock)) || 
03006                  ! (DstBits = geBitmap_GetBits(DstLock)) )
03007         {
03008                 geErrorLog_AddString(-1,"BlitMipRect : GetBits", NULL);
03009                 goto fail;
03010         }
03011 
03012         if ( SizeX < 0 )
03013                 SizeX = min(SrcLockInfo->Width,DstLockInfo->Width);
03014         if ( SizeY < 0 )
03015                 SizeY = min(SrcLockInfo->Height,DstLockInfo->Height);
03016 
03017         if (( (SrcX + SizeX) > SrcLockInfo->Width ) ||
03018                 ( (SrcY + SizeY) > SrcLockInfo->Height) ||
03019                 ( (DstX + SizeX) > DstLockInfo->Width ) ||
03020                 ( (DstY + SizeY) > DstLockInfo->Height))
03021         {
03022                 geErrorLog_AddString(-1,"BlitMipRect : dimensions bad", NULL);
03023                 goto fail;
03024         }
03025 
03026         SrcBits += gePixelFormat_BytesPerPel(SrcLockInfo->Format) * ( SrcY * SrcLockInfo->Stride + SrcX );
03027         DstBits += gePixelFormat_BytesPerPel(DstLockInfo->Format) * ( DstY * DstLockInfo->Stride + DstX );
03028 
03029         // _BlitMipRect : made palette
03030         if ( ! geBitmap_BlitData(       SrcLockInfo,SrcBits,SrcLock,
03031                                                                 DstLockInfo,DstBits,DstLock,
03032                                                                 SizeX,SizeY) )
03033         {
03034                 goto fail;
03035         }
03036 
03037         if ( SrcUnLock ) geBitmap_UnLock(SrcLock);
03038         if ( DstUnLock ) geBitmap_UnLock(DstLock);
03039 
03040         return GE_TRUE;
03041 
03042         fail:
03043 
03044         if ( SrcUnLock ) geBitmap_UnLock(SrcLock);
03045         if ( DstUnLock ) geBitmap_UnLock(DstLock);
03046 
03047         return GE_FALSE;
03048 }

geBoolean geBitmap_ChooseDriverFormat gePixelFormat  SeekFormat1,
gePixelFormat  SeekFormat2,
geBoolean  SeekCK,
geBoolean  SeekAlpha,
geBoolean  SeekSeparates,
uint32  SeekFlags,
geRDriver_PixelFormat DriverFormatsArray,
int  ArrayLen,
geRDriver_PixelFormat pTarget
 

Definition at line 1115 of file bitmap.c.

References A, gePixelFormat_Operations::AMask, gePixelFormat_Operations::AShift, B, gePixelFormat_Operations::BMask, gePixelFormat_Operations::BShift, geRDriver_PixelFormat::Flags, G, GE_BOOLSAME, GE_FALSE, GE_PIXELFORMAT_16BIT_1555_ARGB, GE_TRUE, geBoolean, geErrorLog_AddString, gePixelFormat_GetOperations(), gePixelFormat_HasGoodAlpha(), gePixelFormat_HasPalette(), gePixelFormat_IsRaw(), gePixelFormat_Operations::GMask, gePixelFormat_Operations::GShift, MAX_DRIVER_FORMATS, NULL, NumBitsOn(), geRDriver_PixelFormat::PixelFormat, R, RDRIVER_PF_ALPHA, RDRIVER_PF_CAN_DO_COLORKEY, RDRIVER_PF_HAS_ALPHA, RDRIVER_PF_MAJOR_MASK, RDRIVER_PF_PALETTE, gePixelFormat_Operations::RMask, gePixelFormat_Operations::RShift, and uint32.

Referenced by geBitmap_CreateTHandle().

01124 {
01125 int i,rating;
01126 int FormatRating[MAX_DRIVER_FORMATS];
01127 geRDriver_PixelFormat * DriverPalFormat;
01128 geRDriver_PixelFormat * pf;
01129 geBoolean FoundAlpha;
01130 uint32 SeekMajor,SeekMinor;
01131 const gePixelFormat_Operations *seekops,*pfops;
01132 
01133         assert(pTarget && DriverFormatsArray && ArrayLen > 0);
01134 
01135         if ( SeekAlpha )
01136                 SeekCK = GE_FALSE;      // you can't have both
01137 
01138         if ( SeekFlags & RDRIVER_PF_ALPHA )
01139                 SeekFlags = RDRIVER_PF_ALPHA;
01140         else if ( SeekFlags & RDRIVER_PF_PALETTE )
01141                 SeekFlags = RDRIVER_PF_PALETTE;
01142 
01143         SeekMajor = SeekFlags & RDRIVER_PF_MAJOR_MASK;
01144         SeekMinor = SeekFlags - SeekMajor;
01145 
01146         pf = DriverFormatsArray;
01147         DriverPalFormat = NULL;
01148         for(i=0;i<ArrayLen;i++)
01149         {
01150                 if ( pf->Flags & RDRIVER_PF_PALETTE )
01151                 {
01152                         if ( ! DriverPalFormat || gePixelFormat_HasGoodAlpha(pf->PixelFormat) )
01153                                 DriverPalFormat = pf;
01154                 }
01155                 pf++;
01156         }
01157 
01158         seekops = gePixelFormat_GetOperations(SeekFormat1);
01159 
01160         for(i=0;i<ArrayLen;i++)
01161         {
01162                 pf = DriverFormatsArray + i;
01163                 rating = 0;
01164 
01165                 /***
01166                 {}
01167 
01168                 this is the code to try to pick the closest format the driver has to offer
01169                 the choosing precedence is :
01170 
01171                         1. if want alpha, get alpha
01172                         2. match the _3D_ type flags exactly (PF_MAJOR)
01173                         3. match PreferredFormat
01174                         4. match the bitmap's system format
01175                         5. match up the pixel formats masks
01176 
01177                 we use fuzzy logic : we apply rating to all the matches and then choose
01178                 the one with the best rating.
01179 
01180                 possible todos :
01181                         1. be aware of memory use and format-conversion times, and penalize
01182                                 or favor formats accordingly
01183 
01184                 note : we currently try to use 1555 for colorkey.
01185 
01186                 ***/
01187 
01188                 if ( (pf->Flags & RDRIVER_PF_MAJOR_MASK) == SeekMajor )
01189                 {
01190                         rating += 1<<23;
01191                 }
01192                 else if ( (pf->Flags & SeekMajor) != SeekMajor )
01193                 {
01194                     FormatRating[i] = 0;
01195                         continue;
01196                 }
01197                 else
01198                 {
01199                         // advantage to as few different major flags as possible
01200                         // higher priority than similarity of pixelformats
01201                         rating += (32 - NumBitsOn( (pf->Flags ^ SeekFlags) & RDRIVER_PF_MAJOR_MASK ))<<6;
01202                 }
01203 
01204                 pfops = gePixelFormat_GetOperations(pf->PixelFormat);
01205 
01206                 if ( pf->PixelFormat == SeekFormat1 )
01207                 {
01208                         rating += 1<<16;
01209                 }
01210                 else if ( pf->PixelFormat == SeekFormat2 )
01211                 {
01212                         rating += 1<<15;
01213                 }
01214                 else if ( gePixelFormat_IsRaw(SeekFormat1) && gePixelFormat_IsRaw(pf->PixelFormat) )
01215                 {
01216                 int R,G,B,A;
01217                         // measure similarity
01218                         R = (seekops->RMask >> seekops->RShift) ^ (pfops->RMask >> pfops->RShift);
01219                         G = (seekops->GMask >> seekops->GShift) ^ (pfops->GMask >> pfops->GShift);
01220                         B = (seekops->BMask >> seekops->BShift) ^ (pfops->BMask >> pfops->BShift);
01221                         A = (seekops->AMask >> seekops->AShift) ^ (pfops->AMask >> pfops->AShift);
01222                         R = 8 - NumBitsOn(R);
01223                         G = 8 - NumBitsOn(G);
01224                         B = 8 - NumBitsOn(B);
01225                         A = 4*(8 - NumBitsOn(A)); // right number of A bits is molto importante
01226                         rating += (R + G + B + A);
01227                 }
01228                 else
01229                 {
01230                         // one of the formats is not raw
01231                         // palettized ? compressed ?
01232                         rating += 16;
01233                 }
01234 
01235                 FoundAlpha = GE_FALSE;
01236 
01237                 if ( NumBitsOn(pfops->AMask) > 2 )
01238                         FoundAlpha = GE_TRUE;
01239 
01240                 if ( gePixelFormat_HasPalette(pf->PixelFormat) )
01241                 {
01242             // if Pixelformat is 8BIT_PAL , look at the palette's format to see if it
01243                         //              had alpha!
01244                         assert(DriverPalFormat);
01245                         if ( gePixelFormat_HasGoodAlpha(DriverPalFormat->PixelFormat) )
01246                                 FoundAlpha = GE_TRUE;
01247                 }
01248 
01249                 if ( SeekAlpha && FoundAlpha )
01250                         rating += 1<<24; // HIGHEST ! (except separates)
01251                 else if ( (!SeekAlpha) && (!FoundAlpha) )
01252                         rating += 1<<10; // LOWEST
01253                 else if ( SeekAlpha )
01254                 {
01255                         if ( NumBitsOn(pfops->AMask) || pf->Flags & RDRIVER_PF_CAN_DO_COLORKEY )
01256                         {
01257                                 // sought Alpha, found CK
01258                                 rating += 1<<19;
01259                         }
01260                 }
01261 
01262                 if ( (pf->Flags & RDRIVER_PF_HAS_ALPHA) && SeekSeparates )
01263                 {
01264                         // separates doesn't count as alpha unless we asked for it !
01265                         rating += 1<<25; // VERY HIGHEST !
01266                 }
01267         
01268                 if ( SeekCK ) 
01269                 {
01270                         if ( pf->PixelFormat == GE_PIXELFORMAT_16BIT_1555_ARGB )
01271                         {
01272                                 rating += 1<<23; // just lower than alpha
01273                         }
01274                         else if ( FoundAlpha ) //better than nothing!
01275                         {
01276                                 rating += 1<<18;        // higher than !FoundAlpha
01277                         }
01278                 }
01279 
01280                 if ( GE_BOOLSAME((pf->Flags & RDRIVER_PF_CAN_DO_COLORKEY),SeekCK) )
01281                 {
01282                         rating += 1<<17;
01283                 }
01284 
01285                 FormatRating[i] = rating;
01286         }
01287 
01288         rating = 0;
01289 
01290         for(i=0;i<ArrayLen;i++)
01291         {
01292                 if ( FormatRating[i] > rating )
01293                 {
01294                         rating = FormatRating[i];
01295                         *pTarget = DriverFormatsArray[i];
01296                 }
01297         }
01298 
01299         if ( rating == 0)
01300         {
01301                 geErrorLog_AddString(-1,"ChooseDriverFormat : no valid formats found!", NULL);
01302                 return GE_FALSE;
01303         }
01304 
01305         return GE_TRUE;
01306 }

GENESISAPI geBoolean GENESISCC geBitmap_ClearMips geBitmap Bmp  ) 
 

Definition at line 2681 of file bitmap.c.

References geBitmap::Data, geBitmap::DataOwner, geBitmap::Driver, GE_FALSE, GE_TRUE, geBitmap_AttachToDriver(), geBitmap_DetachDriver(), geBitmap_IsValid(), geBoolean, GENESISAPI, GENESISCC, geRam_Free, geBitmap::Info, geBitmap::LockCount, geBitmap::LockOwner, geBitmap_Info::MaximumMip, geBitmap_Info::MinimumMip, NULL, and geBitmap::SeekMipCount.

Referenced by BumpMap_Create(), ElectricFx_InitBitmap(), Fire_Create(), geBitmap_SetFormat(), Particles_InitBitmap(), Plasma_Create(), Smoke_InitBitmap(), and Water_Create().

02682 {
02683 int mip;
02684 DRV_Driver * Driver;
02685 
02686         // WARNING ! This destroys any mips!
02687 
02688         assert( geBitmap_IsValid(Bmp) );
02689 
02690         if ( Bmp->LockOwner || Bmp->LockCount || Bmp->DataOwner )
02691                 return GE_FALSE;
02692 
02693         if ( Bmp->SeekMipCount == 0 && Bmp->Info.MaximumMip == 0 )
02694                 return GE_TRUE;
02695 
02696         Driver = Bmp->Driver;
02697         if ( Driver )
02698         {
02699                 if ( ! geBitmap_DetachDriver(Bmp,GE_TRUE) )
02700                         return GE_FALSE;
02701         }
02702         assert(Bmp->Driver == NULL);
02703 
02704         mip = Bmp->Info.MinimumMip;
02705         if ( mip == 0 ) 
02706                 mip++;
02707 
02708         Bmp->SeekMipCount = mip;
02709 
02710         for( ; mip <= Bmp->Info.MaximumMip ; mip++)
02711         {
02712                 if ( Bmp->Data[mip] )
02713                 {
02714                         geRam_Free( Bmp->Data[mip] );
02715                         Bmp->Data[mip] = NULL;
02716                 }
02717         }
02718 
02719         Bmp->Info.MaximumMip = Bmp->Info.MinimumMip;
02720 
02721         if ( Driver )
02722         {
02723                 if ( ! geBitmap_AttachToDriver(Bmp,Driver,0) )
02724                         return GE_FALSE;
02725         }
02726 
02727 return GE_TRUE;
02728 }

GENESISAPI geBitmap* GENESISCC geBitmap_Create int  Width,
int  Height,
int  MipCount,
gePixelFormat  Format
 

Definition at line 166 of file bitmap.c.

References geBitmap_Info::Format, GE_FALSE, GE_PIXELFORMAT_WAVELET, geBitmap_Create_Base(), geErrorLog_AddString, GENESISAPI, GENESISCC, geBitmap_Info::HasColorKey, geBitmap_Info::Height, geBitmap::Info, geBitmap_Info::MaximumMip, geBitmap_Info::MinimumMip, NULL, geBitmap::SeekMipCount, geBitmap_Info::Stride, and geBitmap_Info::Width.

Referenced by BumpMap_Create(), ElectricFx_InitBitmap(), Fire_Create(), geBitmapUtil_CreateFromHBITMAP(), geEngine_InitFonts(), geFont_AddBitmapBuffer(), geFont_AddCharacters(), geWBitmap_Pool_CreateAllWBitmaps(), Particles_InitBitmap(), Plasma_Create(), and Smoke_InitBitmap().

00171 {
00172 geBitmap * Bmp;
00173 
00174         Bmp = geBitmap_Create_Base();
00175         if ( ! Bmp )
00176                 return NULL;
00177 
00178         assert( Width > 0 );
00179         assert( Height > 0 );
00180         if ( MipCount == 0 )
00181                 MipCount = 1;
00182         assert( MipCount > 0 );
00183 
00184         Bmp->Info.Width = Width;
00185         Bmp->Info.Stride = Width;
00186         Bmp->Info.Height = Height;
00187         Bmp->Info.Format = Format;
00188 
00189         Bmp->Info.MinimumMip = 0;
00190         Bmp->Info.MaximumMip = 0;
00191         Bmp->Info.HasColorKey = GE_FALSE;
00192 
00193         Bmp->SeekMipCount = MipCount;
00194 
00195         if ( Format == GE_PIXELFORMAT_WAVELET )
00196         {
00197                 geErrorLog_AddString(-1,"Genesis3D 1.0 does not support Wavelet Images",NULL);
00198                 return NULL;
00199         }
00200 
00201 return Bmp;
00202 }

geBitmap* geBitmap_Create_Base void   ) 
 

Definition at line 130 of file bitmap.c.

References BitmapPool, Debug, geBitmap::DriverGamma, geBitmap::DriverGammaLast, geBitmap_Start(), MemPool_GetHunk(), and geBitmap::RefCount.

Referenced by geBitmap_Create(), geBitmap_CreateFromFile(), geBitmap_CreateFromInfo(), geBitmap_CreateLock_CopyInfo(), and geBitmap_ReadFromTGA().

00131 {
00132 geBitmap * Bmp;
00133 
00134         geBitmap_Start();
00135 
00136         Bmp = MemPool_GetHunk(BitmapPool);
00137 
00138         Bmp->RefCount = 1;
00139 
00140         Bmp->DriverGamma = Bmp->DriverGammaLast = 1.0f;
00141 
00142         Debug(_Bitmap_Debug_ActiveRefs ++);
00143         Debug(_Bitmap_Debug_ActiveCount ++);
00144 
00145 return Bmp;
00146 }

GENESISAPI geBitmap* GENESISCC geBitmap_CreateFromFile geVFile F  ) 
 

Definition at line 3747 of file bitmap.c.

References geBitmap::Alpha, geBitmap::Data, geBitmap_Info::Format, GE_FALSE, GE_PIXELFORMAT_WAVELET, GE_TRUE, GE_VFILE_OPEN_READONLY, GE_VFILE_SEEKCUR, geBitmap_AllocSystemMip(), geBitmap_Create_Base(), geBitmap_Destroy(), geBitmap_IsTGA(), geBitmap_MipBytes(), geBitmap_Palette_CreateFromFile(), geBitmap_ReadFromBMP(), geBitmap_ReadFromTGA(), geBitmap_ReadInfo(), GEBM_TAG, GEBM_VERSION, geBmTag_t, geErrorLog_AddString, GENESISAPI, GENESISCC, geVFile_Close(), geVFile_OpenNewSystem(), geVFile_Read(), geVFile_Seek(), geBitmap::Info, geBitmap_Info::MaximumMip, geBitmap_Info::MinimumMip, MIP_FLAG_COMPRESSED, MIP_FLAG_PAETH_FILTERED, MIP_MASK, geBitmap::Modified, NULL, geBitmap_Info::Palette, geBitmap_Info::Stride, uint8, VERSION_MAJOR, and geBitmap_Info::Width.

Referenced by geBitmap_CreateFromFileName(), geBitmapUtil_CreateFromFileName(), geBody_CreateFromFile(), geEngine_InitFonts(), GetABitmap(), and Text_Create().

03748 {
03749         geBitmap *      Bmp;
03750         geBmTag_t Tag;
03751 
03752         assert(F);
03753 
03754         if ( ! geVFile_Read(F, &Tag, sizeof(Tag)) )
03755                 return NULL;
03756 
03757         Bmp = geBitmap_Create_Base();
03758         if ( ! Bmp )
03759                 return NULL;
03760 
03761         if ( Tag == GEBM_TAG )
03762         {
03763                 uint8 flags;
03764                 uint8 Version;
03765                 int mip;
03766 
03767                 // see WriteToFile for comments on the file format
03768 
03769                 if ( ! geVFile_Read(F, &Version, sizeof(Version)) )
03770                         goto fail;
03771 
03772                 if ( VERSION_MAJOR(Version) != VERSION_MAJOR(GEBM_VERSION) )
03773                 {
03774                         geErrorLog_AddString(-1,"CreateFromFile : incompatible GeBm version", NULL);    
03775                         goto fail;
03776                 }
03777 
03778                 if ( ! geBitmap_ReadInfo(Bmp,F) )
03779                         goto fail;
03780 
03781                 if ( Bmp->Info.Palette )
03782                 {
03783                         Bmp->Info.Palette = NULL;
03784                         if ( ! ( Bmp->Info.Palette = geBitmap_Palette_CreateFromFile(F)) )
03785                                 goto fail;
03786                 }
03787 
03788                 if ( Bmp->Info.Format == GE_PIXELFORMAT_WAVELET )
03789                 {
03790                         geErrorLog_AddString(-1,"Genesis3D 1.0 does not support Wavelet Images",NULL);
03791                 }
03792                 else
03793                 {
03794                         for(;;)
03795                         {
03796                                 if ( ! geVFile_Read(F, &flags, sizeof(flags)) )
03797                                         goto fail;
03798 
03799                                 mip = flags & MIP_MASK;
03800 
03801                                 if ( mip > Bmp->Info.MaximumMip )
03802                                         break;
03803 
03804                                 assert(mip >= Bmp->Info.MinimumMip );
03805                                 assert( Bmp->Info.Stride == Bmp->Info.Width );
03806 
03807                                 if ( ! geBitmap_AllocSystemMip(Bmp,mip) )
03808                                         goto fail;
03809 
03810                                 if ( flags & MIP_FLAG_COMPRESSED )
03811                                 {
03812                         #ifdef DO_LZ
03813                                 geVFile * LzF;
03814 
03815                                         LzF = geVFile_OpenNewSystem(F,GE_VFILE_TYPE_LZ,NULL,NULL,GE_VFILE_OPEN_READONLY);
03816                                         if ( ! LzF )
03817                                         {
03818                                                 geErrorLog_AddString(-1,"Bitmap_CreateFromFile : LZ File Open failed",NULL);
03819                                                 return GE_FALSE;
03820                                         }
03821 
03822                                         if ( ! geVFile_Read(LzF, Bmp->Data[mip], geBitmap_MipBytes(Bmp,mip) ) )
03823                                         {
03824                                                 geVFile_Close(LzF);
03825                                                 geErrorLog_AddString(-1,"Bitmap_CreateFromFile : LZ File Read failed",NULL);
03826                                                 return GE_FALSE;
03827                                         }
03828 
03829                                         if ( ! geVFile_Close(LzF) )
03830                                         {
03831                                                 geErrorLog_AddString(-1,"Bitmap_CreateFromFile : LZ File Close failed",NULL);
03832                                                 return GE_FALSE;
03833                                         }
03834                         #endif
03835                                 }
03836                                 else
03837                                 {
03838                                         if ( ! geVFile_Read(F, Bmp->Data[mip], geBitmap_MipBytes(Bmp,mip) ) )
03839                                                 goto fail;
03840                                 }
03841 
03842                                 if ( flags & MIP_FLAG_PAETH_FILTERED )
03843                                 {
03844                                         geErrorLog_AddString(-1,"Bitmap_CreateFromFile : Paeth Filter not supported in this version!",NULL);
03845                                         return GE_FALSE;
03846                                 }
03847 
03848                                 Bmp->Modified[mip] = GE_TRUE;
03849                         }
03850                 }
03851 
03852                 if( Bmp->Alpha )
03853                 {
03854                         if ( ! (Bmp->Alpha = geBitmap_CreateFromFile(F)) )
03855                                 goto fail;
03856                 }
03857         }       // end geBitmap reader
03858         else 
03859         {
03860                 if ( ! geVFile_Seek(F, - (int)sizeof(Tag), GE_VFILE_SEEKCUR) )
03861                         goto fail;
03862 
03863                 if ( (Tag&0xFFFF) == 0x4D42 )   // 'BM'
03864                 {
03865                 
03866                         if ( ! geBitmap_ReadFromBMP(Bmp,F) )
03867                                 goto fail;
03868                 }
03869                 else
03870                 {
03871                         
03872 // change QuestOfDreams
03873                         if (geBitmap_IsTGA(F))
03874                         {
03875                                 if( ! geBitmap_ReadFromTGA(Bmp, F))
03876                                         goto fail;
03877                         }
03878                         else 
03879                                 // geErrorLog_AddString(-1,"CreateFromFile : unknown format", NULL);
03880                                 goto fail;
03881 // end change QuestOfDreams
03882                 }
03883         }
03884 
03885         return Bmp;
03886 
03887 fail:
03888         assert(Bmp);
03889 
03890         geBitmap_Destroy(&Bmp);
03891         return NULL;
03892 }

GENESISAPI geBitmap* GENESISCC geBitmap_CreateFromFileName const geVFile BaseFS,
const char *  Name
 

Definition at line 3682 of file bitmap.c.

References GE_VFILE_OPEN_READONLY, GE_VFILE_TYPE_DOS, geBitmap_CreateFromFile(), GENESISAPI, GENESISCC, geVFile_Close(), geVFile_Open(), geVFile_OpenNewSystem(), and NULL.

Referenced by Client_CreateStatusBar(), GameMgr_SetTextureIndex(), GMenu_Create(), PathPoint_SetTexture(), and SetupConsole().

03683 {
03684         geVFile * File;
03685         geBitmap * Bitmap;
03686 
03687 
03688         if ( BaseFS )
03689         {
03690                 File = geVFile_Open((geVFile *)BaseFS, Name, GE_VFILE_OPEN_READONLY);
03691         }
03692         else
03693         {
03694                 File = geVFile_OpenNewSystem(NULL,GE_VFILE_TYPE_DOS,Name,NULL,GE_VFILE_OPEN_READONLY);
03695         }
03696         if ( ! File )
03697                         return NULL;
03698         
03699         Bitmap = geBitmap_CreateFromFile(File);
03700         geVFile_Close(File);
03701                 
03702         return Bitmap;
03703 }

GENESISAPI geBitmap* GENESISCC geBitmap_CreateFromInfo const geBitmap_Info pInfo  ) 
 

Definition at line 204 of file bitmap.c.

References geBitmap_Info::Format, GE_PIXELFORMAT_WAVELET, geBitmap_Create_Base(), geBitmap_Info_IsValid(), geBitmap_Palette_CreateRef(), geErrorLog_AddString, GENESISAPI, GENESISCC, geBitmap::Info, NULL, geBitmap_Info::Palette, geBitmap_Info::Stride, and geBitmap_Info::Width.

Referenced by geBitmapUtil_SetAlphaFromBrightness().

00205 {
00206 geBitmap * Bmp;
00207 
00208         assert(pInfo);
00209         assert(geBitmap_Info_IsValid(pInfo));
00210 
00211         Bmp = geBitmap_Create_Base();
00212         if ( ! Bmp )
00213                 return NULL;
00214 
00215         Bmp->Info = *pInfo;
00216 
00217         if ( Bmp->Info.Stride < Bmp->Info.Width )
00218                 Bmp->Info.Stride = Bmp->Info.Width;
00219 
00220         if ( Bmp->Info.Palette )
00221                 geBitmap_Palette_CreateRef(Bmp->Info.Palette);
00222 
00223         if ( Bmp->Info.Format == GE_PIXELFORMAT_WAVELET )
00224         {
00225                 geErrorLog_AddString(-1,"Genesis3D 1.0 does not support Wavelet Images",NULL);
00226                 return NULL;
00227         }
00228 
00229 return Bmp;
00230 }

geBitmap* geBitmap_CreateLock_CopyInfo geBitmap BmpSrc,
int  LockCnt,
int  mip
 

Definition at line 851 of file bitmap.c.

References geBitmap::Driver, geBitmap::DriverFlags, geBitmap::DriverGamma, geBitmap::DriverGammaLast, geBitmap::DriverInfo, geBitmap_Create_Base(), geBitmap_CreateRef(), geBitmap_IsValid(), geBitmap_MakeMipInfo(), geBitmap::Info, geBitmap::LockCount, geBitmap::LockOwner, NULL, geBitmap_Info::Palette, and geBitmap::PreferredFormat.

Referenced by geBitmap_CreateLockFromMip(), geBitmap_CreateLockFromMipOnDriver(), and geBitmap_CreateLockFromMipSystem().

00852 {
00853 geBitmap * Bmp;
00854 
00855         assert( geBitmap_IsValid(BmpSrc) );
00856 
00857         // all _CreateLocks go through here
00858 
00859         Bmp = geBitmap_Create_Base();
00860         if ( ! Bmp )
00861                 return NULL;
00862 
00863         geBitmap_MakeMipInfo(&(BmpSrc->Info),mip,&(Bmp->Info));
00864         geBitmap_MakeMipInfo(&(BmpSrc->DriverInfo),mip,&(Bmp->DriverInfo));
00865         Bmp->DriverFlags = BmpSrc->DriverFlags;
00866         Bmp->DriverGamma = BmpSrc->DriverGamma;
00867         Bmp->DriverGammaLast = BmpSrc->DriverGammaLast;
00868                 
00869         Bmp->Info.Palette = NULL;
00870         Bmp->DriverInfo.Palette = NULL;
00871 
00872         Bmp->Driver     = BmpSrc->Driver;
00873         Bmp->PreferredFormat= BmpSrc->PreferredFormat;
00874 
00875         Bmp->LockOwner = BmpSrc;
00876         geBitmap_CreateRef(BmpSrc); // we do a _Destroy() in UnLock()
00877 
00878         BmpSrc->LockCount += LockCnt;
00879 
00880 return Bmp;
00881 }

geBitmap* geBitmap_CreateLockFromMip geBitmap Src,
int  mip,
gePixelFormat  Format,
geBoolean  HasColorKey,
uint32  ColorKey,
int  LockCnt
 

Definition at line 895 of file bitmap.c.

References geBitmap::Alpha, geBitmap_Info::ColorKey, geBitmap::Data, geBitmap::DriverHandle, geBitmap::DriverInfo, geBitmap_Info::Format, GE_BOOLSAME, GE_PIXELFORMAT_8BIT_GRAY, geBitmap_AllocSystemMip(), geBitmap_BlitMip(), geBitmap_CreateLock_CopyInfo(), geBitmap_CreateLockFromMipOnDriver(), geBitmap_CreateLockFromMipSystem(), geBitmap_Destroy(), geBitmap_IsValid(), geBitmap_LockForRead(), geBitmap_MakeSystemMips(), geBitmap_Palette_CreateRef(), geBitmap_Update_DriverToSystem(), geErrorLog_AddString, gePixelFormat_BytesPerPel(), gePixelFormat_HasGoodAlpha(), gePixelFormat_HasPalette(), geBitmap_Info::HasColorKey, geBitmap::Info, geBitmap_Info::MaximumMip, MAXMIPLEVELS, geBitmap_Info::MinimumMip, NULL, geBitmap_Info::Palette, geBitmap_Info::Stride, and geBitmap_Info::Width.

Referenced by geBitmap_LockForRead().

00900 {
00901 geBitmap * Ret;
00902 
00903         assert( geBitmap_IsValid(Src) );
00904         if ( mip < 0 || mip >= MAXMIPLEVELS )
00905                 return NULL;
00906 
00907         // LockForRead always goes through here
00908 
00909         if ( gePixelFormat_BytesPerPel(Format) < 1 )
00910                 return NULL;
00911 
00912         if ( Src->DriverInfo.Format == Format &&
00913                  GE_BOOLSAME(Src->DriverInfo.HasColorKey,HasColorKey) &&
00914                  (!HasColorKey || Src->DriverInfo.ColorKey == ColorKey) &&
00915                  mip >= Src->DriverInfo.MinimumMip && mip <= Src->DriverInfo.MaximumMip )
00916         {
00917                 return geBitmap_CreateLockFromMipOnDriver(Src,mip,LockCnt);
00918         }
00919 
00920         if ( Src->DriverHandle )
00921         {
00922                 if ( ! geBitmap_Update_DriverToSystem(Src) )
00923                 {
00924                         return NULL;
00925                 }
00926         }
00927                 
00928         if ( ! Src->Data[mip] )
00929         {
00930                 if ( ! geBitmap_MakeSystemMips(Src,mip,mip) )
00931                         return NULL;
00932         }
00933 
00934         if ( Src->Info.Format == Format &&
00935                  GE_BOOLSAME(Src->Info.HasColorKey,HasColorKey) &&
00936                  (!HasColorKey || Src->Info.ColorKey == ColorKey) )
00937         {
00938                 return geBitmap_CreateLockFromMipSystem(Src,mip,LockCnt);
00939         }
00940 
00941         Ret = geBitmap_CreateLock_CopyInfo(Src,LockCnt,mip);
00942 
00943         if ( ! Ret )
00944                 return NULL;
00945 
00946         Ret->Info.Stride = Ret->Info.Width;     // {} ?
00947 
00948         Ret->Info.Format = Format;
00949         Ret->Info.ColorKey = ColorKey;
00950         Ret->Info.HasColorKey = HasColorKey;
00951 
00952         if ( gePixelFormat_HasPalette(Format) && Src->Info.Palette )
00953         {
00954                 Ret->Info.Palette = Src->Info.Palette;
00955                 geBitmap_Palette_CreateRef(Ret->Info.Palette);
00956         }
00957 
00958         assert( Ret->Alpha == NULL );
00959         if ( ! gePixelFormat_HasGoodAlpha(Format) && Src->Alpha )
00960         {
00961                 if ( ! geBitmap_LockForRead(Src->Alpha,&(Ret->Alpha),mip,mip,GE_PIXELFORMAT_8BIT_GRAY,0,0) )
00962                 {
00963                         geErrorLog_AddString(-1,"CreateLockFromMip : LockForRead failed", NULL);
00964                         geBitmap_Destroy(&Ret);
00965                         return NULL;
00966                 }
00967                 assert( Ret->Alpha );
00968         }
00969 
00970         assert( geBitmap_IsValid(Ret) );
00971 
00972         if ( ! geBitmap_AllocSystemMip(Ret,0) )
00973         {
00974                 geBitmap_Destroy(&Ret);
00975                 return NULL;
00976         }
00977 
00978         if ( ! geBitmap_BlitMip( Src, mip, Ret, 0 ) )
00979         {
00980                 geErrorLog_AddString(-1,"CreateLockFromMip : BlitMip failed", NULL);
00981                 geBitmap_Destroy(&Ret);
00982                 return NULL;
00983         }
00984 
00985 return Ret;
00986 }

geBitmap* geBitmap_CreateLockFromMipOnDriver geBitmap Src,
int  mip,
int  LockCnt
 

Definition at line 1035 of file bitmap.c.

References geBitmap::DataOwner, geBitmap::Driver, geBitmap::DriverHandle, geBitmap::DriverInfo, geBitmap::DriverMipLock, geBitmap_Info::Format, geBitmap_CreateLock_CopyInfo(), geBitmap_CreateRef(), geBitmap_Destroy(), geBitmap_IsValid(), geBitmap_MakeDriverLockInfo(), geBitmap_Palette_CreateRef(), geErrorLog_AddString, gePixelFormat_BytesPerPel(), geBitmap::Info, geBitmap_Info::MaximumMip, geBitmap_Info::MinimumMip, NULL, and geBitmap_Info::Palette.

Referenced by geBitmap_CreateLockFromMip(), geBitmap_LockForReadNative(), geBitmap_LockForWrite(), and geBitmap_LockForWriteFormat().

01036 {
01037 geBitmap * Ret;
01038 
01039         assert( geBitmap_IsValid(Src) );
01040         if ( ! Src->DriverHandle || ! Src->Driver || Src->DriverMipLock || mip < Src->DriverInfo.MinimumMip || mip > Src->DriverInfo.MaximumMip )
01041                 return NULL;
01042 
01043         // the driver can never have Wavelet data
01044         // {} it could have S3TC data, though..
01045         assert( gePixelFormat_BytesPerPel(Src->DriverInfo.Format) > 0);
01046 
01047         Ret = geBitmap_CreateLock_CopyInfo(Src,LockCnt,mip);
01048 
01049         if ( ! Ret ) return NULL;
01050 
01051         Ret->DriverMipLock = mip;
01052         Ret->DriverHandle = Src->DriverHandle;
01053 
01054         Ret->DataOwner = Src;
01055         geBitmap_CreateRef(Src);
01056 
01057         Ret->DriverInfo.Palette = Src->DriverInfo.Palette;
01058 
01059         if ( ! geBitmap_MakeDriverLockInfo(Ret,mip,&(Ret->DriverInfo)) )
01060         {
01061                 geErrorLog_AddString(-1,"CreateLockFromMipOnDriver : UpdateInfo failed", NULL);
01062                 geBitmap_Destroy(&Ret);
01063                 return NULL;
01064         }
01065 
01066         assert(Ret->DriverInfo.Palette == Src->DriverInfo.Palette);
01067 
01068         Ret->Info = Ret->DriverInfo;    //{} shouldn't be necessary
01069         
01070         if ( Ret->DriverInfo.Palette )
01071                 geBitmap_Palette_CreateRef(Ret->DriverInfo.Palette);
01072         if ( Ret->Info.Palette )
01073                 geBitmap_Palette_CreateRef(Ret->Info.Palette);
01074 
01075         assert( geBitmap_IsValid(Ret) );
01076 
01077 return Ret;
01078 }

geBitmap* geBitmap_CreateLockFromMipSystem geBitmap Src,
int  mip,
int  LockCnt
 

Definition at line 988 of file bitmap.c.

References geBitmap::Alpha, geBitmap::Data, geBitmap::DataOwner, geBitmap_Info::Format, GE_PIXELFORMAT_8BIT_GRAY, geBitmap_CreateLock_CopyInfo(), geBitmap_CreateRef(), geBitmap_Destroy(), geBitmap_IsValid(), geBitmap_LockForRead(), geBitmap_MakeSystemMips(), geBitmap_Palette_CreateRef(), geErrorLog_AddString, gePixelFormat_BytesPerPel(), gePixelFormat_HasGoodAlpha(), geBitmap::Info, MAXMIPLEVELS, geBitmap_Info::MinimumMip, NULL, and geBitmap_Info::Palette.

Referenced by geBitmap_CreateLockFromMip(), geBitmap_LockForReadNative(), geBitmap_LockForWrite(), and geBitmap_LockForWriteFormat().

00989 {
00990 geBitmap * Ret;
00991 
00992         assert( geBitmap_IsValid(Src) );
00993         if ( mip < Src->Info.MinimumMip || mip >= MAXMIPLEVELS )
00994                 return NULL;
00995 
00996         if ( gePixelFormat_BytesPerPel(Src->Info.Format) < 1 )
00997                 return NULL;
00998 
00999         if ( ! Src->Data[mip] )
01000         {
01001                 if ( ! geBitmap_MakeSystemMips(Src,mip,mip) )
01002                         return NULL;
01003         }
01004 
01005         Ret = geBitmap_CreateLock_CopyInfo(Src,LockCnt,mip);
01006 
01007         if ( ! Ret ) return NULL;
01008 
01009         Ret->Data[0] = Src->Data[mip];
01010 
01011         Ret->Info.Palette = Src->Info.Palette;
01012         if ( Ret->Info.Palette )
01013                 geBitmap_Palette_CreateRef(Ret->Info.Palette);
01014 
01015         Ret->DataOwner = Src;
01016         geBitmap_CreateRef(Src);
01017 
01018         assert( Ret->Alpha == NULL );
01019         if ( ! gePixelFormat_HasGoodAlpha(Src->Info.Format) && Src->Alpha )
01020         {
01021                 if ( ! geBitmap_LockForRead(Src->Alpha,&(Ret->Alpha),mip,mip,GE_PIXELFORMAT_8BIT_GRAY,0,0) )
01022                 {
01023                         geErrorLog_AddString(-1,"CreateLockFromMipSystem : LockForRead failed", NULL);
01024                         geBitmap_Destroy(&Ret);
01025                         return NULL;
01026                 }
01027                 assert( Ret->Alpha );
01028         }
01029 
01030         assert( geBitmap_IsValid(Ret) );
01031 
01032 return Ret;
01033 }

GENESISAPI void GENESISCC geBitmap_CreateRef geBitmap Bmp  ) 
 

Definition at line 159 of file bitmap.c.

References Debug, GENESISAPI, GENESISCC, and geBitmap::RefCount.

Referenced by BitmapList_Add(), ElectricFx_InitBitmap(), Fire_Create(), geBitmap_CreateLock_CopyInfo(), geBitmap_CreateLockFromMipOnDriver(), geBitmap_CreateLockFromMipSystem(), geBitmap_SetAlpha(), geBody_AddMaterial(), geBody_SetMaterial(), gePuppet_FetchTextures(), gePuppet_SetMaterial(), gePuppet_SetShadow(), geSprite_Create(), Particles_InitBitmap(), Plasma_Create(), ProcEng_AddProcedural(), SetFormat_Create(), Smoke_InitBitmap(), and Water_Create().

00160 {
00161         assert(Bmp);
00162         Bmp->RefCount ++;
00163         Debug(_Bitmap_Debug_ActiveRefs ++);
00164 }

geRDriver_THandle* geBitmap_CreateTHandle DRV_Driver Driver,
int  Width,
int  Height,
int  NumMipLevels,
gePixelFormat  SeekFormat1,
gePixelFormat  SeekFormat2,
geBoolean  SeekCK,
geBoolean  SeekAlpha,
geBoolean  SeekSeparates,
uint32  DriverFlags
 

Definition at line 1482 of file bitmap.c.

References EnumPFCB(), DRV_Driver::EnumPixelFormats, geRDriver_PixelFormat::Flags, geBitmap_ChooseDriverFormat(), geErrorLog_AddString, gePixelFormat_Description(), gePixelFormat_IsValid(), DRV_Driver::LastErrorStr, Log_Printf(), MAX_DRIVER_FORMATS, NULL, geRDriver_PixelFormat::PixelFormat, RDRIVER_PF_2D, RDRIVER_PF_3D, RDRIVER_PF_ALPHA, RDRIVER_PF_CAN_DO_COLORKEY, RDRIVER_PF_LIGHTMAP, RDRIVER_PF_PALETTE, DRV_Driver::THandle_Create, and uint32.

Referenced by geBitmap_AttachToDriver(), and geBitmap_Palette_CreateFromDriver().

01484 {
01485 geRDriver_PixelFormat DriverFormats[MAX_DRIVER_FORMATS];
01486 geRDriver_PixelFormat *DriverFormatsPtr;
01487 int DriverFormatsCount;
01488 geRDriver_PixelFormat DriverFormat;
01489 geRDriver_THandle * Ret;
01490 
01491         DriverFormatsPtr = DriverFormats;
01492         Driver->EnumPixelFormats(EnumPFCB,&DriverFormatsPtr);
01493         DriverFormatsCount = ((uint32)DriverFormatsPtr - (uint32)DriverFormats)/sizeof(*DriverFormatsPtr);
01494         assert(DriverFormatsCount < MAX_DRIVER_FORMATS && DriverFormatsCount >= 0);
01495 
01496         if ( DriverFormatsCount == 0 )
01497         {
01498                 geErrorLog_AddString(-1,"Bitmap_CreateTHandle : no formats found!", NULL);
01499                 return NULL;
01500         }
01501 
01502         if ( ! SeekFormat1 )
01503                 SeekFormat1 = SeekFormat2;
01504         else if ( ! SeekFormat2 )
01505                 SeekFormat2 = SeekFormat1;
01506 
01507         assert( gePixelFormat_IsValid(SeekFormat1) );
01508         assert( gePixelFormat_IsValid(SeekFormat2) );
01509 
01510         // now choose DriverFormat
01511         if ( ! geBitmap_ChooseDriverFormat(SeekFormat1,SeekFormat2,SeekCK,SeekAlpha,SeekSeparates,DriverFlags,
01512                                                                                 DriverFormats,DriverFormatsCount,&DriverFormat) )
01513                 return NULL;
01514 
01515         assert( gePixelFormat_IsValid(DriverFormat.PixelFormat) );
01516 
01517 #if 1 //{
01518         Log_Printf("Bitmap : Chose %s for %s",
01519                 gePixelFormat_Description(DriverFormat.PixelFormat),
01520                 gePixelFormat_Description(SeekFormat1));
01521 
01522         if ( SeekFormat1 != SeekFormat2 )
01523                 Log_Printf(" (%s)",gePixelFormat_Description(SeekFormat2));
01524         if ( SeekCK )
01525                 Log_Printf(" (sought CK)");
01526         if ( SeekAlpha )
01527                 Log_Printf(" (sought Alpha)");
01528         if ( DriverFormat.Flags & RDRIVER_PF_2D )
01529                 Log_Printf(" (2D)");
01530         if ( DriverFormat.Flags & RDRIVER_PF_3D )
01531                 Log_Printf(" (3D)");
01532         if ( DriverFormat.Flags & RDRIVER_PF_CAN_DO_COLORKEY )
01533                 Log_Printf(" (can CK)");
01534         if ( DriverFormat.Flags & RDRIVER_PF_PALETTE )
01535                 Log_Printf(" (Palette)");
01536         if ( DriverFormat.Flags & RDRIVER_PF_ALPHA )
01537                 Log_Printf(" (Alpha)");
01538         if ( DriverFormat.Flags & RDRIVER_PF_LIGHTMAP )
01539                 Log_Printf(" (Lightmap)");
01540 
01541         Log_Printf("\n");
01542 #endif //}
01543 
01544         Ret = Driver->THandle_Create(
01545                 Width,Height,
01546                 NumMipLevels,
01547                 &DriverFormat);
01548 
01549         if ( ! Ret )
01550         {
01551                 geErrorLog_AddString(-1, Driver->LastErrorStr, NULL);
01552                 geErrorLog_AddString(-1,"Bitmap_CreateTHandle : Driver->THandle_Create failed", NULL);
01553         }
01554 
01555 return Ret;
01556 }

GENESISAPI geBoolean GENESISCC geBitmap_Destroy geBitmap **  Bmp  ) 
 

Definition at line 232 of file bitmap.c.

References geBitmap::Alpha, geBitmap::Data, geBitmap::DataOwner, Debug, geBitmap::Driver, geBitmap::DriverInfo, GE_FALSE, GE_TRUE, geBitmap_Destroy_Base(), geBitmap_DetachDriver(), geBitmap_Palette_Destroy(), geBitmap_UnLock(), geBoolean, GENESISAPI, GENESISCC, geRam_Free, geBitmap::Info, geBitmap::LockOwner, geBitmap_Info::MaximumMip, geBitmap_Info::MinimumMip, NULL, geBitmap_Info::Palette, and geBitmap::RefCount.

Referenced by BitmapList_Destroy(), BitmapList_Remove(), BumpMap_Create(), Client_DestroyStatusBar(), Console_FreeResources(), Corona_Init(), Corona_Shutdown(), DoSplashScreen(), Electric_SetWorld(), Electric_Shutdown(), ElectricFx_Destroy(), Fire_Destroy(), FreeFxTextures(), GameMgr_FreeWorld(), GameMgr_SetTextureIndex(), geBitmap_CreateFromFile(), geBitmap_CreateLockFromMip(), geBitmap_CreateLockFromMipOnDriver(), geBitmap_CreateLockFromMipSystem(), geBitmap_LockForRead(), geBitmap_LockForReadNative(), geBitmap_LockForWrite(), geBitmap_LockForWriteFormat(), geBitmap_ReadFromTGA(), geBitmap_SetAlpha(), geBitmap_SetFormat(), geBitmap_UnLock_Internal(), geBitmapUtil_CreateFromFileAndAlphaNames(), geBitmapUtil_CreateFromHBITMAP(), geBody_DestroyPossiblyIncompleteBody(), geEngine_InitFonts(), geEngine_ShutdownFonts(), geFont_Destroy(), geFont_DestroyBitmapBuffer(), gePuppet_Destroy(), gePuppet_SetMaterial(), gePuppet_SetShadow(), geSprite_Destroy(), GetABitmap(), geWBitmap_Pool_DestroyAllWBitmaps(), GMenu_DestroyAllData(), Particles_Destroy(), PathPoint_SetTexture(), PathPt_Shutdown(), Plasma_Create(), Plasma_Destroy(), ProcEng_Destroy(), SetFormat_Destroy(), Smoke_Destroy(), Text_Destroy(), and Water_Destroy().

00233 {
00234 int                     i;
00235 geBitmap *      Bitmap;
00236 
00237         assert(Bmp);
00238 
00239         Bitmap = *Bmp;
00240 
00241         if ( Bitmap )
00242         {
00243                 if ( Bitmap->LockOwner )
00244                 {
00245                         return geBitmap_UnLock(Bitmap);
00246                 }
00247 
00248                 if ( Bitmap->RefCount <= 1 )
00249                 {
00250                         if ( Bitmap->DataOwner )
00251                         {
00252                                 geBitmap_Destroy(&(Bitmap->DataOwner));
00253                                 Bitmap->DataOwner = NULL;
00254                         }
00255                         else
00256                         {
00257                                 if ( Bitmap->Driver )
00258                                 {
00259                                         geBitmap_DetachDriver(Bitmap,GE_FALSE);
00260                                 }
00261 
00262                                 for     (i = Bitmap->Info.MinimumMip; i <= Bitmap->Info.MaximumMip; i++)
00263                                 {
00264                                         if      (Bitmap->Data[i])
00265                                                 geRam_Free(Bitmap->Data[i]);
00266                                 }
00267                         }
00268                 }
00269 
00270                 Debug(assert(_Bitmap_Debug_ActiveRefs > 0));
00271                 Debug(_Bitmap_Debug_ActiveRefs --);
00272 
00273                 Bitmap->RefCount --;
00274 
00275                 if ( Bitmap->RefCount <= 0 )
00276                 {
00277                         if      (Bitmap->Alpha)
00278                         {
00279                                 geBitmap_Destroy(&Bitmap->Alpha);
00280                         }
00281 
00282                         if      (Bitmap->Info.Palette)
00283                         {
00284                                 geBitmap_Palette_Destroy(&(Bitmap->Info.Palette));
00285                         }
00286 
00287                         if      (Bitmap->DriverInfo.Palette)
00288                         {
00289                                 geBitmap_Palette_Destroy(&(Bitmap->DriverInfo.Palette));
00290                         }
00291 
00292                         geBitmap_Destroy_Base(Bitmap);
00293 
00294                         *Bmp = NULL;
00295 
00296                         return GE_TRUE;
00297                 }
00298         }
00299 
00300 return GE_FALSE;
00301 }

void geBitmap_Destroy_Base geBitmap Bmp  ) 
 

Definition at line 148 of file bitmap.c.

References BitmapPool, Debug, geBitmap_Stop(), MemPool_FreeHunk(), and geBitmap::RefCount.

Referenced by geBitmap_Destroy().

00149 {
00150         assert(Bmp);
00151         assert(Bmp->RefCount == 0);
00152         Debug(_Bitmap_Debug_ActiveCount --);
00153 
00154         MemPool_FreeHunk(BitmapPool,Bmp);
00155 
00156         geBitmap_Stop();
00157 }

geBoolean BITMAP_GENESIS_INTERNAL geBitmap_DetachDriver geBitmap Bmp,
geBoolean  DoUpdate
 

Definition at line 1755 of file bitmap.c.

References geBitmap::Alpha, BITMAP_GENESIS_INTERNAL, geBitmap_Info::ColorKey, geBitmap::DataOwner, geBitmap::Driver, geBitmap::DriverBitsLocked, geBitmap::DriverDataChanged, geBitmap::DriverHandle, geBitmap::DriverInfo, geBitmap::DriverMipLock, geBitmap_Info::Format, geBitmap_Palette::Format, GE_FALSE, GE_TRUE, geBitmap_IsValid(), geBitmap_Palette_Copy(), geBitmap_Palette_Create(), geBitmap_Palette_Destroy(), geBitmap_Update_DriverToSystem(), geBoolean, geErrorLog_AddString, gePixelFormat, geBitmap_Info::HasColorKey, geBitmap_Info::Height, geBitmap::Info, geBitmap::LockCount, geBitmap::LockOwner, geBitmap_Info::MaximumMip, geBitmap_Info::MinimumMip, NULL, geBitmap_Info::Palette, geBitmap::RefCount, geBitmap_Info::Stride, DRV_Driver::THandle_Destroy, and geBitmap_Info::Width.

Referenced by BitmapList_Destroy(), BitmapList_DetachAll(), BitmapList_Remove(), geBitmap_AttachToDriver(), geBitmap_ClearMips(), geBitmap_Destroy(), geBitmap_SetFormat(), geBitmap_SetMipCount(), geBitmap_SetPreferredFormat(), geBitmap_Update_SystemToDriver(), and geEngine_RemoveBitmap().

01756 {
01757 geBoolean Ret = GE_TRUE;
01758 
01759         assert(geBitmap_IsValid(Bmp) );
01760 
01761         if ( Bmp->LockOwner || Bmp->DataOwner || Bmp->LockCount )
01762         {
01763                 geErrorLog_AddString(-1,"DetachDriver : not an isolated bitmap!", NULL);
01764                 return GE_FALSE;
01765         }
01766 
01767         if ( Bmp->RefCount > 1 )
01768                 DoUpdate = GE_TRUE;
01769 
01770         if ( Bmp->Driver && Bmp->DriverHandle )
01771         {
01772                 if ( DoUpdate )
01773                 {
01774                         if ( ! geBitmap_Update_DriverToSystem(Bmp) )
01775                         {
01776                                 geErrorLog_AddString(-1,"DetachDriver : Update_DriverToSystem", NULL);
01777                                 Ret = GE_FALSE;
01778                         }
01779                         assert(Bmp->DriverDataChanged == GE_FALSE);
01780                 }
01781                         Bmp->Driver->THandle_Destroy(Bmp->DriverHandle);
01782                 Bmp->DriverHandle = NULL;
01783         }
01784 
01785         if ( Bmp->DriverInfo.Palette )
01786         {
01787                 // save it for later in case we re-attach
01788                 if ( ! Bmp->Info.Palette )
01789                 {
01790                 geBitmap_Palette * NewPal;
01791                 gePixelFormat Format;
01792                         Format = Bmp->DriverInfo.Palette->Format;
01793                         NewPal = geBitmap_Palette_Create(Format,256);
01794                         if ( NewPal )
01795                         {
01796                                 if ( geBitmap_Palette_Copy(Bmp->DriverInfo.Palette,NewPal) )
01797                                 {
01798                                         Bmp->Info.Palette = NewPal;
01799                                 }
01800                                 else
01801                                 {
01802                                         geBitmap_Palette_Destroy(&NewPal);
01803                                 }
01804                         }
01805                 }
01806 
01807                 geBitmap_Palette_Destroy(&(Bmp->DriverInfo.Palette));
01808         }
01809 
01810         if ( Bmp->Alpha )
01811         {
01812                 if ( ! geBitmap_DetachDriver(Bmp->Alpha,DoUpdate) )
01813                 {
01814                         geErrorLog_AddString(-1,"DetachDriver : detach alpha", NULL);
01815                         Ret = GE_FALSE;
01816                 }
01817         }
01818 
01819         Bmp->DriverInfo.Width = Bmp->DriverInfo.Height = Bmp->DriverInfo.Stride = 0;
01820         Bmp->DriverInfo.MinimumMip = Bmp->DriverInfo.MaximumMip = 0;
01821         Bmp->DriverInfo.ColorKey = Bmp->DriverInfo.HasColorKey = Bmp->DriverInfo.Format = 0;
01822         Bmp->DriverInfo.Palette = NULL;
01823         Bmp->DriverMipLock = 0;
01824         Bmp->DriverBitsLocked = GE_FALSE;
01825         Bmp->DriverDataChanged = GE_FALSE;
01826         Bmp->DriverHandle = NULL;
01827         Bmp->Driver = NULL;
01828 
01829         //Bmp->DriverFlags left intentionally !
01830 
01831 return Ret;
01832 }

geBoolean geBitmap_FixDriverFlags uint32 pFlags  ) 
 

Definition at line 1718 of file bitmap.c.

References GE_FALSE, GE_TRUE, geBoolean, NumBitsOn(), RDRIVER_PF_3D, RDRIVER_PF_CAN_DO_COLORKEY, RDRIVER_PF_COMBINE_LIGHTMAP, RDRIVER_PF_LIGHTMAP, RDRIVER_PF_MAJOR_MASK, RDRIVER_PF_PALETTE, and uint32.

Referenced by geBitmap_SetDriverFlags().

01719 {
01720 uint32 DriverFlags;
01721         assert(pFlags);
01722         DriverFlags = *pFlags;
01723         
01724         if ( DriverFlags & RDRIVER_PF_COMBINE_LIGHTMAP )
01725                 DriverFlags |= RDRIVER_PF_3D;
01726         if ( DriverFlags & RDRIVER_PF_CAN_DO_COLORKEY )
01727         {
01728                 // <> someone is doing this!
01729                 // bad!
01730                 DriverFlags ^= RDRIVER_PF_CAN_DO_COLORKEY;
01731                 //      return GE_FALSE;
01732         }
01733         if ( (DriverFlags & RDRIVER_PF_COMBINE_LIGHTMAP) &&
01734                 (DriverFlags & (RDRIVER_PF_LIGHTMAP | RDRIVER_PF_PALETTE) ) )
01735                 return GE_FALSE;
01736         if ( NumBitsOn(DriverFlags & RDRIVER_PF_MAJOR_MASK) == 0 )
01737                 return GE_FALSE;
01738         *pFlags = DriverFlags;
01739 return GE_TRUE;
01740 }

GENESISAPI geBitmap* GENESISCC geBitmap_GetAlpha const geBitmap Bmp  ) 
 

Definition at line 3599 of file bitmap.c.

References geBitmap::Alpha, GENESISAPI, GENESISCC, and NULL.

03600 {
03601         if ( ! Bmp ) return NULL;
03602         return Bmp->Alpha;
03603 }

GENESISAPI geBoolean GENESISCC geBitmap_GetAverageColor const geBitmap Bmp,
int *  pR,
int *  pG,
int *  pB
 

Definition at line 5577 of file bitmap.c.

References A, B, geBitmap_Info::ColorKey, geBitmap::Data, gePixelFormat_Operations::DecomposePixel, geBitmap::DriverDataChanged, geBitmap::DriverHandle, geBitmap_Info::Format, G, GE_FALSE, GE_TRUE, geBitmap_Update_DriverToSystem(), geBoolean, geErrorLog_AddString, GENESISAPI, GENESISCC, gePixelFormat, gePixelFormat_BytesPerPel(), gePixelFormat_ColorGetter, gePixelFormat_Decomposer, gePixelFormat_GetOperations(), gePixelFormat_HasPalette(), gePixelFormat_IsRaw(), gePixelFormat_PixelGetter, gePixelFormat_Operations::GetColor, gePixelFormat_Operations::GetPixel, geBitmap_Info::HasColorKey, geBitmap_Info::Height, geBitmap::Info, NULL, R, geBitmap_Info::Stride, uint32, uint8, geBitmap_Info::Width, and y.

05578 {
05579         {
05580         int bpp,x,y,w,h,xtra,dock;
05581         gePixelFormat Format;
05582         uint8 * ptr;
05583         uint32 R,G,B,A,Rt,Gt,Bt,cnt,ck;
05584 
05585                 //{} Rt == Rtotal , probably won't overflow; we can handle a 4096x4095 solid-white image
05586 
05587                 if ( Bmp->DriverHandle && Bmp->DriverDataChanged )
05588                 {
05589                         // must use the driver bits
05590                         if ( ! geBitmap_Update_DriverToSystem((geBitmap *)Bmp) )
05591                         {
05592                                 geErrorLog_AddString(-1,"Bitmap_AverageColor : DriverToSystem failed!",NULL);
05593                                 return GE_FALSE;
05594                         }
05595                 }
05596 
05597                 Format = Bmp->Info.Format;
05598                 bpp = gePixelFormat_BytesPerPel(Format);
05599                 ptr = Bmp->Data[0];     
05600 
05601                 if ( ! ptr || bpp < 1 )
05602                 {
05603                         geErrorLog_AddString(-1,"Bitmap_AverageColor : no data!",NULL);
05604                         return GE_FALSE;
05605                 }
05606 
05607                 w = Bmp->Info.Width;
05608                 h = Bmp->Info.Height;
05609                 xtra = (Bmp->Info.Stride - w)*bpp;
05610                 ck = Bmp->Info.ColorKey;
05611                 dock = Bmp->Info.HasColorKey;
05612 
05613                 Rt = Gt = Bt = cnt = 0;
05614 
05615                 if ( gePixelFormat_HasPalette(Format) )
05616                 {
05617                         // <> Blech!
05618                         geErrorLog_AddString(-1,"Bitmap_AverageColor : doesn't support palettized yet!",NULL);
05619                         #pragma message("Bitmap_AverageColor : doesn't support palettized yet!")
05620                         return GE_FALSE;
05621                 }
05622                 else
05623                 {
05624                 const gePixelFormat_Operations * ops;
05625                 gePixelFormat_ColorGetter GetColor;
05626                 gePixelFormat_PixelGetter GetPixel;
05627                 gePixelFormat_Decomposer Decomposer;
05628 
05629                         assert( gePixelFormat_IsRaw(Format) );
05630 
05631                         ops = gePixelFormat_GetOperations(Format);
05632                         GetColor = ops->GetColor;
05633                         GetPixel = ops->GetPixel;
05634                         Decomposer = ops->DecomposePixel;
05635 
05636                         if ( dock )
05637                         {
05638                                 for(y=h;y--;)
05639                                 {
05640                                         for(x=w;x--;)
05641                                         {
05642                                         uint32 Pixel;
05643                                                 Pixel = GetPixel(&ptr);
05644                                                 if ( Pixel != ck )
05645                                                 {
05646                                                         Decomposer(Pixel,&R,&G,&B,&A);
05647                                                         Rt += R; Gt += G; Bt += B;
05648                                                         cnt ++;
05649                                                 }
05650                                         }
05651                                         ptr += xtra;
05652                                 }
05653                         }
05654                         else
05655                         {
05656                                 for(y=h;y--;)
05657                                 {
05658                                         for(x=w;x--;)
05659                                         {
05660                                                 GetColor(&ptr,&R,&G,&B,&A);
05661                                                 if ( A > 80 )
05662                                                 {
05663                                                         Rt += R; Gt += G; Bt += B;
05664                                                         cnt ++;
05665                                                 }
05666                                         }
05667                                         ptr += xtra;
05668                                 }
05669                         }
05670                 }
05671 
05672                 if ( pR ) *pR = (Rt + (cnt>>1)) / cnt;
05673                 if ( pG ) *pG = (Gt + (cnt>>1)) / cnt;
05674                 if ( pB ) *pB = (Bt + (cnt>>1)) / cnt;
05675         }
05676 
05677 return GE_TRUE;
05678 }

GENESISAPI void* GENESISCC geBitmap_GetBits geBitmap Bmp  ) 
 

Definition at line 812 of file bitmap.c.

References geBitmap::Data, geBitmap::Driver, geBitmap::DriverBitsLocked, geBitmap::DriverHandle, geBitmap::DriverMipLock, GE_TRUE, geBitmap_IsValid(), geErrorLog_AddString, GENESISAPI, GENESISCC, geBitmap::LockOwner, NULL, and DRV_Driver::THandle_Lock.

Referenced by BlitData_FromSeparateAlpha(), BlitData_ToSeparateAlpha(), BumpMap_CreateFromHeightMap(), createPaletteFromBitmap(), ElectricFx_Shade(), FireAnimator_CreateFire(), geBitmap_BlitMipRect(), geBitmap_Gamma_Apply(), geBitmap_SetFormat(), geBitmap_Update_DriverToSystem(), geBitmap_Update_SystemToDriver(), geBitmap_UpdateMips(), geBitmapUtil_CompareBitmaps(), geBitmapUtil_CreateFromHBITMAP(), geBitmapUtil_CreateHBITMAP(), geBitmapUtil_SetColor(), geFont_DrawUsingDIB(), geWBitmap_Pool_CreateAllWBitmaps(), Particles_Draw(), PlaceLetter(), PlasmaAnimator_CreatePlasma(), Smoke_Shade(), Water_ApplyToBitmap(), and Water_Create().

00813 {
00814 void * bits;
00815 
00816         assert( geBitmap_IsValid(Bmp) );
00817 
00818         if ( ! Bmp )
00819         {
00820                 geErrorLog_AddString(-1,"GetBits : bad bmp", NULL);
00821                 return NULL;
00822         }
00823 
00824         if ( ! Bmp->LockOwner ) // must be a lock!
00825         {
00826                 geErrorLog_AddString(-1,"GetBits : not a lock", NULL);
00827                 return NULL;
00828         }
00829 
00830         if ( Bmp->DriverHandle )
00831         {
00832                 assert(Bmp->Driver);
00833                 if ( ! Bmp->Driver->THandle_Lock(Bmp->DriverHandle,Bmp->DriverMipLock,&bits) )
00834                 {
00835                         geErrorLog_AddString(-1,"GetBits : THandle_Lock", NULL);
00836                         return NULL;
00837                 }
00838 
00839                 Bmp->DriverBitsLocked = GE_TRUE;
00840         }
00841         else
00842         {
00843                 bits = Bmp->Data[0];
00844         }
00845 
00846 return bits;
00847 }

GENESISAPI geBoolean GENESISCC geBitmap_GetInfo const geBitmap Bmp,
geBitmap_Info Info,
geBitmap_Info SecondaryInfo
 

Definition at line 2826 of file bitmap.c.

References geBitmap::DriverHandle, geBitmap::DriverInfo, GE_TRUE, geBitmap_IsValid(), geBoolean, GENESISAPI, GENESISCC, and geBitmap::Info.

Referenced by BlitData_FromSeparateAlpha(), BlitData_ToSeparateAlpha(), BumpMap_CreateFromHeightMap(), createPaletteFromBitmap(), ElectricFx_InitBitmap(), ElectricFx_InitPalette(), ElectricFx_Shade(), FireAnimator_CreateFire(), geBitmap_Gamma_Apply(), geBitmap_UpdateMips(), geBitmapUtil_CompareBitmaps(), geBitmapUtil_CreateHBITMAP(), geBitmapUtil_SetAlphaFromBrightness(), geBitmapUtil_SetColor(), geEngine_DrawAlphaBitmap(), geFont_DrawUsingDIB(), geWBitmap_Pool_CreateAllWBitmaps(), geWorld_BitmapListInit(), Particles_Create(), Particles_Draw(), Particles_InitPalette(), PlaceLetter(), PlasmaAnimator_CreatePlasma(), ProcUtil_SetPaletteFromString(), SetFormat_Create(), Smoke_InitBitmap(), Smoke_InitPalette(), Smoke_Shade(), Water_ApplyToBitmap(), and Water_Create().

02827 {
02828         assert( geBitmap_IsValid(Bmp) );
02829 
02830         assert(Info);
02831 
02832         if ( Bmp->DriverHandle )
02833         {
02834                 *Info = Bmp->DriverInfo;
02835         }
02836         else
02837         {
02838                 *Info = Bmp->Info;
02839         }
02840 
02841         if ( SecondaryInfo )
02842                 *SecondaryInfo = Bmp->Info;
02843 
02844         return GE_TRUE;
02845 }

GENESISAPI geBitmap_Palette* GENESISCC geBitmap_GetPalette const geBitmap Bmp  ) 
 

Definition at line 3585 of file bitmap.c.

References geBitmap::Driver, geBitmap::DriverInfo, GENESISAPI, GENESISCC, geBitmap::Info, NULL, and geBitmap_Info::Palette.

Referenced by BumpMap_ComputePalette(), ElectricFx_InitPalette(), geBitmap_BlitData_Sub(), geBitmap_Palette_CreateFromBitmap(), geBitmap_SetFormat(), geBitmap_SetFormatMin(), geBitmapUtil_SetAlphaFromBrightness(), geFont_DrawText(), geFont_DrawTextToBitmap(), Particles_InitPalette(), PlasmaAnimator_CreatePalette(), ProcUtil_SetPaletteFromString(), and Smoke_InitPalette().

03586 {
03587         if ( ! Bmp ) return NULL;
03588 
03589         if ( Bmp->Driver && Bmp->DriverInfo.Palette )
03590         {
03591                 assert(Bmp->Info.Palette);
03592                 return Bmp->DriverInfo.Palette;
03593         }
03594 
03595         return Bmp->Info.Palette;
03596 }

GENESISAPI gePixelFormat GENESISCC geBitmap_GetPreferredFormat const geBitmap Bmp  ) 
 

Definition at line 3674 of file bitmap.c.

References GENESISAPI, GENESISCC, gePixelFormat, and geBitmap::PreferredFormat.

03675 {
03676         if ( ! Bmp ) return 0;
03677 return Bmp->PreferredFormat;
03678 }

geRDriver_THandle* BITMAP_GENESIS_INTERNAL geBitmap_GetTHandle const geBitmap Bmp  ) 
 

Definition at line 1923 of file bitmap.c.

References BITMAP_GENESIS_INTERNAL, and geBitmap::DriverHandle.

Referenced by BitmapList_CountMembersAttached(), geEngine_DrawBitmap(), geEngine_RenderPoly(), geEngine_RenderPolyArray(), geTClip_SetTexture(), RenderFace(), RenderSkyThroughFrustum(), RenderTexturedPoint(), RenderTexturedPoly(), and RenderTransPoly().

01924 {
01925 //      assert( geBitmap_IsValid(Bmp) );
01926 
01927         return Bmp->DriverHandle;
01928 }

GENESISAPI geBoolean GENESISCC geBitmap_HasAlpha const geBitmap Bmp  ) 
 

Definition at line 1558 of file bitmap.c.

References geBitmap::Alpha, geBitmap_Info::Format, geBitmap_Palette::Format, GE_FALSE, GE_TRUE, geBitmap_IsValid(), geBoolean, GENESISAPI, GENESISCC, gePixelFormat_HasGoodAlpha(), gePixelFormat_HasPalette(), geBitmap::Info, and geBitmap_Info::Palette.

Referenced by geBitmap_AttachToDriver().

01559 {
01560         assert( geBitmap_IsValid(Bmp) );
01561         
01562         if ( Bmp->Alpha )
01563                 return GE_TRUE;
01564 
01565         if ( gePixelFormat_HasGoodAlpha(Bmp->Info.Format) )
01566                 return GE_TRUE;
01567 
01568         if ( gePixelFormat_HasPalette(Bmp->Info.Format) && Bmp->Info.Palette )
01569         {
01570                 if ( gePixelFormat_HasGoodAlpha(Bmp->Info.Palette->Format) )
01571                         return GE_TRUE;
01572         }       
01573 
01574 return GE_FALSE;
01575 }

GENESISAPI int GENESISCC geBitmap_Height const geBitmap Bmp  ) 
 

Definition at line 2896 of file bitmap.c.

References GENESISAPI, GENESISCC, geBitmap_Info::Height, and geBitmap::Info.

Referenced by BumpMap_Create(), geEngine_InitFonts(), geFont_AddCharacters(), geFont_DrawText(), geFont_DrawUsingDIB(), Particles_Create(), PlaceLetter(), Plasma_Create(), and RenderTexturedPoint().

02897 {
02898         assert(Bmp);
02899 return(Bmp->Info.Height);
02900 }

geBoolean geBitmap_Info_IsValid const geBitmap_Info Info  ) 
 

Definition at line 5525 of file bitmap.c.

References geBitmap_Info::Format, GE_FALSE, GE_PIXELFORMAT_COUNT, GE_PIXELFORMAT_NO_DATA, GE_TRUE, geBitmap_Palette_IsValid(), geBoolean, geBitmap_Info::Height, geBitmap_Info::MaximumMip, MAXMIPLEVELS, geBitmap_Info::MinimumMip, geBitmap_Info::Palette, geBitmap_Info::Stride, and geBitmap_Info::Width.

Referenced by geBitmap_CreateFromInfo(), and geBitmap_IsValid().

05526 {
05527         if ( ! Info ) return GE_FALSE;
05528 
05529         assert( Info->Width > 0 && Info->Height > 0 && Info->Stride >= Info->Width );
05530 
05531         assert( Info->MinimumMip >= 0 && Info->MaximumMip < MAXMIPLEVELS && Info->MinimumMip <= Info->MaximumMip );
05532 
05533         assert( Info->Format > GE_PIXELFORMAT_NO_DATA && Info->Format < GE_PIXELFORMAT_COUNT );
05534 
05535 //      ok to have palette on non-palettized
05536 //      if ( ! gePixelFormat_HasPalette(Info->Format) && Info->Palette )
05537 //              return GE_FALSE;
05538 
05539         if ( Info->Palette )
05540                 if ( ! geBitmap_Palette_IsValid(Info->Palette) )
05541                         return GE_FALSE;
05542 
05543 return GE_TRUE;
05544 }

geBoolean geBitmap_IsTGA geVFile F  )  [static]
 

Definition at line 4227 of file bitmap.c.

References TGAHEADER::ColorMapType, GE_FALSE, GE_TRUE, GE_VFILE_SEEKEND, GE_VFILE_SEEKSET, geBoolean, geVFile_Read(), geVFile_Seek(), TGAHEADER::ImageType, and TGAHEADER::PixelDepth.

Referenced by geBitmap_CreateFromFile().

04228 {
04229         char targa[18];
04230         TGAHEADER tgah;
04231         
04232         if (!geVFile_Seek(F, - 18, GE_VFILE_SEEKEND))
04233                 return GE_FALSE;
04234         
04235         if(!geVFile_Read(F, &targa, 18))
04236                 return GE_FALSE;
04237         geVFile_Seek(F, 0, GE_VFILE_SEEKSET);
04238 
04239         //if we find the TRUEVISION-XFILE. signature this should be a tga file
04240         if(!strcmp(targa, "TRUEVISION-XFILE."))
04241                 return GE_TRUE;
04242         
04243         // older versions don't have a signature so do further checks
04244         if(!geVFile_Read(F, &tgah, 18))
04245                 return GE_FALSE;
04246         geVFile_Seek(F, 0, GE_VFILE_SEEKSET);
04247 
04248         if(tgah.ColorMapType != 0 && tgah.ColorMapType != 1)
04249                 return GE_FALSE;
04250         else if(tgah.ImageType != 1 && tgah.ImageType != 2 && tgah.ImageType != 9 && tgah.ImageType != 10)
04251                 return GE_FALSE;
04252         else if(tgah.PixelDepth != 8 && tgah.PixelDepth != 16 && tgah.PixelDepth != 24 && tgah.PixelDepth != 32)
04253                 return GE_FALSE;
04254         else 
04255                 return GE_TRUE;
04256 
04257                                 
04258         return GE_FALSE;
04259 }

geBoolean geBitmap_IsValid const geBitmap Bmp  ) 
 

Definition at line 5482 of file bitmap.c.

References geBitmap::Alpha, geBitmap::DataOwner, geBitmap::Driver, geBitmap::DriverBitsLocked, geBitmap::DriverDataChanged, geBitmap::DriverHandle, geBitmap::DriverInfo, GE_FALSE, GE_TRUE, geBitmap_Info_IsValid(), geBoolean, geBitmap::Info, geBitmap::LockCount, geBitmap::LockOwner, and geBitmap::RefCount.

Referenced by geBitmap_AttachToDriver(), geBitmap_Blit(), geBitmap_BlitBestMip(), geBitmap_BlitBitmap(), geBitmap_BlitMip(), geBitmap_ClearMips(), geBitmap_CreateLock_CopyInfo(), geBitmap_CreateLockFromMip(), geBitmap_CreateLockFromMipOnDriver(), geBitmap_CreateLockFromMipSystem(), geBitmap_DetachDriver(), geBitmap_GetBits(), geBitmap_GetInfo(), geBitmap_HasAlpha(), geBitmap_LockForRead(), geBitmap_LockForReadNative(), geBitmap_LockForWrite(), geBitmap_LockForWriteFormat(), geBitmap_MakeSystemMips(), geBitmap_RefreshMips(), geBitmap_SetAlpha(), geBitmap_SetColorKey(), geBitmap_SetDriverFlags(), geBitmap_SetFormat(), geBitmap_SetFormatMin(), geBitmap_SetGammaCorrection(), geBitmap_SetGammaCorrection_DontChange(), geBitmap_SetMipCount(), geBitmap_SetPalette(), geBitmap_Update_DriverToSystem(), geBitmap_Update_SystemToDriver(), geBitmap_UpdateMips(), geBitmap_UpdateMips_System(), geBitmap_WriteToFile(), and geSprite_Create().

05483 {
05484         if ( ! Bmp ) return GE_FALSE;
05485 
05486         assert( Bmp->RefCount >= 1 );
05487 
05488         assert( ! (Bmp->LockCount && Bmp->LockOwner) );
05489 
05490         assert( !( (Bmp->DriverDataChanged || Bmp->DriverBitsLocked) &&
05491                         ! Bmp->DriverHandle ) );
05492         assert( ! (Bmp->DriverHandle && ! Bmp->Driver) );
05493 
05494         if ( ! geBitmap_Info_IsValid(&(Bmp->Info)) )
05495                 return GE_FALSE;
05496 
05497         if ( Bmp->DriverHandle && ! geBitmap_Info_IsValid(&(Bmp->DriverInfo)) )
05498                 return GE_FALSE;
05499 
05500         if ( Bmp->LockOwner && Bmp->Alpha )
05501                 assert( Bmp->Alpha->LockOwner );
05502 
05503         if ( Bmp->LockOwner )
05504         {
05505                 assert(Bmp->LockOwner != Bmp);
05506                 assert( Bmp->LockOwner->LockCount );
05507         }
05508 
05509         if ( Bmp->DataOwner )
05510         {
05511                 assert(Bmp->DataOwner != Bmp);
05512                 assert( Bmp->DataOwner->RefCount >= 2 );
05513         }
05514 
05515         if ( Bmp->Alpha )
05516         {
05517                 assert(Bmp->Alpha != Bmp);
05518                 if ( ! geBitmap_IsValid(Bmp->Alpha) )
05519                         return GE_FALSE;
05520         }
05521 
05522 return GE_TRUE;
05523 }

GENESISAPI geBoolean GENESISCC geBitmap_LockForRead const geBitmap iBmp,
geBitmap **  Target,
int  MinimumMip,
int  MaximumMip,
gePixelFormat  Format,
geBoolean  HasColorKey,
uint32  ColorKey
 

Definition at line 616 of file bitmap.c.

References GE_FALSE, GE_TRUE, geBitmap_CreateLockFromMip(), geBitmap_Destroy(), geBitmap_IsValid(), geBoolean, geErrorLog_AddString, GENESISAPI, GENESISCC, geBitmap::Info, geBitmap::LockCount, geBitmap::LockOwner, MAXMIPLEVELS, geBitmap_Info::MinimumMip, and NULL.

Referenced by BumpMap_CreateFromHeightMap(), createPaletteFromBitmap(), geBitmap_CreateLockFromMip(), geBitmap_CreateLockFromMipSystem(), geBitmapUtil_CompareBitmaps(), geBitmapUtil_CreateHBITMAP(), and Water_Create().

00624 {
00625 int mip;
00626 geBitmap * Bmp = (geBitmap *)iBmp;
00627 
00628         assert( geBitmap_IsValid(Bmp) );
00629         assert( Target);
00630         assert(MaximumMip >= MinimumMip);
00631         assert( &Bmp != Target );
00632 
00633         if ( MinimumMip < Bmp->Info.MinimumMip ||
00634 //               MaximumMip > Bmp->Info.MaximumMip
00635                 MaximumMip >= MAXMIPLEVELS )
00636         {
00637                 geErrorLog_AddString(-1,"LockForRead : invalid mip", NULL);
00638                 return GE_FALSE;
00639         }
00640 
00641         if ( Bmp->LockCount < 0 || Bmp->LockOwner )
00642         {
00643                 geErrorLog_AddString(-1,"LockForRead : already locked", NULL);
00644                 return GE_FALSE;
00645         }
00646         
00647         for(mip=MinimumMip;mip <= MaximumMip;mip ++)
00648         {
00649                 Target[ mip - MinimumMip ] = geBitmap_CreateLockFromMip(Bmp,mip, Format,HasColorKey,ColorKey,1);
00650                 if ( ! Target[ mip - MinimumMip ] )
00651                 {
00652                         geErrorLog_AddString(-1,"LockForRead : CreateLockFromMip failed", NULL);
00653                         mip--;
00654                         while(mip >= MinimumMip )
00655                         {
00656                                 geBitmap_Destroy( & Target[ mip - MinimumMip ] );
00657                                 mip--;
00658                         }
00659                         return GE_FALSE;
00660                 }
00661         }
00662 
00663 return GE_TRUE;
00664 }

GENESISAPI geBoolean GENESISCC geBitmap_LockForReadNative const geBitmap iBmp,
geBitmap **  Target,
int  MinimumMip,
int  MaximumMip
 

Definition at line 561 of file bitmap.c.

References geBitmap::DriverDataChanged, geBitmap::DriverHandle, geBitmap::DriverInfo, GE_FALSE, GE_TRUE, geBitmap_CreateLockFromMipOnDriver(), geBitmap_CreateLockFromMipSystem(), geBitmap_Destroy(), geBitmap_IsValid(), geBoolean, geErrorLog_AddString, GENESISAPI, GENESISCC, geBitmap::Info, geBitmap::LockCount, geBitmap::LockOwner, geBitmap_Info::MaximumMip, MAXMIPLEVELS, geBitmap_Info::MinimumMip, and NULL.

Referenced by geBitmap_BlitMipRect(), geBitmap_SetFormat(), geBitmap_Update_DriverToSystem(), geBitmap_Update_SystemToDriver(), and PlasmaAnimator_CreatePlasma().

00566 {
00567 int mip;
00568 geBitmap * Bmp = (geBitmap *)iBmp;
00569 
00570         assert( geBitmap_IsValid(Bmp) );
00571         assert( Target);
00572         assert(MaximumMip >= MinimumMip);
00573         assert( &Bmp != Target );
00574 
00575         if ( (MinimumMip < Bmp->Info.MinimumMip && MinimumMip < Bmp->DriverInfo.MinimumMip) ||
00576                  (MaximumMip >= MAXMIPLEVELS) )
00577         {
00578                 geErrorLog_AddString(-1,"LockForRead : invalid mip", NULL);
00579                 return GE_FALSE;
00580         }
00581 
00582         if ( Bmp->LockCount < 0 || Bmp->LockOwner )
00583         {
00584                 geErrorLog_AddString(-1,"LockForRead : already locked", NULL);
00585                 return GE_FALSE;
00586         }
00587 
00588         for(mip=MinimumMip;mip <= MaximumMip;mip ++)
00589         {
00590                 // err on the side of *not* choosing the driver data to read from !
00591                 if ( Bmp->DriverHandle && Bmp->DriverDataChanged
00592                         && mip <= Bmp->DriverInfo.MaximumMip && mip >= Bmp->DriverInfo.MinimumMip)
00593                 {
00594                         Target[ mip - MinimumMip ] = geBitmap_CreateLockFromMipOnDriver(Bmp,mip,1);
00595                 }
00596                 else
00597                 {
00598                         Target[ mip - MinimumMip ] = geBitmap_CreateLockFromMipSystem(Bmp,mip,1);
00599                 }
00600                 if ( ! Target[ mip - MinimumMip ] )
00601                 {
00602                         geErrorLog_AddString(-1,"LockForRead : CreateLockFromMip failed", NULL);
00603                         mip--;
00604                         while(mip >= MinimumMip )
00605                         {
00606                                 geBitmap_Destroy( & Target[ mip - MinimumMip ] );
00607                                 mip--;
00608                         }
00609                         return GE_FALSE;
00610                 }
00611         }
00612 
00613 return GE_TRUE;
00614 }

GENESISAPI geBoolean GENESISCC geBitmap_LockForWrite geBitmap Bmp,
geBitmap **  Target,
int  MinimumMip,
int  MaximumMip
 

Definition at line 399 of file bitmap.c.

References geBitmap::DriverHandle, geBitmap::DriverInfo, GE_FALSE, GE_TRUE, geBitmap_CreateLockFromMipOnDriver(), geBitmap_CreateLockFromMipSystem(), geBitmap_Destroy(), geBitmap_IsValid(), geBitmap_MakeSystemMips(), geBoolean, geErrorLog_AddString, GENESISAPI, GENESISCC, geBitmap::Info, geBitmap::LockCount, geBitmap::LockOwner, geBitmap_Info::MaximumMip, MAXMIPLEVELS, geBitmap_Info::MinimumMip, and NULL.

Referenced by geBitmap_BlitMipRect(), geBitmap_Gamma_Apply(), geBitmap_SetFormat(), geBitmap_UpdateMips(), geBitmapUtil_CreateFromHBITMAP(), geBitmapUtil_SetColor(), geFont_DrawUsingDIB(), geWBitmap_Pool_CreateAllWBitmaps(), PlaceLetter(), and Water_ApplyToBitmap().

00404 {
00405 int mip;
00406 
00407         assert( geBitmap_IsValid(Bmp) );
00408         assert( Target);
00409         assert(MaximumMip >= MinimumMip);
00410         assert( &Bmp != Target );
00411 
00412         if ( Bmp->LockCount || Bmp->LockOwner )
00413         {
00414                 geErrorLog_AddString(-1,"LockForWrite : already locked", NULL);
00415                 return GE_FALSE;
00416         }
00417 
00418         if ( Bmp->DriverHandle )
00419         {
00420                 if ( (MinimumMip < Bmp->DriverInfo.MinimumMip) ||
00421                          (MaximumMip > Bmp->DriverInfo.MaximumMip) )
00422                 {
00423                         geErrorLog_AddString(-1,"LockForWrite : Driver : invalid mip", NULL);
00424                         return GE_FALSE;
00425                 }
00426         }
00427         else
00428         {
00429                 if ( (MinimumMip < Bmp->Info.MinimumMip) ||
00430                          (MaximumMip >= MAXMIPLEVELS) )
00431                 {
00432                         geErrorLog_AddString(-1,"LockForWrite : System : invalid mip", NULL);
00433                         return GE_FALSE;
00434                 }
00435 
00436                 if ( MaximumMip > Bmp->Info.MaximumMip )
00437                 {
00438                         if ( ! geBitmap_MakeSystemMips(Bmp,Bmp->Info.MaximumMip,MaximumMip) )
00439                                 return GE_FALSE;
00440                         Bmp->Info.MaximumMip = MaximumMip;
00441                 }
00442         }
00443         
00444         for(mip=MinimumMip;mip <= MaximumMip;mip ++)
00445         {
00446                 if ( Bmp->DriverHandle )
00447                 {
00448                         Target[ mip - MinimumMip ] = geBitmap_CreateLockFromMipOnDriver(Bmp,mip,-1);
00449                 }
00450                 else
00451                 {
00452                         Target[ mip - MinimumMip ] = geBitmap_CreateLockFromMipSystem(Bmp,mip,-1);
00453                 }
00454                 if ( ! Target[ mip - MinimumMip ] )
00455                 {
00456                         geErrorLog_AddString(-1,"LockForWrite : CreateLockFromMip failed", NULL);
00457                         mip--;
00458                         while(mip >= MinimumMip )
00459                         {
00460                                 geBitmap_Destroy( & Target[ mip - MinimumMip ] );
00461                                 mip--;
00462                         }
00463                         return GE_FALSE;
00464                 }
00465         }
00466 
00467         assert( Bmp->LockCount == - (MaximumMip - MinimumMip + 1) );
00468 
00469 return GE_TRUE;
00470 }

GENESISAPI geBoolean GENESISCC geBitmap_LockForWriteFormat geBitmap Bmp,
geBitmap **  Target,
int  MinimumMip,
int  MaximumMip,
gePixelFormat  Format
 

Definition at line 472 of file bitmap.c.

References geBitmap::DriverHandle, geBitmap::DriverInfo, geBitmap_Info::Format, GE_FALSE, GE_TRUE, geBitmap_CreateLockFromMipOnDriver(), geBitmap_CreateLockFromMipSystem(), geBitmap_Destroy(), geBitmap_IsValid(), geBitmap_MakeSystemMips(), geBitmap_Update_DriverToSystem(), geBoolean, geErrorLog_AddString, GENESISAPI, GENESISCC, geBitmap::Info, geBitmap::LockCount, geBitmap::LockOwner, geBitmap_Info::MaximumMip, MAXMIPLEVELS, geBitmap_Info::MinimumMip, and NULL.

Referenced by BumpMap_CreateFromHeightMap(), ElectricFx_Shade(), FireAnimator_CreateFire(), geFont_DrawUsingDIB(), Particles_Draw(), PlasmaAnimator_CreatePlasma(), Smoke_Shade(), and Water_ApplyToBitmap().

00478 {
00479 int mip;
00480 
00481         assert( geBitmap_IsValid(Bmp) );
00482         assert( Target);
00483         assert(MaximumMip >= MinimumMip);
00484         assert( &Bmp != Target );
00485         
00486         if ( Bmp->LockCount || Bmp->LockOwner )
00487         {
00488                 geErrorLog_AddString(-1,"LockForWrite : already locked", NULL);
00489                 return GE_FALSE;
00490         }
00491 
00492         if ( Format != Bmp->Info.Format && Format != Bmp->DriverInfo.Format )
00493         {
00494                 geErrorLog_AddString(-1,"LockForWriteFormat : must be System or Driver Format !", NULL);
00495                 return GE_FALSE;
00496         }
00497 
00498         if ( Format == Bmp->DriverInfo.Format )
00499         {
00500                 if ( MinimumMip < Bmp->DriverInfo.MinimumMip || MaximumMip > Bmp->DriverInfo.MaximumMip )
00501                 {
00502                         geErrorLog_AddString(-1,"LockForWrite : invalid Driver mip", NULL);
00503                         return GE_FALSE;
00504                 }
00505         }
00506         else
00507         {
00508                 assert( Format == Bmp->Info.Format );
00509 
00510                 if ( Bmp->DriverHandle )
00511                 {
00512                         if ( ! geBitmap_Update_DriverToSystem(Bmp) )
00513                         {
00514                                 geErrorLog_AddString(-1,"LockForWrite : Update_DriverToSystem", NULL);
00515                                 return GE_FALSE;
00516                         }
00517                 }
00518 
00519                 // create mips?
00520 
00521                 if ( MinimumMip < Bmp->Info.MinimumMip || MaximumMip >= MAXMIPLEVELS )
00522                 {
00523                         geErrorLog_AddString(-1,"LockForWrite : invalid System mip", NULL);
00524                         return GE_FALSE;
00525                 }
00526                 
00527                 if ( ! geBitmap_MakeSystemMips(Bmp,Bmp->Info.MaximumMip,MaximumMip) )
00528                         return GE_FALSE;
00529                 Bmp->Info.MaximumMip = MaximumMip;
00530         }
00531 
00532         for(mip=MinimumMip;mip <= MaximumMip;mip ++)
00533         {
00534                 if ( Bmp->DriverHandle && Format == Bmp->DriverInfo.Format )
00535                 {
00536                         Target[ mip - MinimumMip ] = geBitmap_CreateLockFromMipOnDriver(Bmp,mip,-1);
00537                 }
00538                 else
00539                 {
00540                         Target[ mip - MinimumMip ] = geBitmap_CreateLockFromMipSystem(Bmp,mip,-1);
00541                 }
00542 
00543                 if ( ! Target[ mip - MinimumMip ] )
00544                 {
00545                         geErrorLog_AddString(-1,"LockForWrite : CreateLockFromMip failed", NULL);
00546                         mip--;
00547                         while(mip >= MinimumMip )
00548                         {
00549                                 geBitmap_Destroy( & Target[ mip - MinimumMip ] );
00550                                 mip--;
00551                         }
00552                         return GE_FALSE;
00553                 }
00554         }
00555 
00556         assert( Bmp->LockCount == - (MaximumMip - MinimumMip + 1) );
00557 
00558 return GE_TRUE;
00559 }

geBoolean geBitmap_MakeDriverLockInfo geBitmap Bmp,
int  mip,
geBitmap_Info Into
 

Definition at line 2847 of file bitmap.c.

References geRDriver_THandleInfo::ColorKey, geBitmap_Info::ColorKey, geBitmap_Palette::ColorKeyIndex, geBitmap::Driver, geBitmap::DriverFlags, geBitmap::DriverHandle, geBitmap::DriverInfo, geBitmap::DriverMipLock, geRDriver_THandleInfo::Flags, geRDriver_PixelFormat::Flags, geBitmap_Info::Format, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_AddString, gePixelFormat_HasPalette(), geBitmap_Palette::HasColorKey, geBitmap_Info::HasColorKey, geRDriver_THandleInfo::Height, geBitmap_Info::Height, geBitmap_Info::MaximumMip, geBitmap_Info::MinimumMip, NULL, geBitmap_Info::Palette, geRDriver_PixelFormat::PixelFormat, geRDriver_THandleInfo::PixelFormat, RDRIVER_THANDLE_HAS_COLORKEY, geRDriver_THandleInfo::Stride, geBitmap_Info::Stride, DRV_Driver::THandle_GetInfo, geRDriver_THandleInfo::Width, and geBitmap_Info::Width.

Referenced by geBitmap_AttachToDriver(), geBitmap_CreateLockFromMipOnDriver(), and geBitmap_Update_SystemToDriver().

02848 {
02849 geRDriver_THandleInfo TInfo;
02850 
02851         // MakeDriverLockInfo also doesn't full out the full info, so it must be a valid info first!
02852         // Bmp also gets some stuff written into him.
02853 
02854         assert(Bmp && Into); // not necessarily valid
02855 
02856         if ( ! Bmp->DriverHandle || ! Bmp->Driver || mip < Bmp->DriverInfo.MinimumMip || mip > Bmp->DriverInfo.MaximumMip )
02857                 return GE_FALSE;
02858 
02859         if ( ! Bmp->Driver->THandle_GetInfo(Bmp->DriverHandle,mip,&TInfo) )
02860         {
02861                 geErrorLog_AddString(-1,"MakeDriverLockInfo : THandle_GetInfo", NULL);
02862                 return GE_FALSE;
02863         }
02864 
02865         Bmp->DriverMipLock      = mip;
02866         Bmp->DriverFlags        = TInfo.PixelFormat.Flags;
02867 
02868         Into->Width                     = TInfo.Width;
02869         Into->Height            = TInfo.Height;
02870         Into->Stride            = TInfo.Stride;
02871         Into->Format            = TInfo.PixelFormat.PixelFormat;
02872         Into->ColorKey          = TInfo.ColorKey;
02873 
02874         if ( TInfo.Flags & RDRIVER_THANDLE_HAS_COLORKEY )
02875                 Into->HasColorKey = GE_TRUE;
02876         else
02877                 Into->HasColorKey = GE_FALSE;
02878 
02879         Into->MinimumMip = Into->MaximumMip = mip;
02880 
02881         if ( gePixelFormat_HasPalette(Into->Format) && Into->Palette && Into->Palette->HasColorKey )
02882         {
02883                 Into->HasColorKey = GE_TRUE;
02884                 Into->ColorKey = Into->Palette->ColorKeyIndex;
02885         }
02886 
02887 return GE_TRUE;
02888 }

void geBitmap_MakeMipInfo geBitmap_Info Src,
int  mip,
geBitmap_Info Target
 

Definition at line 883 of file bitmap.c.

References geBitmap_Info::Height, geBitmap_Info::MaximumMip, MAXMIPLEVELS, geBitmap_Info::MinimumMip, SHIFT_R_ROUNDUP, geBitmap_Info::Stride, and geBitmap_Info::Width.

Referenced by geBitmap_CreateLock_CopyInfo(), and geBitmap_Update_DriverToSystem().

00884 {
00885         assert( Src && Target );
00886         assert( mip >= 0 && mip < MAXMIPLEVELS );
00887         *Target = *Src;
00888 
00889         Target->Width  = SHIFT_R_ROUNDUP(Target->Width,mip);
00890         Target->Height = SHIFT_R_ROUNDUP(Target->Height,mip);
00891         Target->Stride = SHIFT_R_ROUNDUP(Target->Stride,mip);
00892         Target->MinimumMip = Target->MaximumMip = mip;
00893 }

geBoolean geBitmap_MakeSystemMips geBitmap Bmp,
int  low,
int  high
 

Definition at line 2770 of file bitmap.c.

References geBitmap::Data, geBitmap::DataOwner, geBitmap_Info::Format, GE_FALSE, GE_TRUE, geBitmap_AllocSystemMip(), geBitmap_IsValid(), geBitmap_UpdateMips_System(), geBoolean, gePixelFormat_BytesPerPel(), geBitmap::Info, geBitmap::LockOwner, max, geBitmap_Info::MaximumMip, MAXMIPLEVELS, min, and geBitmap_Info::MinimumMip.

Referenced by geBitmap_CreateLockFromMip(), geBitmap_CreateLockFromMipSystem(), geBitmap_LockForWrite(), and geBitmap_LockForWriteFormat().

02771 {
02772 int mip;
02773 
02774         assert( geBitmap_IsValid(Bmp) );
02775 
02776         // this is that CreateLockFromMip uses to make its new data
02777 
02778         if ( Bmp->LockOwner )
02779                 Bmp = Bmp->LockOwner;
02780 //      if ( Bmp->LockCount > 0 )
02781 //              return GE_FALSE;
02782         if ( Bmp->DataOwner )
02783                 return GE_FALSE;
02784 
02785         // {} for compressed data, just don't make mips and say we did!
02786         if ( gePixelFormat_BytesPerPel(Bmp->Info.Format) < 1 )
02787                 return GE_TRUE;
02788 
02789         if ( low < 0 || high >= MAXMIPLEVELS || low > high )
02790                 return GE_FALSE;
02791 
02792         for( mip = low; mip <= high; mip++)
02793         {
02794                 if ( ! Bmp->Data[mip] )
02795                 {
02796                         if ( ! geBitmap_AllocSystemMip(Bmp,mip) )
02797                                 return GE_FALSE;
02798         
02799                         if ( mip != 0 )
02800                         {
02801                                 if ( ! geBitmap_UpdateMips_System(Bmp,mip-1,mip) )
02802                                         return GE_FALSE;
02803                         }
02804                 }
02805         }
02806 
02807         Bmp->Info.MinimumMip = min(Bmp->Info.MinimumMip,low);
02808         Bmp->Info.MaximumMip = max(Bmp->Info.MaximumMip,high);
02809 
02810 return GE_TRUE;
02811 }

GENESISAPI uint32 GENESISCC geBitmap_MipBytes const geBitmap Bmp,
int  mip
 

Definition at line 2815 of file bitmap.c.

References geBitmap_Info::Format, GENESISAPI, GENESISCC, gePixelFormat_BytesPerPel(), geBitmap_Info::Height, geBitmap::Info, SHIFT_R_ROUNDUP, geBitmap_Info::Stride, and uint32.

Referenced by geBitmap_AllocSystemMip(), and geBitmap_CreateFromFile().

02816 {
02817 uint32 bytes;
02818         if ( ! Bmp )
02819                 return 0;
02820         bytes = gePixelFormat_BytesPerPel(Bmp->Info.Format) * 
02821                                                 SHIFT_R_ROUNDUP(Bmp->Info.Stride,mip) *
02822                                                 SHIFT_R_ROUNDUP(Bmp->Info.Height,mip);
02823 return bytes;
02824 }

geBoolean geBitmap_Palette_BlitData gePixelFormat  SrcFormat,
const void *  SrcData,
const geBitmap_Palette SrcPal,
gePixelFormat  DstFormat,
void *  DstData,
const geBitmap_Palette DstPal,
int  Pixels
 

Definition at line 4700 of file bitmap.c.

References A, gePixelFormat_Operations::AMask, B, geBitmap_Palette::ColorKey, geBitmap_Palette::ColorKeyIndex, gePixelFormat_Operations::ComposePixel, gePixelFormat_Operations::DecomposePixel, DstData, G, GE_FALSE, GE_TRUE, geBoolean, gePixelFormat_Composer, gePixelFormat_Decomposer, gePixelFormat_GetOperations(), gePixelFormat_IsRaw(), gePixelFormat_PixelGetter, gePixelFormat_PixelPutter, gePixelFormat_Operations::GetPixel, geBitmap_Palette::HasColorKey, gePixelFormat_Operations::PutPixel, R, SrcData, and uint32.

Referenced by geBitmap_Palette_Copy(), geBitmap_Palette_GetData(), geBitmap_Palette_SetData(), and geBitmap_Palette_SetFormat().

04703 {
04704 char *SrcPtr,*DstPtr;
04705 geBoolean SrcHasCK,DstHasCK;
04706 uint32 SrcCK=0,DstCK=0;
04707 int SrcCKi=0,DstCKi=0;
04708 
04709         assert( SrcData && DstData );
04710 
04711         assert( gePixelFormat_IsRaw(SrcFormat) );
04712         assert( gePixelFormat_IsRaw(DstFormat) );
04713 
04714         SrcPtr = (char *)SrcData;
04715         DstPtr = (char *)DstData;
04716 
04717         if ( SrcPal && SrcPal->HasColorKey )
04718         {
04719                 SrcHasCK = GE_TRUE;
04720                 SrcCK = SrcPal->ColorKey;
04721                 SrcCKi = SrcPal->ColorKeyIndex;
04722         }
04723         else
04724         {
04725                 SrcHasCK = GE_FALSE;
04726         }
04727 
04728         if ( DstPal && DstPal->HasColorKey )
04729         {
04730                 DstHasCK = GE_TRUE;
04731                 DstCK = DstPal->ColorKey;
04732                 DstCKi = DstPal->ColorKeyIndex;
04733         }
04734         else
04735         {
04736                 DstHasCK = GE_FALSE;
04737         }
04738 
04739 #if 0 // {} ?
04740         if ( SrcHasCK && DstHasCK )
04741         {
04742                 if ( DstCKi == -1 )
04743                         DstCKi = SrcCKi;
04744         }
04745 #endif
04746 
04747         // no, can't do this, and if SrcCKi < 0 then it's just ignored, which is correct
04748         //assert( SrcCKi >= 0 );
04749         //assert( DstCKi >= 0 );
04750 
04751         // CK -> no CK : do nothing
04752         // no CK -> CK : avoid CK
04753         // CK -> CK    : assert the CKI's are the same; change color at CKI
04754 
04755         {
04756         uint32 Pixel;
04757         int p,R,G,B,A;
04758         const gePixelFormat_Operations *SrcOps,*DstOps;
04759         gePixelFormat_Composer          ComposePixel;
04760         gePixelFormat_Decomposer        DecomposePixel;
04761         gePixelFormat_PixelPutter       PutPixel;
04762         gePixelFormat_PixelGetter       GetPixel;
04763 
04764                 SrcOps = gePixelFormat_GetOperations(SrcFormat);
04765                 DstOps = gePixelFormat_GetOperations(DstFormat);
04766                 assert(SrcOps && DstOps);
04767 
04768                 GetPixel = SrcOps->GetPixel;
04769                 DecomposePixel = SrcOps->DecomposePixel;
04770                 ComposePixel = DstOps->ComposePixel;
04771                 PutPixel = DstOps->PutPixel;
04772 
04773                 if ( SrcOps->AMask && ! DstOps->AMask )
04774                 {
04775                         // alpha -> CK in the palette
04776                         for(p=0;p<Pixels;p++)
04777                         {
04778                                 Pixel = GetPixel(&SrcPtr);
04779                                 DecomposePixel(Pixel,&R,&G,&B,&A);
04780                                 if ( SrcHasCK && ( p == SrcCKi || Pixel == SrcCK ) ) 
04781                                         A = 0;
04782                                 Pixel = ComposePixel(R,G,B,A);
04783 
04784                                 if ( DstHasCK )
04785                                 {
04786                                         if ( p == DstCKi || A < 128 )
04787                                                 Pixel = DstCK;
04788                                         else if ( Pixel == DstCK )
04789                                                 Pixel ^= 1;
04790 
04791                                         // BTW this makes dark blue into dark purple on glide
04792                                 }
04793                                 PutPixel(&DstPtr,Pixel);
04794                         }
04795                 }
04796                 else if ( ! SrcOps->AMask && DstOps->AMask )
04797                 {
04798                         // CK -> alpha in the palette
04799                         for(p=0;p<Pixels;p++)
04800                         {
04801                                 Pixel = GetPixel(&SrcPtr);
04802                                 DecomposePixel(Pixel,&R,&G,&B,&A);
04803                                 if ( SrcHasCK && ( p == SrcCKi || Pixel == SrcCK ) ) 
04804                                         A = 0;
04805 
04806                                 Pixel = ComposePixel(R,G,B,A);
04807                                 if ( DstHasCK )
04808                                 {
04809                                         if ( p == DstCKi )
04810                                                 Pixel = DstCK;
04811                                         else if ( Pixel == DstCK )
04812                                                 Pixel ^= 1;
04813                                 }
04814                                 PutPixel(&DstPtr,Pixel);
04815                         }
04816                 }
04817                 else
04818                 {
04819                         // both have alpha or both don't
04820                         for(p=0;p<Pixels;p++)
04821                         {
04822                                 Pixel = GetPixel(&SrcPtr);
04823                                 DecomposePixel(Pixel,&R,&G,&B,&A);
04824                                 if ( (SrcHasCK && ( p == SrcCKi || Pixel == SrcCK )) ||
04825                                          DstHasCK && p == DstCKi ) 
04826                                 {
04827                                         Pixel = DstCK;
04828                                 }
04829                                 else
04830                                 {
04831                                         Pixel = ComposePixel(R,G,B,A);
04832                                         if ( DstHasCK && Pixel == DstCK )
04833                                                 Pixel ^= 1;
04834                                 }
04835                                 PutPixel(&DstPtr,Pixel);
04836                         }
04837                 }
04838         }
04839 
04840 return GE_TRUE;
04841 }

GENESISAPI geBoolean GENESISCC geBitmap_Palette_Copy const geBitmap_Palette Fm,
geBitmap_Palette To
 

Definition at line 5195 of file bitmap.c.

References GE_FALSE, GE_TRUE, geBitmap_Palette_BlitData(), geBitmap_Palette_Lock(), geBitmap_Palette_UnLock(), geBoolean, GENESISAPI, GENESISCC, and gePixelFormat.

Referenced by BlitData_DePalettize(), geBitmap_BlitData_Sub(), geBitmap_DetachDriver(), geBitmap_Palette_CreateCopy(), geBitmap_SetPalette(), and geBitmap_Update_DriverToSystem().

05196 {
05197 gePixelFormat FmFormat,ToFormat;
05198 void *FmData,*ToData;
05199 int FmSize,ToSize;
05200 geBoolean Ret;
05201 
05202         assert(Fm);
05203         assert(To);
05204         if ( Fm == To )
05205                 return GE_TRUE;
05206 
05207         if ( ! geBitmap_Palette_Lock((geBitmap_Palette *)Fm,&FmData,&FmFormat,&FmSize) )
05208                 return GE_FALSE;
05209 
05210         if ( ! geBitmap_Palette_Lock(To,&ToData,&ToFormat,&ToSize) )
05211         {
05212                 geBitmap_Palette_UnLock((geBitmap_Palette *)Fm);
05213                 return GE_FALSE;
05214         }
05215 
05216         if ( FmSize > ToSize )
05217         {
05218                 Ret = GE_FALSE;
05219         }
05220         else
05221         {
05222                 Ret = geBitmap_Palette_BlitData(FmFormat,FmData,Fm,ToFormat,ToData,To,FmSize);
05223         }
05224         
05225         geBitmap_Palette_UnLock((geBitmap_Palette *)Fm);
05226         geBitmap_Palette_UnLock(To);
05227 
05228 return Ret;
05229 }

GENESISAPI geBitmap_Palette* GENESISCC geBitmap_Palette_Create gePixelFormat  Format,
int  Size
 

on a file which is streaming, the sequence of returns looks like :

GE_BITMAP_STREAMING_IDLE GE_BITMAP_STREAMING_CHANGED GE_BITMAP_STREAMING_IDLE GE_BITMAP_STREAMING_IDLE GE_BITMAP_STREAMING_CHANGED ... GE_BITMAP_STREAMING_DONE GE_BITMAP_STREAMING_NOT GE_BITMAP_STREAMING_NOT GE_BITMAP_STREAMING_NOT ...

Status >= GE_BITMAP_STREAMING_STARTED means streaming has started & is in progress

the user should never see _STARTED or _DATADONE

Definition at line 4843 of file bitmap.c.

References allocate, clear, geBitmap_Palette::Data, geBitmap_Palette::Format, GE_FALSE, geErrorLog_AddString, GENESISAPI, GENESISCC, gePixelFormat_BytesPerPel(), gePixelFormat_GetOperations(), geRam_Allocate, geRam_Free, geBitmap_Palette::HasColorKey, geBitmap_Palette::LockCount, NULL, geBitmap_Palette::RefCount, gePixelFormat_Operations::RMask, and geBitmap_Palette::Size.

Referenced by BlitData_DePalettize(), BumpMap_CreateFromHeightMap(), createPalette(), createPaletteFast(), createPaletteGoodSub(), ElectricFx_InitPalette(), geBitmap_AllocPalette(), geBitmap_BlitData_Sub(), geBitmap_DetachDriver(), geBitmap_Palette_CreateCopy(), geBitmap_Palette_CreateFromFile(), geBitmap_ReadFromBMP(), geBitmap_ReadFromTGA(), geFont_AddBitmapBuffer(), geFont_AddCharacters(), geWBitmap_Pool_CreateAllWBitmaps(), Particles_InitPalette(), PlasmaAnimator_CreatePalette(), ProcUtil_SetPaletteFromString(), and Smoke_InitPalette().

04844 {
04845 geBitmap_Palette * P;
04846 int DataBytes;
04847 const gePixelFormat_Operations * ops;
04848 
04849         ops = gePixelFormat_GetOperations(Format);
04850         if ( ! ops->RMask )
04851         {
04852                 geErrorLog_AddString(-1,"geBitmap_Palette_Create : Invalid format for a palette!", NULL);
04853                 return NULL;
04854         }
04855 
04856         DataBytes = gePixelFormat_BytesPerPel(Format) * Size;
04857         if ( DataBytes == 0 )
04858         {
04859                 geErrorLog_AddString(-1,"geBitmap_Palette_Create : Invalid format for a palette!", NULL);
04860                 return NULL;
04861         }
04862 
04863         allocate(P);
04864         if ( ! P ) return NULL;
04865         clear(P);
04866 
04867         P->Size = Size;
04868         P->Format = Format;
04869         if ( ! (P->Data = geRam_Allocate(DataBytes)) )
04870         {
04871                 geRam_Free(P);
04872                 return NULL;
04873         }
04874 
04875         P->RefCount = 1;
04876         P->LockCount = 0;
04877 
04878         P->HasColorKey = GE_FALSE;
04879 
04880 return P;
04881 }

GENESISAPI geBitmap_Palette* GENESISCC geBitmap_Palette_CreateCopy const geBitmap_Palette Palette  ) 
 

Definition at line 4946 of file bitmap.c.

References geBitmap_Palette::Driver, geBitmap_Palette::Format, geBitmap_Palette_Copy(), geBitmap_Palette_Create(), geBitmap_Palette_CreateFromDriver(), geBitmap_Palette_Destroy(), GENESISAPI, GENESISCC, NULL, and geBitmap_Palette::Size.

Referenced by geBitmap_AllocPalette().

04947 {
04948 geBitmap_Palette * P;
04949 
04950         if ( ! Palette )
04951                 return NULL;
04952 
04953         if ( Palette->Driver )
04954         {
04955                 P = geBitmap_Palette_CreateFromDriver(Palette->Driver,Palette->Format,Palette->Size);
04956         }
04957         else
04958         {
04959                 P = geBitmap_Palette_Create(Palette->Format,Palette->Size);
04960         }
04961 
04962         if ( ! P ) return NULL;
04963 
04964         if ( ! geBitmap_Palette_Copy(Palette,P) )
04965         {
04966                 geBitmap_Palette_Destroy(&P);
04967                 return NULL;
04968         }
04969 
04970 return P;
04971 }

GENESISAPI geBitmap_Palette* GENESISCC geBitmap_Palette_CreateFromBitmap geBitmap Bmp,
geBoolean  Slow
 

Definition at line 4891 of file bitmap.c.

References createPaletteFromBitmap(), geBitmap_GetPalette(), geBitmap_Palette_CreateRef(), GENESISAPI, and GENESISCC.

Referenced by geBitmap_SetFormat().

04892 {
04893 geBitmap_Palette * Pal;
04894         Pal = geBitmap_GetPalette(Bmp);
04895         if ( Pal )
04896         {
04897                 geBitmap_Palette_CreateRef(Pal);
04898                 return Pal;
04899         }
04900         else
04901         {
04902                 return createPaletteFromBitmap(Bmp, Slow);
04903         }
04904 }

geBitmap_Palette* BITMAP_GENESIS_INTERNAL geBitmap_Palette_CreateFromDriver DRV_Driver Driver,
gePixelFormat  Format,
int  Size
 

Definition at line 4906 of file bitmap.c.

References allocate, BITMAP_GENESIS_INTERNAL, clear, geRDriver_THandleInfo::ColorKey, geBitmap_Palette::ColorKey, geBitmap_Palette::ColorKeyIndex, geBitmap_Palette::Driver, geBitmap_Palette::DriverHandle, geRDriver_THandleInfo::Flags, geBitmap_Palette::Format, GE_FALSE, GE_TRUE, geBitmap_CreateTHandle(), geErrorLog_AddString, gePixelFormat_HasAlpha(), gePixelFormat_IsRaw(), geRam_Free, geBitmap_Palette::HasColorKey, NULL, geRDriver_PixelFormat::PixelFormat, geRDriver_THandleInfo::PixelFormat, RDRIVER_PF_PALETTE, RDRIVER_THANDLE_HAS_COLORKEY, geBitmap_Palette::RefCount, geBitmap_Palette::Size, and DRV_Driver::THandle_GetInfo.

Referenced by geBitmap_AllocPalette(), and geBitmap_Palette_CreateCopy().

04907 {
04908 geBitmap_Palette * P;
04909 geRDriver_THandleInfo TInfo;
04910 
04911         assert(Driver);
04912 
04913         allocate(P);
04914         if ( ! P ) return NULL;
04915         clear(P);
04916 
04917         P->Size = Size;
04918         P->Driver = Driver;     
04919 
04920         // {} the pixelformat passed in here has non-trivial implications when the
04921         //              driver provides more than one possible palette type
04922 
04923         assert( gePixelFormat_IsRaw(Format) );
04924 
04925         P->DriverHandle = geBitmap_CreateTHandle(Driver,Size,1,1,
04926                         Format,0,0,gePixelFormat_HasAlpha(Format),0,RDRIVER_PF_PALETTE);
04927         if ( ! P->DriverHandle )
04928         {
04929                 geErrorLog_AddString(-1,"Palette_CreateFromDriver : CreateTHandle", NULL);      
04930                 geRam_Free(P);
04931                 return NULL;
04932         }
04933 
04934         Driver->THandle_GetInfo(P->DriverHandle,0,&TInfo);
04935         P->Format = TInfo.PixelFormat.PixelFormat;
04936 
04937         P->HasColorKey = (TInfo.Flags & RDRIVER_THANDLE_HAS_COLORKEY) ? GE_TRUE : GE_FALSE;
04938         P->ColorKey = TInfo.ColorKey;
04939         P->ColorKeyIndex = -1;
04940 
04941         P->RefCount = 1;
04942 
04943 return P;
04944 }

GENESISAPI geBitmap_Palette* GENESISCC geBitmap_Palette_CreateFromFile geVFile F  ) 
 

Definition at line 5381 of file bitmap.c.

References geBitmap_Palette::Data, geBitmap_Palette::Format, GE_FALSE, geBitmap_Palette_Create(), geErrorLog_AddString, GENESISAPI, GENESISCC, gePixelFormat, gePixelFormat_BytesPerPel(), geRam_Free, geVFile_Read(), NULL, PALETTE_INFO_FLAG_COMPRESS, PALETTE_INFO_FLAG_SIZE256, PALETTE_INFO_FORMAT_MASK, geBitmap_Palette::Size, and uint8.

Referenced by geBitmap_CreateFromFile().

05382 {
05383 geBitmap_Palette * P;
05384 int Size;
05385 gePixelFormat Format;
05386 uint8 flags,b;
05387 
05388         if ( ! geVFile_Read(F, &flags, sizeof(flags)) )
05389                 return NULL;
05390 
05391         Format = flags & PALETTE_INFO_FORMAT_MASK;
05392 
05393         if ( flags & PALETTE_INFO_FLAG_SIZE256 )
05394         {
05395                 Size = 256;
05396         }
05397         else
05398         {
05399                 if ( ! geVFile_Read(F, &b, sizeof(b)) )
05400                         return NULL;
05401                 Size = b;
05402         }
05403 
05404         P = geBitmap_Palette_Create(Format,Size);
05405         if ( ! P )
05406                 return NULL;
05407 
05408         if ( flags & PALETTE_INFO_FLAG_COMPRESS )
05409         {
05410                 geErrorLog_AddString(-1,"Bitmap_Palette_CreateFromFile : codePal failed!",NULL);
05411                 return GE_FALSE;
05412         }
05413         else
05414         {
05415                 if ( ! geVFile_Read(F, P->Data, gePixelFormat_BytesPerPel(P->Format) * P->Size) )
05416                 {
05417                         geRam_Free(P);
05418                         return NULL;
05419                 }
05420         }
05421 
05422 return P;
05423 }

GENESISAPI geBoolean GENESISCC geBitmap_Palette_CreateRef geBitmap_Palette P  ) 
 

Definition at line 4883 of file bitmap.c.

References GE_FALSE, GE_TRUE, geBoolean, GENESISAPI, GENESISCC, and geBitmap_Palette::RefCount.

Referenced by geBitmap_CreateFromInfo(), geBitmap_CreateLockFromMip(), geBitmap_CreateLockFromMipOnDriver(), geBitmap_CreateLockFromMipSystem(), geBitmap_Palette_CreateFromBitmap(), and geBitmap_SetPalette().

04884 {
04885         if ( ! P || P->RefCount < 1 )
04886                 return GE_FALSE;
04887         P->RefCount ++;
04888 return GE_TRUE;
04889 }

GENESISAPI geBoolean GENESISCC geBitmap_Palette_Destroy geBitmap_Palette **  ppPalette  ) 
 

Definition at line 4973 of file bitmap.c.

References geBitmap_Palette::Data, geBitmap_Palette::Driver, geBitmap_Palette::DriverHandle, GE_FALSE, GE_TRUE, geBoolean, GENESISAPI, GENESISCC, geRam_Free, geBitmap_Palette::LockCount, NULL, geBitmap_Palette::RefCount, and DRV_Driver::THandle_Destroy.

Referenced by BlitData_DePalettize(), BumpMap_CreateFromHeightMap(), ElectricFx_InitPalette(), geBitmap_BlitData_Sub(), geBitmap_Destroy(), geBitmap_DetachDriver(), geBitmap_Palette_CreateCopy(), geBitmap_SetFormat(), geBitmap_SetPalette(), geBitmap_Update_SystemToDriver(), geFont_AddCharacters(), geWBitmap_Pool_CreateAllWBitmaps(), Particles_InitPalette(), PlasmaAnimator_CreatePalette(), ProcUtil_SetPaletteFromString(), and Smoke_InitPalette().

04974 {
04975 geBitmap_Palette * Palette;
04976         assert(ppPalette);
04977         if ( Palette = *ppPalette )
04978         {
04979                 if ( Palette->LockCount )
04980                         return GE_FALSE;
04981                 Palette->RefCount --;
04982                 if ( Palette->RefCount <= 0 )
04983                 {
04984                         if ( Palette->Data )
04985                                 geRam_Free(Palette->Data);
04986                         if ( Palette->DriverHandle )
04987                         {
04988                                 Palette->Driver->THandle_Destroy(Palette->DriverHandle);
04989                                 Palette->DriverHandle = NULL;
04990                         }
04991                         geRam_Free(Palette);
04992                 }
04993         }
04994         *ppPalette = NULL;
04995 return GE_TRUE;
04996 }

GENESISAPI geBoolean GENESISCC geBitmap_Palette_GetData const geBitmap_Palette P,
void *  Into,
gePixelFormat  Format,
int  Size
 

Definition at line 5132 of file bitmap.c.

References GE_FALSE, geBitmap_Palette_BlitData(), geBitmap_Palette_Lock(), geBitmap_Palette_UnLock(), geBoolean, GENESISAPI, GENESISCC, gePixelFormat, and NULL.

Referenced by BlitData_FromSeparateAlpha(), createPaletteFromBitmap(), geBitmap_UpdateMips_Data(), geBitmapUtil_SetAlphaFromBrightness(), and palettizePlane().

05133 {
05134 gePixelFormat FmFormat;
05135 const void *FmData;
05136 int FmSize;
05137 geBoolean Ret;
05138 
05139         assert(P);
05140         assert(Into);
05141 
05142         if ( ! geBitmap_Palette_Lock((geBitmap_Palette *)P,(void **)&FmData,&FmFormat,&FmSize) )
05143                 return GE_FALSE;
05144 
05145         if ( FmSize < Size )
05146                 Size = FmSize;
05147 
05148         Ret = geBitmap_Palette_BlitData(FmFormat,FmData,P,Format,Into,NULL,Size);
05149         
05150         geBitmap_Palette_UnLock((geBitmap_Palette *)P);
05151 
05152 return Ret;
05153 }

GENESISAPI geBoolean GENESISCC geBitmap_Palette_GetEntry const geBitmap_Palette P,
int  Color,
uint32 Pixel
 

Definition at line 5337 of file bitmap.c.

References geBitmap_Palette::Data, geBitmap_Palette::Format, GE_FALSE, GE_TRUE, geBitmap_Palette_Lock(), geBitmap_Palette_UnLock(), geBoolean, GENESISAPI, GENESISCC, gePixelFormat, gePixelFormat_BytesPerPel(), gePixelFormat_GetPixel(), and geBitmap_Palette::Size.

Referenced by BlitData_DePalettize(), geBitmap_Palette_GetEntryColor(), and geBitmap_SetFormatMin().

05338 {
05339 
05340         assert(P);
05341 
05342         if ( P->Data )
05343         {
05344         char *Data;
05345 
05346                 if ( Color >= P->Size )
05347                         return GE_FALSE;
05348 
05349                 Data = (char *)(P->Data) + Color * gePixelFormat_BytesPerPel(P->Format);
05350                 *Pixel = gePixelFormat_GetPixel(P->Format,&Data);
05351         }
05352         else
05353         {
05354         char *Data;
05355         gePixelFormat Format;
05356         int Size;
05357 
05358                 // must cast away const cuz we don't have a lockforread/write on palettes
05359 
05360                 if ( ! geBitmap_Palette_Lock((geBitmap_Palette *)P,&Data,&Format,&Size) )
05361                         return GE_FALSE;
05362 
05363                 if ( Color >= Size )
05364                 {
05365                         geBitmap_Palette_UnLock((geBitmap_Palette *)P);
05366                         return GE_FALSE;
05367                 }
05368 
05369                 Data += Color * gePixelFormat_BytesPerPel(Format);
05370                 *Pixel = gePixelFormat_GetPixel(Format,&Data);
05371 
05372                 geBitmap_Palette_UnLock((geBitmap_Palette *)P);
05373         }
05374 return GE_TRUE;
05375 }

GENESISAPI geBoolean GENESISCC geBitmap_Palette_GetEntryColor const geBitmap_Palette P,
int  Color,
int *  R,
int *  G,
int *  B,
int *  A
 

Definition at line 5260 of file bitmap.c.

References A, B, geBitmap_Palette::ColorKey, geBitmap_Palette::ColorKeyIndex, geBitmap_Palette::Format, G, GE_FALSE, GE_TRUE, geBitmap_Palette_GetEntry(), geBoolean, GENESISAPI, GENESISCC, gePixelFormat_DecomposePixel(), geBitmap_Palette::HasColorKey, R, and uint32.

05261 {
05262 uint32 Pixel;
05263         assert(P);
05264         if ( P->HasColorKey )
05265         {
05266                 if ( Color == P->ColorKeyIndex )
05267                 {
05268                         *R = *G = *B = *A = 0;
05269                         return GE_TRUE;
05270                 }
05271                 else
05272                 {
05273                         if ( ! geBitmap_Palette_GetEntry(P,Color,&Pixel) )
05274                                 return GE_FALSE;
05275                         if ( Pixel == P->ColorKey )
05276                         {
05277                                 *R = *G = *B = *A = 0;
05278                         }
05279                         else
05280                         {
05281                                 gePixelFormat_DecomposePixel(P->Format,Pixel,R,G,B,A);
05282                         }
05283                 }
05284         }
05285         else
05286         {
05287                 if ( ! geBitmap_Palette_GetEntry(P,Color,&Pixel) )
05288                         return GE_FALSE;
05289                 gePixelFormat_DecomposePixel(P->Format,Pixel,R,G,B,A);
05290         }
05291         return GE_TRUE;
05292 }

GENESISAPI geBoolean GENESISCC geBitmap_Palette_GetInfo const geBitmap_Palette P,
geBitmap_Info pInfo
 

Definition at line 5155 of file bitmap.c.

References geBitmap_Info::ColorKey, geBitmap_Palette::ColorKey, geBitmap_Info::Format, geBitmap_Palette::Format, GE_TRUE, geBoolean, GENESISAPI, GENESISCC, geBitmap_Info::HasColorKey, geBitmap_Palette::HasColorKey, geBitmap_Info::Height, geBitmap_Info::MaximumMip, geBitmap_Info::MinimumMip, NULL, geBitmap_Info::Palette, geBitmap_Palette::Size, geBitmap_Info::Stride, and geBitmap_Info::Width.

Referenced by geBitmap_Gamma_Apply().

05156 {
05157         assert(P && pInfo);
05158 
05159         pInfo->Width = pInfo->Stride = P->Size;
05160         pInfo->Height = 1;
05161 
05162         pInfo->Format = P->Format;
05163         pInfo->HasColorKey = P->HasColorKey;
05164         pInfo->ColorKey = P->ColorKey;
05165         pInfo->MaximumMip = pInfo->MinimumMip = 0;
05166         pInfo->Palette = NULL;
05167 
05168 return GE_TRUE;
05169 }

geBoolean geBitmap_Palette_IsValid const geBitmap_Palette Pal  ) 
 

Definition at line 5546 of file bitmap.c.

References geBitmap_Palette::Data, geBitmap_Palette::Driver, geBitmap_Palette::DriverHandle, geBitmap_Palette::Format, GE_FALSE, GE_PIXELFORMAT_COUNT, GE_PIXELFORMAT_NO_DATA, GE_TRUE, geBoolean, geBitmap_Palette::RefCount, and geBitmap_Palette::Size.

Referenced by geBitmap_Info_IsValid(), and geBitmap_SetPalette().

05547 {
05548         if ( ! Pal ) return GE_FALSE;
05549 
05550         assert(  Pal->Data ||  Pal->DriverHandle );
05551         assert( !Pal->Data || !Pal->DriverHandle );
05552 
05553         assert( (Pal->Driver && Pal->DriverHandle) ||
05554                 (! Pal->Driver && ! Pal->DriverHandle) );
05555 
05556         assert( Pal->RefCount >= 1 && Pal->Size >= 1 );
05557         assert( Pal->Format > GE_PIXELFORMAT_NO_DATA && Pal->Format < GE_PIXELFORMAT_COUNT );
05558 
05559 return GE_TRUE;
05560 }

GENESISAPI geBoolean GENESISCC geBitmap_Palette_Lock geBitmap_Palette P,
void **  pBits,
gePixelFormat pFormat,
int *  pSize
 

Definition at line 4998 of file bitmap.c.

References geBitmap_Palette::Data, geBitmap_Palette::Driver, geBitmap_Palette::DriverBits, geBitmap_Palette::DriverHandle, geBitmap_Palette::Format, GE_FALSE, GE_TRUE, geBoolean, GENESISAPI, GENESISCC, geRDriver_THandleInfo::Height, geBitmap_Palette::LockCount, NULL, geRDriver_THandleInfo::PixelFormat, geRDriver_PixelFormat::PixelFormat, geBitmap_Palette::Size, DRV_Driver::THandle_GetInfo, DRV_Driver::THandle_Lock, and geRDriver_THandleInfo::Width.

Referenced by BumpMap_ComputePalette(), ElectricFx_InitPalette(), geBitmap_Gamma_Apply(), geBitmap_Palette_Copy(), geBitmap_Palette_GetData(), geBitmap_Palette_GetEntry(), geBitmap_Palette_SetData(), geBitmap_Palette_SetEntry(), geBitmap_Palette_WriteToFile(), geWBitmap_Pool_CreateAllWBitmaps(), Particles_InitPalette(), PlasmaAnimator_CreatePalette(), ProcUtil_SetPaletteFromString(), and Smoke_InitPalette().

04999 {
05000         assert(P);
05001         assert(pBits);
05002 
05003         if ( P->LockCount )
05004                 return GE_FALSE;
05005         P->LockCount++;
05006 
05007         *pBits = NULL;
05008 
05009         if ( P->Data )
05010         {
05011                 *pBits          = P->Data;
05012                 if ( pFormat )
05013                         *pFormat= P->Format;
05014                 if ( pSize )
05015                         *pSize  = P->Size;
05016         }
05017         else if ( P->DriverHandle )
05018         {
05019         geRDriver_THandleInfo TInfo;
05020 
05021                 if ( ! P->Driver->THandle_GetInfo(P->DriverHandle,0,&TInfo) )
05022                         return GE_FALSE;
05023 
05024                 if ( TInfo.Height != 1 )
05025                         return GE_FALSE;
05026 
05027                 if ( ! (P->Driver->THandle_Lock(P->DriverHandle,0,pBits)) )
05028                         *pBits = NULL;
05029 
05030                 P->DriverBits = *pBits;
05031 
05032                 if ( pFormat )
05033                         *pFormat = TInfo.PixelFormat.PixelFormat;
05034                 if ( pSize )
05035                         *pSize = TInfo.Width;
05036         }
05037 
05038         return (*pBits) ? GE_TRUE : GE_FALSE;
05039 }

GENESISAPI geBoolean GENESISCC geBitmap_Palette_SetData geBitmap_Palette P,
const void *  From,
gePixelFormat  Format,
int  Colors
 

Definition at line 5171 of file bitmap.c.

References GE_FALSE, geBitmap_Palette_BlitData(), geBitmap_Palette_Lock(), geBitmap_Palette_UnLock(), geBoolean, GENESISAPI, GENESISCC, gePixelFormat, and NULL.

Referenced by createPalette(), createPaletteFast(), createPaletteFromBitmap(), createPaletteGoodSub(), geBitmapUtil_SetAlphaFromBrightness(), geFont_DrawText(), and geFont_DrawTextToBitmap().

05172 {
05173 gePixelFormat PalFormat;
05174 void *PalData;
05175 int PalSize;
05176 geBoolean Ret;
05177 
05178         assert(P);
05179         assert(From);
05180 
05181         if ( ! geBitmap_Palette_Lock(P,&PalData,&PalFormat,&PalSize) )
05182                 return GE_FALSE;
05183 
05184         if ( PalSize < Colors )
05185                 Colors = PalSize;
05186 
05187         Ret = geBitmap_Palette_BlitData(Format,From,NULL,PalFormat,PalData,P,Colors);
05188         
05189         if ( ! geBitmap_Palette_UnLock(P) )
05190                 return GE_FALSE;
05191 
05192 return Ret;
05193 }

GENESISAPI geBoolean GENESISCC geBitmap_Palette_SetEntry geBitmap_Palette P,
int  Color,
uint32  Pixel
 

Definition at line 5294 of file bitmap.c.

References geBitmap_Palette::ColorKeyIndex, geBitmap_Palette::Data, geBitmap_Palette::Format, GE_FALSE, GE_TRUE, geBitmap_Palette_Lock(), geBitmap_Palette_UnLock(), geBoolean, GENESISAPI, GENESISCC, gePixelFormat, gePixelFormat_BytesPerPel(), gePixelFormat_PutPixel(), geBitmap_Palette::HasColorKey, and geBitmap_Palette::Size.

Referenced by BlitData_DePalettize(), and geBitmap_Palette_SetEntryColor().

05295 {
05296         assert(P);
05297 
05298         if ( P->HasColorKey )
05299         {
05300                 if ( Color == P->ColorKeyIndex )
05301                         return GE_TRUE;
05302         }
05303 
05304         if ( P->Data )
05305         {
05306         char *Data;
05307 
05308                 if ( Color >= P->Size )
05309                         return GE_FALSE;
05310 
05311                 Data = (char *)(P->Data) + Color * gePixelFormat_BytesPerPel(P->Format);
05312                 gePixelFormat_PutPixel(P->Format,&Data,Pixel);
05313         }
05314         else
05315         {
05316         char *Data;
05317         gePixelFormat Format;
05318         int Size;
05319 
05320                 if ( ! geBitmap_Palette_Lock(P,&Data,&Format,&Size) )
05321                         return GE_FALSE;
05322 
05323                 if ( Color >= Size )
05324                 {
05325                         geBitmap_Palette_UnLock(P);
05326                         return GE_FALSE;
05327                 }
05328 
05329                 Data += Color * gePixelFormat_BytesPerPel(Format);
05330                 gePixelFormat_PutPixel(Format,&Data,Pixel);
05331 
05332                 geBitmap_Palette_UnLock(P);
05333         }
05334 return GE_TRUE;
05335 }

GENESISAPI geBoolean GENESISCC geBitmap_Palette_SetEntryColor geBitmap_Palette P,
int  Color,
int  R,
int  G,
int  B,
int  A
 

Definition at line 5231 of file bitmap.c.

References A, B, geBitmap_Palette::ColorKey, geBitmap_Palette::ColorKeyIndex, geBitmap_Palette::Format, G, GE_FALSE, geBitmap_Palette_SetEntry(), geBoolean, GENESISAPI, GENESISCC, gePixelFormat_ComposePixel(), gePixelFormat_HasAlpha(), geBitmap_Palette::HasColorKey, R, and uint32.

Referenced by BlitData_DePalettize(), geBitmap_BlitData_Sub(), geFont_AddBitmapBuffer(), and geFont_AddCharacters().

05232 {
05233         assert(P);
05234         
05235         if ( A < 80 && ! gePixelFormat_HasAlpha(P->Format) && P->HasColorKey )
05236         {
05237                 return geBitmap_Palette_SetEntry(P,Color,P->ColorKey);
05238         }
05239         else if ( P->HasColorKey )
05240         {
05241         uint32 Pixel;
05242 
05243                 // might have alpha AND colorkey !
05244 
05245                 if ( Color == P->ColorKeyIndex ) // and A > 80 because of the above
05246                         return GE_FALSE;
05247 
05248                 Pixel = gePixelFormat_ComposePixel(P->Format,R,G,B,A);
05249                 if ( Pixel == P->ColorKey )
05250                         Pixel ^= 1;
05251                         
05252                 return geBitmap_Palette_SetEntry(P,Color,Pixel);
05253         }
05254         else
05255         {
05256                 return geBitmap_Palette_SetEntry(P,Color,gePixelFormat_ComposePixel(P->Format,R,G,B,A));
05257         }
05258 }

GENESISAPI geBoolean GENESISCC geBitmap_Palette_SetFormat geBitmap_Palette P,
gePixelFormat  Format
 

Definition at line 5101 of file bitmap.c.

References geBitmap_Palette::Data, geBitmap_Palette::DriverHandle, geBitmap_Palette::Format, GE_FALSE, GE_TRUE, geBitmap_Palette_BlitData(), geBoolean, GENESISAPI, GENESISCC, gePixelFormat_BytesPerPel(), geRam_Allocate, geRam_Free, geBitmap_Palette::HasColorKey, NULL, and geBitmap_Palette::Size.

Referenced by geBitmapUtil_SetAlphaFromBrightness().

05102 {
05103 void * NewData;
05104         
05105         assert(P);
05106 
05107         if ( P->DriverHandle ) // can't change format on card!
05108                 return GE_FALSE;
05109 
05110         assert( ! P->HasColorKey ); // can't have colorkey accept on Glide
05111 
05112         if ( Format == P->Format )
05113                 return GE_TRUE;
05114 
05115         NewData = geRam_Allocate( gePixelFormat_BytesPerPel(Format) * P->Size );
05116         if ( ! NewData )
05117                 return GE_FALSE;
05118 
05119         if ( ! geBitmap_Palette_BlitData(P->Format,P->Data,NULL,Format,NewData,NULL,P->Size) )
05120         {
05121                 geRam_Free(NewData);
05122                 return GE_FALSE;
05123         }
05124 
05125         geRam_Free(P->Data);
05126         P->Data = NewData;
05127         P->Format = Format;
05128 
05129 return GE_TRUE;
05130 }

GENESISAPI geBoolean GENESISCC geBitmap_Palette_UnLock geBitmap_Palette P  ) 
 

Definition at line 5041 of file bitmap.c.

References geBitmap_Palette::ColorKey, geBitmap_Palette::ColorKeyIndex, geBitmap_Palette::Data, geBitmap_Palette::Driver, geBitmap_Palette::DriverBits, geBitmap_Palette::DriverHandle, geBitmap_Palette::Format, GE_FALSE, GE_TRUE, geBoolean, GENESISAPI, GENESISCC, gePixelFormat_GetOperations(), gePixelFormat_PixelGetter, gePixelFormat_PixelPutter, gePixelFormat_Operations::GetPixel, geBitmap_Palette::HasColorKey, geBitmap_Palette::LockCount, NULL, gePixelFormat_Operations::PutPixel, geBitmap_Palette::Size, DRV_Driver::THandle_UnLock, uint32, and uint8.

Referenced by BumpMap_ComputePalette(), ElectricFx_InitPalette(), geBitmap_Gamma_Apply(), geBitmap_Palette_Copy(), geBitmap_Palette_GetData(), geBitmap_Palette_GetEntry(), geBitmap_Palette_SetData(), geBitmap_Palette_SetEntry(), geBitmap_Palette_WriteToFile(), geWBitmap_Pool_CreateAllWBitmaps(), Particles_InitPalette(), PlasmaAnimator_CreatePalette(), ProcUtil_SetPaletteFromString(), and Smoke_InitPalette().

05042 {
05043         assert(P);
05044         if ( P->LockCount <= 0 )
05045                 return GE_FALSE;
05046         P->LockCount--;
05047         if ( P->LockCount == 0 )
05048         {
05049                 if ( P->HasColorKey )
05050                 {
05051                         if ( P->ColorKeyIndex >= 0 && P->ColorKeyIndex < P->Size )
05052                         {
05053                         uint8 *Bits=NULL,*pBits=NULL;
05054                         uint32 Pixel;
05055                         int p;
05056                         const gePixelFormat_Operations *ops;
05057                         gePixelFormat_PixelPutter       PutPixel;
05058                         gePixelFormat_PixelGetter       GetPixel;
05059 
05060                                 if ( P->Data )
05061                                 {
05062                                         Bits = P->Data;
05063                                 }
05064                                 else if ( P->DriverBits )
05065                                 {
05066                                         Bits = P->DriverBits;
05067                                 }
05068 
05069                                 ops = gePixelFormat_GetOperations(P->Format);
05070                                 assert(ops);
05071 
05072                                 GetPixel = ops->GetPixel;
05073                                 PutPixel = ops->PutPixel;
05074 
05075                                 for(p=0;p<P->Size;p++)
05076                                 {
05077                                         pBits = Bits;
05078                                         Pixel = GetPixel(&Bits);
05079                                         if ( p == P->ColorKeyIndex )
05080                                         {
05081                                                 PutPixel(&pBits,P->ColorKey);
05082                                         }
05083                                         else if ( Pixel == P->ColorKey )
05084                                         {
05085                                                 Pixel ^= 1;
05086                                                 PutPixel(&pBits,Pixel);
05087                                         }
05088                                 }
05089                         }
05090                 }
05091                 if ( P->DriverHandle )
05092                 {
05093                         if ( ! P->Driver->THandle_UnLock(P->DriverHandle,0) )
05094                                 return GE_FALSE;
05095                         P->DriverBits = NULL;
05096                 }
05097         }
05098 return GE_TRUE;
05099 }

GENESISAPI geBoolean GENESISCC geBitmap_Palette_WriteToFile const geBitmap_Palette P,
geVFile F
 

Definition at line 5425 of file bitmap.c.

References GE_FALSE, GE_TRUE, geBitmap_Palette_Lock(), geBitmap_Palette_UnLock(), geBoolean, GENESISAPI, GENESISCC, gePixelFormat, gePixelFormat_BytesPerPel(), geVFile_Write(), geBitmap_Palette::HasColorKey, PALETTE_INFO_FLAG_SIZE256, and uint8.

Referenced by geBitmap_WriteToFile().

05426 {
05427 int Size;
05428 gePixelFormat Format;
05429 void *Data;
05430 
05431         assert(P);
05432 
05433         assert( P->HasColorKey == GE_FALSE ); // system palettes can't have color key!
05434 
05435         // we usually write the palette's header in one byte :^)
05436 
05437         if ( ! geBitmap_Palette_Lock((geBitmap_Palette *)P,&Data,&Format,&Size) )
05438                 return GE_FALSE;
05439 
05440         {
05441         uint8 b;
05442 
05443                 b = Format;
05444                 assert( b < 32 );
05445                 if ( Size == 256 )
05446                         b |= PALETTE_INFO_FLAG_SIZE256;
05447 
05448                 if ( ! geVFile_Write(F, &b, sizeof(b)) )
05449                 {
05450                         geBitmap_Palette_UnLock((geBitmap_Palette *)P);
05451                         return GE_FALSE;
05452                 }
05453 
05454                 if ( Size != 256 )
05455                 {
05456                         assert(Size < 256);
05457                         b = Size;
05458                         
05459                         if ( ! geVFile_Write(F, &b, sizeof(b)) )
05460                         {
05461                                 geBitmap_Palette_UnLock((geBitmap_Palette *)P);
05462                                 return GE_FALSE;
05463                         }
05464                 }
05465         }
05466 
05467         if ( ! geVFile_Write(F, Data, gePixelFormat_BytesPerPel(Format) * Size) )
05468         {
05469                 geBitmap_Palette_UnLock((geBitmap_Palette *)P);
05470                 return GE_FALSE;
05471         }
05472                 
05473         geBitmap_Palette_UnLock((geBitmap_Palette *)P);
05474 
05475 return GE_TRUE;
05476 }

geBoolean geBitmap_ReadFromBMP geBitmap Bmp,
geVFile F
[static]
 

Definition at line 4105 of file bitmap.c.

References BITMAPFILEHEADER::bfOffBits, BITMAPFILEHEADER::bfType, BITMAPINFOHEADER::biBitCount, BITMAPINFOHEADER::biClrUsed, BITMAPINFOHEADER::biCompression, BITMAPINFOHEADER::biHeight, BITMAPINFOHEADER::biSize, BITMAPINFOHEADER::biWidth, geBitmap::Data, geBitmap_Palette::Data, geBitmap_Info::Format, GE_FALSE, GE_PIXELFORMAT_16BIT_555_RGB, GE_PIXELFORMAT_24BIT_BGR, GE_PIXELFORMAT_32BIT_XRGB, GE_PIXELFORMAT_8BIT_PAL, GE_TRUE, GE_VFILE_SEEKCUR, geBitmap_AllocSystemMip(), geBitmap_Palette_Create(), geBoolean, geErrorLog_AddString, geVFile_Read(), geVFile_Seek(), geBitmap_Info::HasColorKey, geBitmap_Info::Height, geBitmap::Info, NULL, geBitmap_Info::Palette, geBitmap_Info::Stride, geBitmap_Info::Width, and y.

Referenced by geBitmap_CreateFromFile().

04106 {
04107 BITMAPFILEHEADER        bmfh;
04108 BITMAPINFOHEADER        bmih;
04109 int bPad,myRowWidth,bmpRowWidth,pelBytes;
04110 
04111         // Windows Bitmap
04112 
04113         if ( ! geVFile_Read(F, &bmfh, sizeof(bmfh)) )
04114                 return GE_FALSE;
04115 
04116         assert(bmfh.bfType == 0x4D42);
04117 
04118         bPad = bmfh.bfOffBits;
04119 
04120         if ( ! geVFile_Read(F, &bmih, sizeof(bmih)) )
04121                 return GE_FALSE;
04122 
04123         if ( bmih.biSize > sizeof(bmih) )
04124         {
04125                 geVFile_Seek(F, bmih.biSize - sizeof(bmih), GE_VFILE_SEEKCUR);
04126         }
04127         else if ( bmih.biSize < sizeof(bmih) )
04128         {
04129                 geErrorLog_AddString(-1,"CreateFromFile : bmih size bad", NULL);        
04130                 return GE_FALSE;
04131         }
04132 
04133         if ( bmih.biCompression )
04134         {
04135                 geErrorLog_AddString(-1,"CreateFromFile : only BI_RGB BMP compression supported", NULL);
04136                 return GE_FALSE;
04137         }
04138 
04139         bPad -= sizeof(bmih) + sizeof(bmfh);
04140 
04141         switch (bmih.biBitCount) 
04142         {
04143                 case 8:                 /* colormapped image */
04144                         if ( bmih.biClrUsed == 0 ) bmih.biClrUsed = 256;
04145 
04146                         if ( ! (Bmp->Info.Palette = geBitmap_Palette_Create(GE_PIXELFORMAT_32BIT_XRGB,bmih.biClrUsed)) )
04147                                 return GE_FALSE;
04148 
04149                         if ( ! geVFile_Read(F, Bmp->Info.Palette->Data, bmih.biClrUsed * 4) )
04150                                 return GE_FALSE;
04151 
04152                         bPad -= bmih.biClrUsed * 4;
04153 
04154                         Bmp->Info.Format = GE_PIXELFORMAT_8BIT_PAL;
04155                         pelBytes = 1;
04156                         break;
04157                 case 16:                        
04158                         Bmp->Info.Format = GE_PIXELFORMAT_16BIT_555_RGB;
04159                         // tried 555,565_BGR & RGB, seems to have too much green
04160                         pelBytes = 2;
04161                         break;
04162                 case 24:                        
04163                         Bmp->Info.Format = GE_PIXELFORMAT_24BIT_BGR;
04164                         pelBytes = 3;
04165                         break;
04166                 case 32:                        
04167                         Bmp->Info.Format = GE_PIXELFORMAT_32BIT_XRGB; // surprisingly sane !?
04168                         pelBytes = 4;
04169                         break;
04170                 default:
04171                         return GE_FALSE;
04172         }
04173 
04174         if ( bPad < 0 )
04175         {
04176                 geErrorLog_AddString(-1,"CreateFromFile : bPad bad", NULL);
04177                 return GE_FALSE;
04178         }
04179 
04180         geVFile_Seek(F, bPad, GE_VFILE_SEEKCUR);
04181         
04182         Bmp->Info.Width = bmih.biWidth;
04183         Bmp->Info.Height = abs(bmih.biHeight);
04184         Bmp->Info.Stride = ((bmih.biWidth+3)&(~3));
04185 
04186         Bmp->Info.HasColorKey = GE_FALSE;
04187 
04188         myRowWidth      = Bmp->Info.Stride * pelBytes;
04189         bmpRowWidth = (((bmih.biWidth * pelBytes) + 3)&(~3));
04190 
04191         assert( bmpRowWidth <= myRowWidth );
04192 
04193         if ( ! geBitmap_AllocSystemMip(Bmp,0) )
04194                 return GE_FALSE;
04195 
04196         if ( bmih.biHeight > 0 )
04197         {
04198         int y;
04199         char * row;
04200                 row = Bmp->Data[0];
04201                 row += (Bmp->Info.Height - 1) * myRowWidth;
04202                 for(y= Bmp->Info.Height;y--;)
04203                 {
04204                         if ( ! geVFile_Read(F, row, bmpRowWidth) )
04205                                 return GE_FALSE;                                
04206                         row -= myRowWidth;
04207                 }
04208         }
04209         else
04210         {
04211         int y;
04212         char * row;
04213                 row = Bmp->Data[0];
04214                 for(y= Bmp->Info.Height;y--;)
04215                 {
04216                         if ( ! geVFile_Read(F, row, bmpRowWidth) )
04217                                 return GE_FALSE;                                
04218                         row += myRowWidth;
04219                 }
04220         }
04221 
04222 return GE_TRUE;
04223 }       // end BMP reader

geBoolean geBitmap_ReadFromTGA geBitmap Bmp,
geVFile File
[static]
 

Definition at line 4263 of file bitmap.c.

References TGAHEADER::CMEntrySize, TGAHEADER::CMLength, count, geBitmap::Data, geBitmap_Palette::Data, geBitmap_Info::Format, GE_FALSE, GE_PIXELFORMAT_16BIT_555_RGB, GE_PIXELFORMAT_24BIT_BGR, GE_PIXELFORMAT_32BIT_ARGB, GE_PIXELFORMAT_32BIT_XRGB, GE_PIXELFORMAT_8BIT_GRAY, GE_PIXELFORMAT_8BIT_PAL, GE_TRUE, GE_VFILE_SEEKCUR, geBitmap_AllocSystemMip(), geBitmap_Create_Base(), geBitmap_Destroy(), geBitmap_Palette_Create(), geBitmap_SetAlpha(), geBitmap_SetPreferredFormat(), geBoolean, geVFile_Read(), geVFile_Seek(), geBitmap_Info::HasColorKey, TGAHEADER::Height, geBitmap_Info::Height, TGAHEADER::IDLength, TGAHEADER::ImageDescriptor, TGAHEADER::ImageType, geBitmap::Info, NULL, geBitmap_Info::Palette, TGAHEADER::PixelDepth, geBitmap_Info::Stride, TGAHEADER::Width, geBitmap_Info::Width, and y.

Referenced by geBitmap_CreateFromFile().

04264 {
04265         TGAHEADER tgah;
04266         int alphabits;
04267         int fliphoriz;
04268         int flipvert;
04269     int myRowWidth,bmpRowWidth,pelBytes;
04270         long ImageOffset = 0;
04271         geBitmap *AlphaBmp = NULL;
04272 
04273 
04274         //read the header fields 
04275         if(!geVFile_Read(File, &tgah, 18))
04276                 return GE_FALSE;
04277         
04278         Bmp->Info.Width = tgah.Width;
04279         Bmp->Info.Height = tgah.Height;
04280         Bmp->Info.Stride = ((tgah.Width+3)&(~3));
04281         Bmp->Info.HasColorKey = GE_FALSE;
04282 
04283         alphabits = tgah.ImageDescriptor & 0x0f;
04284         fliphoriz = (tgah.ImageDescriptor & 0x10) ? 0 : 1;
04285         flipvert = (tgah.ImageDescriptor & 0x20) ? 1 : 0;  
04286         //flipvert is ignored at the moment, because it appears rather rarely
04287         //+ you can flip textures in editors
04288 
04289         switch (tgah.PixelDepth) 
04290         {
04291                 case 8 :
04292                         pelBytes=1;
04293                         Bmp->Info.Format =