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

bitmap.__h File Reference

#include "bitmap.h"
#include "bitmap._h"

Go to the source code of this file.

Compounds

struct  geBitmap
struct  geBitmap_Palette

Defines

#define GEBM_VERSION_MAJOR   (0x0004)
#define GEBM_VERSION_MINOR   (0x0000)
#define MAXMIPLEVELS   (8)
#define PALETTE_FORMAT_DEFAULT   (GE_PIXELFORMAT_24BIT_RGB)
#define ALPHA_TO_TRANSPARENCY_THRESHOLD   (80)

Functions

geBoolean geBitmap_IsValid (const geBitmap *Bmp)
geBoolean geBitmap_Info_IsValid (const geBitmap_Info *Info)
geBoolean geBitmap_Palette_IsValid (const geBitmap_Palette *Pal)
geBoolean geBitmap_BlitMipRect (const geBitmap *Src, int SrcMip, int SrcX, int SrcY, geBitmap *Dst, int DstMip, int DstX, int DstY, int SizeX, int SizeY)
geBitmapgeBitmap_CreateLock_CopyInfo (geBitmap *BmpSrc, int LockCnt, int mip)
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 geBitmap_UnLock_NoChange (geBitmap *Bmp)
geBoolean geBitmap_UnLockArray_NoChange (geBitmap **Locks, int Size)
geBoolean geBitmap_Update_SystemToDriver (geBitmap *Bmp)
geBoolean geBitmap_Update_DriverToSystem (geBitmap *Bmp)
geBoolean geBitmap_MakeSystemMips (geBitmap *Bmp, int low, int high)
geBoolean geBitmap_UpdateMips_Data (geBitmap_Info *FmInfo, void *FmBits, geBitmap_Info *ToInfo, void *ToBits)
geBoolean geBitmap_UpdateMips_System (geBitmap *Bmp, int fm, int to)
geBoolean geBitmap_UsesColorKey (const geBitmap *Bmp)
void geBitmap_MakeMipInfo (geBitmap_Info *Src, int mip, geBitmap_Info *Into)
geBoolean geBitmap_MakeDriverLockInfo (geBitmap *Bmp, int mip, geBitmap_Info *Into)
geBoolean geBitmap_AllocSystemMip (geBitmap *Bmp, int mip)
geBoolean geBitmap_AllocPalette (geBitmap *Bmp, gePixelFormat Format, DRV_Driver *Driver)
geBoolean geBitmap_ReadInfo (geBitmap *Bmp, geVFile *F)
geBoolean geBitmap_WriteInfo (const geBitmap *Bmp, geVFile *F)
geBoolean geBitmap_FixDriverFlags (uint32 *pFlags)


Define Documentation

#define ALPHA_TO_TRANSPARENCY_THRESHOLD   (80)
 

Definition at line 43 of file bitmap.__h.

Referenced by BlitData_DePalettize(), BlitData_FromSeparateAlpha(), and BlitData_Raw().

#define GEBM_VERSION_MAJOR   (0x0004)
 

Definition at line 36 of file bitmap.__h.

#define GEBM_VERSION_MINOR   (0x0000)
 

Definition at line 37 of file bitmap.__h.

#define MAXMIPLEVELS   (8)
 

Definition at line 39 of file bitmap.__h.

Referenced by geBitmap_CreateLockFromMip(), geBitmap_CreateLockFromMipSystem(), geBitmap_Info_IsValid(), geBitmap_LockForRead(), geBitmap_LockForReadNative(), geBitmap_LockForWrite(), geBitmap_LockForWriteFormat(), geBitmap_MakeMipInfo(), geBitmap_MakeSystemMips(), geBitmap_RefreshMips(), geBitmap_Update_DriverToSystem(), geBitmap_Update_SystemToDriver(), geBitmap_UpdateMips(), and geBitmap_UpdateMips_System().

#define PALETTE_FORMAT_DEFAULT   (GE_PIXELFORMAT_24BIT_RGB)
 

Definition at line 41 of file bitmap.__h.

Referenced by geBitmap_BlitData_Sub().


Function Documentation

geBoolean geBitmap_AllocPalette geBitmap Bmp,
gePixelFormat  Format,
DRV_Driver Driver
 

Definition at line 327 of file bitmap.c.

References geBitmap_Palette::ColorKey, geBitmap_Info::ColorKey, geBitmap_Palette::ColorKeyIndex, geBitmap::DriverHandle, geBitmap_Palette::DriverHandle, geBitmap::DriverInfo, geBitmap_Info::Format, geBitmap_Palette::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_Info::HasColorKey, geBitmap_Palette::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 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 }

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 }

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 }

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_IsValid const geBitmap Bmp  ) 
 

Definition at line 5482 of file bitmap.c.

Referenced by geSprite_GetBackfaceBitmap(), and geSprite_GetBitmap().

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 }

geBoolean geBitmap_MakeDriverLockInfo geBitmap Bmp,
int  mip,
geBitmap_Info Into
 

Definition at line 2847 of file bitmap.c.

References geBitmap_Info::ColorKey, geRDriver_THandleInfo::ColorKey, geBitmap_Palette::ColorKeyIndex, geBitmap::Driver, geBitmap::DriverFlags, geBitmap::DriverHandle, geBitmap::DriverInfo, geBitmap::DriverMipLock, geRDriver_PixelFormat::Flags, geRDriver_THandleInfo::Flags, geBitmap_Info::Format, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_AddString, gePixelFormat_HasPalette(), geBitmap_Info::HasColorKey, geBitmap_Palette::HasColorKey, geBitmap_Info::Height, geRDriver_THandleInfo::Height, geBitmap_Info::MaximumMip, geBitmap_Info::MinimumMip, NULL, geBitmap_Info::Palette, geRDriver_THandleInfo::PixelFormat, geRDriver_PixelFormat::PixelFormat, RDRIVER_THANDLE_HAS_COLORKEY, geBitmap_Info::Stride, geRDriver_THandleInfo::Stride, DRV_Driver::THandle_GetInfo, geBitmap_Info::Width, and geRDriver_THandleInfo::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 Into
 

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 }

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 }

geBoolean geBitmap_ReadInfo geBitmap Bmp,
geVFile F
 

Definition at line 4538 of file bitmap.c.

References geBitmap::Alpha, geBitmap_Info::ColorKey, geBitmap_Info::Format, GE_FALSE, GE_TRUE, geBoolean, gePixelFormat_BytesPerPel(), gePixelFormat_GetPixel(), geVFile_Read(), geBitmap_Info::HasColorKey, geBitmap_Info::Height, geBitmap::Info, INFO_FLAG_HAS_ALPHA, INFO_FLAG_HAS_CK, INFO_FLAG_HAS_PAL, INFO_FLAG_IF_NOT_LOG2_ARE_BYTE, INFO_FLAG_WH_ARE_LOG2, geBitmap_Info::MaximumMip, geBitmap_Info::Palette, geBitmap::SeekMipCount, geBitmap_Info::Stride, uint16, uint8, and geBitmap_Info::Width.

Referenced by geBitmap_CreateFromFile().

04539 {
04540 uint8 data[4];
04541 uint8 flags;
04542 uint8 b;
04543 uint16 w;
04544 geBitmap_Info * pi;
04545 
04546         pi = &(Bmp->Info);
04547 
04548         if ( ! geVFile_Read(F,data,3) )
04549                 return GE_FALSE;
04550 
04551         flags = data[0];
04552 
04553         pi->Format = data[1]; // could go in 5 bits
04554 
04555         b = data[2];
04556 
04557         pi->MaximumMip = (b>>4)&0xF;
04558         Bmp->SeekMipCount = (b)&0xF;
04559 
04560         if ( flags & INFO_FLAG_HAS_PAL )
04561                 pi->Palette  = (geBitmap_Palette *)1;
04562         if ( flags & INFO_FLAG_HAS_ALPHA )
04563                 Bmp->Alpha = (geBitmap *)1;
04564 
04565         if ( flags & INFO_FLAG_WH_ARE_LOG2 )
04566         {
04567         int logw,logh;
04568 
04569                 if ( ! geVFile_Read(F,&b,1) )
04570                         return GE_FALSE;
04571 
04572                 logw = (b>>4)&0xF;
04573                 logh = (b   )&0xF;
04574 
04575                 pi->Width = 1<<logw;
04576                 pi->Height= 1<<logh;
04577         }
04578         else if ( flags & INFO_FLAG_IF_NOT_LOG2_ARE_BYTE )
04579         {
04580                 if ( ! geVFile_Read(F,&b,1) )
04581                         return GE_FALSE;
04582                 pi->Width = b;
04583                 if ( ! geVFile_Read(F,&b,1) )
04584                         return GE_FALSE;
04585                 pi->Height = b;
04586         }
04587         else
04588         {
04589                 if ( ! geVFile_Read(F,&w,2) )
04590                         return GE_FALSE;
04591                 pi->Width = w;
04592                 if ( ! geVFile_Read(F,&w,2) )
04593                         return GE_FALSE;
04594                 pi->Height = w;
04595         }
04596 
04597         if ( (flags & INFO_FLAG_HAS_CK) && gePixelFormat_BytesPerPel(pi->Format) > 0 )
04598         {
04599         uint8 * ptr;
04600                 pi->HasColorKey = GE_TRUE;
04601 
04602                 if ( ! geVFile_Read(F,data,gePixelFormat_BytesPerPel(pi->Format)) )
04603                         return GE_FALSE;
04604                 
04605                 ptr = data;
04606                 pi->ColorKey = gePixelFormat_GetPixel(pi->Format,&ptr);
04607         }
04608 
04609         pi->Stride = pi->Width;
04610 
04611         return GE_TRUE;
04612 }

geBoolean geBitmap_UnLock_NoChange geBitmap Bmp  ) 
 

Definition at line 807 of file bitmap.c.

References GE_FALSE, geBitmap_UnLock_Internal(), and geBoolean.

Referenced by geBitmap_UnLockArray_NoChange().

00808 {
00809 return geBitmap_UnLock_Internal(Bmp,GE_FALSE);
00810 }

geBoolean geBitmap_UnLockArray_NoChange geBitmap **  Locks,
int  Size
 

Definition at line 666 of file bitmap.c.

References GE_FALSE, GE_TRUE, geBitmap_UnLock_NoChange(), and geBoolean.

Referenced by geBitmap_Gamma_Apply(), and geBitmap_UpdateMips().

00667 {
00668 int i;
00669 geBoolean Ret = GE_TRUE;
00670         assert(Locks);
00671         for(i=0;i<Size;i++)
00672         {
00673                 if ( ! geBitmap_UnLock_NoChange(Locks[i]) )
00674                         Ret = GE_FALSE;
00675         }
00676 return Ret;
00677 }

geBoolean geBitmap_Update_DriverToSystem geBitmap Bmp  ) 
 

Definition at line 2162 of file bitmap.c.

References geBitmap::Data, geBitmap::DataOwner, geBitmap::DriverBitsLocked, geBitmap::DriverDataChanged, geBitmap::DriverHandle, geBitmap::DriverInfo, GE_FALSE, GE_TRUE, geBitmap_AllocSystemMip(), geBitmap_BlitData(), geBitmap_Gamma_Apply(), geBitmap_GetBits(), geBitmap_IsValid(), geBitmap_LockForReadNative(), geBitmap_MakeMipInfo(), geBitmap_Palette_Copy(), geBitmap_UnLock(), geBoolean, geErrorLog_AddString, geBitmap_Info::Height, geBitmap::Info, geBitmap::LockCount, geBitmap::LockOwner, Log_Puts, geBitmap_Info::MaximumMip, MAXMIPLEVELS, geBitmap_Info::MinimumMip, geBitmap::Modified, NULL, geBitmap_Info::Palette, and geBitmap_Info::Width.

Referenced by geBitmap_CreateLockFromMip(), geBitmap_DetachDriver(), geBitmap_GetAverageColor(), geBitmap_LockForWriteFormat(), geBitmap_SetAlpha(), geBitmap_SetColorKey(), geBitmap_SetGammaCorrection(), and geBitmap_WriteToFile().

02163 {
02164 geBitmap *DriverLocks[MAXMIPLEVELS];
02165 geBoolean Ret;
02166 int mip;
02167         
02168         assert( geBitmap_IsValid(Bmp) );
02169 
02170         if ( Bmp->LockOwner )
02171                 Bmp = Bmp->LockOwner;
02172 
02173         if ( Bmp->LockCount > 0 || Bmp->DataOwner )
02174         {
02175                 geErrorLog_AddString(-1,"Update_DriverToSystem : not an original bitmap", NULL);
02176                 return GE_FALSE;
02177         }
02178 
02179         if ( ! Bmp->DriverHandle )
02180         {
02181                 geErrorLog_AddString(-1,"Update_DriverToSystem : no driver data", NULL);
02182                 return GE_FALSE;
02183         }
02184 
02185         if ( ! Bmp->DriverDataChanged )
02186                 return GE_TRUE;
02187 
02188         // bits are on driver; undo the gamma to copy them home
02189 
02190         Log_Puts("Bitmap : Doing Update_DriverToSystem");
02191 
02192         if ( ! geBitmap_Gamma_Apply(Bmp,GE_TRUE) ) // undo the gamma!
02193                 return GE_FALSE;
02194 
02195         if ( Bmp->Info.Palette && Bmp->DriverInfo.Palette )
02196         {
02197                 if ( ! geBitmap_Palette_Copy(Bmp->DriverInfo.Palette,Bmp->Info.Palette) )
02198                 {
02199                         geErrorLog_AddString(-1,"Update_DriverToSystem : Palette_Copy", NULL);
02200                 }
02201         }
02202 
02203         if ( geBitmap_LockForReadNative(Bmp,DriverLocks,
02204                         Bmp->DriverInfo.MinimumMip,Bmp->DriverInfo.MaximumMip) )
02205         {
02206                 Ret = GE_TRUE;
02207 
02208                 for(mip=Bmp->DriverInfo.MinimumMip;mip <=Bmp->DriverInfo.MaximumMip;mip++)
02209                 {       
02210                 geBitmap *MipBmp;
02211                 geBitmap_Info SystemInfo;
02212 
02213                         MipBmp = DriverLocks[mip];
02214 
02215                         if ( Bmp->Modified[mip] )
02216                         {
02217                         void *DriverBits,*SystemBits;
02218                                 DriverBits = geBitmap_GetBits(MipBmp);
02219                                 assert( MipBmp->DriverBitsLocked );
02220 
02221                                 if ( ! geBitmap_AllocSystemMip(Bmp,mip) )
02222                                         Ret = GE_FALSE;
02223 
02224                                 SystemBits = Bmp->Data[mip];
02225 
02226                                 geBitmap_MakeMipInfo(&(Bmp->Info),mip,&SystemInfo);
02227 
02228                                 if ( DriverBits && SystemBits )
02229                                 {
02230                                         // _Update_DriverToSystem
02231                                         // {} palette (not) made in AttachToDriver; must be made in here->
02232                                         if ( ! geBitmap_BlitData(       &(MipBmp->Info), DriverBits, MipBmp,
02233                                                                                                 &SystemInfo,    SystemBits, Bmp,
02234                                                                                                 SystemInfo.Width,SystemInfo.Height) )
02235                                                 Ret = GE_FALSE;
02236                                 }
02237                                 else
02238                                 {
02239                                         Ret = GE_FALSE;
02240                                 }
02241                         }
02242                         
02243                         geBitmap_UnLock(DriverLocks[mip]);
02244                 }
02245 
02246                 Bmp->DriverDataChanged = GE_FALSE;
02247         }
02248         else
02249         {
02250                 Ret = GE_FALSE;
02251         }
02252 
02253         if ( ! Ret )
02254         {
02255                 geErrorLog_AddString(-1,"Update_DriverToSystem : Locking and Blitting error", NULL);
02256         }
02257 
02258         if ( ! geBitmap_Gamma_Apply(Bmp,GE_FALSE) ) // redo the gamma!
02259                 return GE_FALSE;
02260 
02261 return Ret;
02262 }

geBoolean geBitmap_Update_SystemToDriver geBitmap Bmp  ) 
 

this function is totally hacked out, because what we really need to do is lock Bmp for Read (system) & Write (driver) , but that's illegal!

Bmp is a driver BMP

the SrcLocks are locks of the system bits.

Definition at line 1930 of file bitmap.c.

References geBitmap::Alpha, geBitmap::Data, geBitmap::DataOwner, geBitmap::Driver, geBitmap::DriverBitsLocked, geBitmap::DriverDataChanged, geBitmap::DriverFlags, geBitmap::DriverHandle, geBitmap::DriverInfo, geBitmap::DriverMipLock, DstInfo, geBitmap_Info::Format, GE_FALSE, GE_TRUE, geBitmap_AttachToDriver(), geBitmap_BlitData(), geBitmap_DetachDriver(), geBitmap_Gamma_Apply(), geBitmap_GetBits(), geBitmap_IsValid(), geBitmap_LockForReadNative(), geBitmap_MakeDriverLockInfo(), geBitmap_Palette_Destroy(), geBitmap_SetPalette(), geBitmap_UnLockArray(), geBitmap_UpdateMips(), geBoolean, geErrorLog_AddString, gePixelFormat_HasGoodAlpha(), geBitmap_Info::Height, geBitmap::Info, geBitmap::LockCount, geBitmap::LockOwner, geBitmap_Info::MaximumMip, MAXMIPLEVELS, geBitmap_Info::MinimumMip, geBitmap::Modified, NULL, geBitmap_Info::Palette, RDRIVER_PF_ALPHA, RDRIVER_PF_HAS_ALPHA, DRV_Driver::THandle_GetAlpha, DRV_Driver::THandle_Lock, DRV_Driver::THandle_SetAlpha, DRV_Driver::THandle_UnLock, and geBitmap_Info::Width.

Referenced by geBitmap_AttachToDriver(), geBitmap_SetAlpha(), geBitmap_SetColorKey(), geBitmap_SetGammaCorrection(), geBitmap_SetPalette(), and geBitmap_UnLock_Internal().

01931 {
01932 geBitmap * SrcLocks[MAXMIPLEVELS];
01933 geBoolean Ret,MipsChanged;
01934 int mip,mipMin,mipMax;
01935 geRDriver_THandle * SaveDriverHandle;
01936 geBitmap * SaveAlpha;
01937 int SaveMaxMip;
01938         
01939         assert( geBitmap_IsValid(Bmp) );
01940 
01947 
01948         if ( Bmp->LockOwner )
01949                 Bmp = Bmp->LockOwner;
01950 
01951         if ( Bmp->LockCount > 0 || Bmp->DataOwner )
01952         {
01953                 geErrorLog_AddString(-1,"Update_SystemToDriver : not an original bitmap", NULL);
01954                 return GE_FALSE;
01955         }
01956 
01957         if ( ! Bmp->DriverHandle )
01958         {
01959                 geErrorLog_AddString(-1,"Update_SystemToDriver : no driver data", NULL);
01960                 return GE_FALSE;
01961         }
01962 
01963         MipsChanged = GE_FALSE;
01964         for(mip=Bmp->DriverInfo.MinimumMip;mip<=Bmp->DriverInfo.MaximumMip;mip++)
01965         {
01966                 if ( Bmp->Modified[mip] && mip != Bmp->Info.MinimumMip )
01967                 {
01968                         assert(Bmp->Data[mip]);
01969                         MipsChanged = GE_TRUE;
01970                 }
01971         }
01972 
01973         //make mips after driver blit
01974         
01975 #if 0 
01976         MipsChanged = GE_TRUE;
01977 #endif
01978 
01979         mipMin = Bmp->DriverInfo.MinimumMip;
01980 
01981         if ( MipsChanged )
01982                 mipMax = Bmp->DriverInfo.MaximumMip;
01983         else
01984                 mipMax = mipMin;
01985 
01986 
01987         SaveDriverHandle = Bmp->DriverHandle;
01988         Bmp->DriverHandle = NULL;       // so Lock() won't use the driver data
01989 
01990         SaveAlpha = Bmp->Alpha;
01991 
01992         if ( Bmp->Alpha && ! gePixelFormat_HasGoodAlpha(Bmp->DriverInfo.Format) && 
01993                         (Bmp->DriverFlags & RDRIVER_PF_HAS_ALPHA) )
01994         {
01995                 // hide the alpha so that it won't be used to make a colorkey in the target
01996                 // we'll blit it independently later
01997                 Bmp->Alpha = NULL;
01998         }
01999 
02000         if ( ! geBitmap_LockForReadNative(Bmp,SrcLocks,mipMin,mipMax) )
02001         {
02002                 geErrorLog_AddString(-1,"Update_SystemToDriver : LockForReadNative", NULL);
02003                 return GE_FALSE;
02004         }
02005 
02006         Ret = GE_TRUE;
02007         Bmp->DriverHandle = SaveDriverHandle;
02008         Bmp->Alpha = NULL;
02009 
02010         // we should have always updated the driver to system before fiddling the system
02011         assert( ! Bmp->DriverDataChanged );
02012 
02020 
02021         for(mip=mipMin;mip <=mipMax;mip++)
02022         {
02023         geBitmap *SrcMip;
02024         void * SrcBits,*DstBits;
02025         geBitmap_Info DstInfo;
02026 
02027                 SrcMip = SrcLocks[mip - mipMin];
02028                 SrcBits = geBitmap_GetBits(SrcMip);
02029 
02030                 DstInfo = Bmp->DriverInfo;
02031 
02032                 if ( ! geBitmap_MakeDriverLockInfo(Bmp,mip,&DstInfo) )
02033                 {
02034                         geErrorLog_AddString(-1,"Update_SystemToDriver : MakeInfo", NULL);
02035                         Ret = GE_FALSE;
02036                         continue;
02037                 }
02038 
02039                 // Zooma! THandle_Lock might lock the Win16 Lock !
02040                 //      this is really bad when _BlitData is a wavelet decompress !
02041                 // {} try this : decompress to a buffer in memory (on a thread)
02042                 //      then THandle_Lock and just do a (prefetching) memcpy
02043                 //#pragma message("Bitmap : minimize time spent in a THandle_Lock!")
02044 
02045                 if ( ! Bmp->Driver->THandle_Lock(SaveDriverHandle,mip,&DstBits) )
02046                 {
02047                         geErrorLog_AddString(-1,"Update_SystemToDriver : THandle_Lock", NULL);
02048                         Ret = GE_FALSE;
02049                         continue;
02050                 }
02051 
02052                 if ( ! SrcBits || ! DstBits )
02053                 {
02054                         geErrorLog_AddString(-1,"Update_SystemToDriver : No Bits", NULL);
02055                         Ret = GE_FALSE;
02056                         continue;
02057                 }
02058 
02059                 assert( DstInfo.Palette == Bmp->DriverInfo.Palette );
02060 
02061                 if ( ! geBitmap_BlitData(       &(SrcMip->Info),SrcBits,SrcMip,
02062                                                                         &DstInfo,               DstBits,Bmp,
02063                                                                         SrcMip->Info.Width,SrcMip->Info.Height) )
02064                 {
02065                         geErrorLog_AddString(-1,"Update_SystemToDriver : BlitData", NULL);
02066                         //assert(0);
02067                         Ret = GE_FALSE;
02068                         continue;
02069                 }
02070 
02071                 if ( ! Bmp->Driver->THandle_UnLock(SaveDriverHandle,mip) )
02072                 {
02073                         geErrorLog_AddString(-1,"Update_SystemToDriver : THandle_UnLock", NULL);
02074                         Ret = GE_FALSE;
02075                         continue;
02076                 }
02077 
02078                 // normally this would be done by the Bitmap_UnLock ,
02079                 //  but since we don't lock ..
02080                 if ( DstInfo.Palette != Bmp->DriverInfo.Palette )
02081                 {
02082                         //assert( OldDstPal == NULL );
02083                         geBitmap_SetPalette(Bmp,DstInfo.Palette);
02084                         geBitmap_Palette_Destroy(&(DstInfo.Palette));
02085                         // must destroy here, since DstInfo is on the stack!
02086                 }
02087         }
02088 
02089         Bmp->Alpha = SaveAlpha;
02090         Bmp->DriverBitsLocked = GE_FALSE;
02091         Bmp->DriverMipLock = 0;
02092         Bmp->DriverDataChanged = GE_FALSE;
02093 
02094         geBitmap_UnLockArray(SrcLocks, mipMax - mipMin + 1 );
02095 
02096         if ( ! Ret )
02097         {
02098                 geErrorLog_AddString(-1,"Update_SystemToDriver : Locking and Blitting error", NULL);
02099         }
02100 
02101         if ( Bmp->Alpha && ! gePixelFormat_HasGoodAlpha(Bmp->DriverInfo.Format) && 
02102                         (Bmp->DriverFlags & RDRIVER_PF_HAS_ALPHA) )
02103         {
02104         geRDriver_THandle * AlphaTH;
02105 
02106                 // blit the alpha surface to the separate alpha
02107 
02108                 AlphaTH = Bmp->Driver->THandle_GetAlpha(Bmp->DriverHandle);
02109                 if ( !AlphaTH || AlphaTH != Bmp->Alpha->DriverHandle)
02110                 {
02111                         if ( ! geBitmap_AttachToDriver(Bmp->Alpha,Bmp->Driver,Bmp->Alpha->DriverFlags | RDRIVER_PF_ALPHA) )
02112                         {
02113                                 geErrorLog_AddString(-1,"AttachToDriver : attach Alpha", NULL);
02114                                 return GE_FALSE;
02115                         }
02116 
02117                         assert(Bmp->Alpha->DriverHandle);
02118                         if ( ! Bmp->Driver->THandle_SetAlpha(Bmp->DriverHandle,Bmp->Alpha->DriverHandle) )
02119                         {
02120                                 geErrorLog_AddString(-1,"AttachToDriver : THandle_SetAlpha", NULL);
02121                                 geBitmap_DetachDriver(Bmp->Alpha,GE_FALSE);
02122                                 geBitmap_DetachDriver(Bmp,GE_FALSE);
02123                                 return GE_FALSE;
02124                         }
02125                         
02126                         AlphaTH = Bmp->Driver->THandle_GetAlpha(Bmp->DriverHandle);
02127                         assert(AlphaTH == Bmp->Alpha->DriverHandle);
02128                 }
02129         }
02130 
02131         // now bits are on driver , gamma correct them
02132 
02133         //for gamma : just Gamma up to mipMax then make mips from it
02134         //      seems to work
02135 
02136         SaveMaxMip = Bmp->DriverInfo.MaximumMip;
02137         Bmp->DriverInfo.MaximumMip = mipMax;
02138         if ( ! geBitmap_Gamma_Apply(Bmp,GE_FALSE) )
02139         {
02140                 geErrorLog_AddString(-1,"AttachToDriver : Gamma_Apply failed!", NULL);
02141                 Ret = GE_FALSE;
02142         }
02143         Bmp->DriverInfo.MaximumMip = SaveMaxMip;
02144 
02145         if ( ! MipsChanged && mipMax < Bmp->DriverInfo.MaximumMip )
02146         {
02147                 for(mip=mipMax+1;mip<= Bmp->DriverInfo.MaximumMip; mip++)
02148                 {
02149                         if ( ! geBitmap_UpdateMips(Bmp,mip-1,mip) )
02150                         {
02151                                 geErrorLog_AddString(-1,"AttachToDriver : UpdateMips on driver failed!", NULL);
02152                                 return GE_FALSE;
02153                         }
02154                 }
02155         }
02156 
02157         Bmp->DriverDataChanged = GE_FALSE; // in case _SetPal freaks us out
02158 
02159 return Ret;
02160 }

geBoolean geBitmap_UpdateMips_Data geBitmap_Info FmInfo,
void *  FmBits,
geBitmap_Info ToInfo,
void *  ToBits
 

Definition at line 2402 of file bitmap.c.

References B, B1, B2, closestPal(), closestPalFree(), closestPalInit(), geBitmap_Info::ColorKey, gePixelFormat_Operations::DecomposePixel, geBitmap_Info::Format, G, G1, G2, GE_FALSE, GE_PIXELFORMAT_24BIT_RGB, GE_TRUE, geBitmap_Palette_GetData(), geBoolean, geErrorLog_AddString, gePixelFormat_BytesPerPel(), gePixelFormat_ColorGetter, gePixelFormat_ColorPutter, gePixelFormat_Decomposer, gePixelFormat_GetOperations(), gePixelFormat_HasPalette(), gePixelFormat_PixelGetter, gePixelFormat_PixelPutter, gePixelFormat_Operations::GetColor, gePixelFormat_Operations::GetPixel, geBitmap_Info::HasColorKey, geBitmap_Info::Height, int32, NULL, geBitmap_Info::Palette, gePixelFormat_Operations::PutColor, gePixelFormat_Operations::PutPixel, R, R1, R2, geBitmap_Info::Stride, uint16, uint32, uint8, geBitmap_Info::Width, and y.

Referenced by geBitmap_UpdateMips(), and geBitmap_UpdateMips_System().

02404 {
02405 int fmxtra,tow,toh,toxtra,fmw,fmh,fmstep,x,y,bpp;
02406 
02407         assert( FmInfo && ToInfo && FmBits && ToBits );
02408         assert( FmInfo->Format == ToInfo->Format && FmInfo->HasColorKey == ToInfo->HasColorKey );
02409 
02410         tow = ToInfo->Width;
02411         toh = ToInfo->Height;
02412         toxtra = ToInfo->Stride - ToInfo->Width;
02413         
02414         x = ToInfo->Width;
02415         fmstep = 1;
02416         while( x < FmInfo->Width )
02417         {
02418                 fmstep += fmstep;
02419                 x += x;
02420         }
02421 
02422         fmw = FmInfo->Width;
02423         fmh = FmInfo->Height;
02424         fmxtra = (FmInfo->Stride - tow) * fmstep; // amazingly simple and correct! think about it!
02425 
02426         // fmh == 15
02427         // toh == 8
02428         // fmstep == 2
02429         // 7*2 <= 14 -> Ok
02430         if ( (toh-1)*fmstep > (fmh - 1) )
02431         {
02432                 geErrorLog_AddString(-1,"UpdateMips_Data : Vertical mip scaling doesn't match horizontal!", NULL);
02433                 return GE_FALSE;
02434         }
02435 
02436         // {} todo : average for some special cases (16rgb,24rgb,32rgb)
02437 
02438         bpp = gePixelFormat_BytesPerPel(FmInfo->Format);
02439 
02440         if ( fmstep == 2 && bpp > 1 )
02441         {
02442         int R1,G1,B1,A1,R2,G2,B2,A2,R3,G3,B3,A3,R4,G4,B4,A4;
02443         gePixelFormat_ColorGetter GetColor;
02444         gePixelFormat_ColorPutter PutColor;
02445         const gePixelFormat_Operations *ops;
02446         uint8 *fmp,*fmp2,*top;
02447 
02448                 fmp = FmBits;
02449                 top = ToBits;
02450 
02451                 ops = gePixelFormat_GetOperations(FmInfo->Format);
02452                 GetColor = ops->GetColor;
02453                 PutColor = ops->PutColor;
02454 
02455                 fmxtra *= bpp;
02456                 toxtra *= bpp;
02457 
02458                 if ( FmInfo->HasColorKey )
02459                 {
02460                 uint32 ck,p1,p2,p3,p4;
02461                 gePixelFormat_PixelGetter GetPixel;
02462                 gePixelFormat_PixelPutter PutPixel;
02463                 gePixelFormat_Decomposer DecomposePixel;
02464                 int32 PixelComposeRTable[]={0x696C6345,0x21657370};
02465 
02466                         assert( FmInfo->ColorKey == ToInfo->ColorKey );
02467                         ck = FmInfo->ColorKey;
02468                         GetPixel = ops->GetPixel;
02469                         PutPixel = ops->PutPixel;
02470                         DecomposePixel = ops->DecomposePixel;
02471                 
02472                         // {} the colorkey mip-subsampler
02473                         // slow; yet another reason to not use CK !
02474                         
02475                         for(y=toh;y--;)
02476                         {
02477                                 //y = 7, fmh = 15; y*2+1 == fmh : last line is not a double line
02478                                 if ( (y+y + 1) == fmh ) fmp2 = fmp;
02479                                 else                                    fmp2 = fmp + (FmInfo->Stride*bpp);
02480                                 for(x=tow;x--;)
02481                                 {
02482                                         p1 = GetPixel(&fmp);
02483                                         p2 = GetPixel(&fmp);
02484                                         p3 = GetPixel(&fmp2);
02485                                         p4 = GetPixel(&fmp2);
02486                                         if ( p1 == ck || p4 == ck )
02487                                         {
02488                                                 PutPixel(&top,ck);
02489                                         }
02490                                         else
02491                                         {
02492                                                 // p1 and p4 are not ck;
02493                                                 if ( p2 == ck ) p2 = p1;
02494                                                 if ( p3 == ck ) p3 = p4;
02495                                                 DecomposePixel(p1,&R1,&G1,&B1,&A1);
02496                                                 DecomposePixel(p2,&R2,&G2,&B2,&A2);
02497                                                 DecomposePixel(p3,&R3,&G3,&B3,&A3);
02498                                                 DecomposePixel(p4,&R4,&G4,&B4,&A4);
02499                                                 PutColor(&top,(R1+R2+R3+R4+2)>>2,(G1+G2+G3+G4+2)>>2,(B1+B2+B3+B4+2)>>2,(A1+A2+A3+A4+2)>>2);
02500                                         }
02501                                 }
02502                                 fmp += fmxtra;
02503                                 top += toxtra;
02504                         }
02505                 }
02506                 else
02507                 {
02508                         for(y=toh;y--;)
02509                         {
02510                                 //y = 7, fmh = 15; y*2+1 == fmh : last line is not a double line
02511                                 if ( (y+y + 1) == fmh ) fmp2 = fmp;
02512                                 else                                    fmp2 = fmp + (FmInfo->Stride*bpp);
02513                                 for(x=tow;x--;)
02514                                 {
02515                                         GetColor(&fmp ,&R1,&G1,&B1,&A1);
02516                                         GetColor(&fmp ,&R2,&G2,&B2,&A2);
02517                                         GetColor(&fmp2,&R3,&G3,&B3,&A3);
02518                                         GetColor(&fmp2,&R4,&G4,&B4,&A4);
02519                                         PutColor(&top,(R1+R2+R3+R4+2)>>2,(G1+G2+G3+G4+2)>>2,(B1+B2+B3+B4+2)>>2,(A1+A2+A3+A4+2)>>2);
02520                                 }
02521                                 fmp += fmxtra;
02522                                 top += toxtra;
02523                         }
02524                 }
02525 
02526                 assert( top == (((uint8 *)ToBits) + ToInfo->Stride * ToInfo->Height * bpp ) );
02527                 assert( fmp == (((uint8 *)FmBits) + FmInfo->Stride * ToInfo->Height * 2 * bpp ) );
02528         }
02529         else if ( fmstep == 2 && gePixelFormat_HasPalette(FmInfo->Format) )
02530         {
02531         int R,G,B;
02532         uint8 *fmp,*fmp2,*top;
02533         uint8 paldata[768],*palptr;
02534         int p;
02535         palInfo * PalInfo;
02536 
02537                 assert(bpp == 1);
02538                 assert(FmInfo->Palette);
02539 
02540                 if ( ! geBitmap_Palette_GetData(FmInfo->Palette,paldata,GE_PIXELFORMAT_24BIT_RGB,256) )
02541                         return GE_FALSE;
02542 
02543                 if ( ! (PalInfo = closestPalInit(paldata)) )
02544                         return GE_FALSE;
02545 
02546                 fmp = FmBits;
02547                 top = ToBits;
02548 
02549                 // @@ colorkey?
02550 
02551                 for(y=toh;y--;)
02552                 {
02553                         //y = 7, fmh = 15; y*2+1 == fmh : last line is not a double line
02554                         if ( (y*2 + 1) == fmh ) fmp2 = fmp;
02555                         else                                    fmp2 = fmp + (FmInfo->Stride*bpp);
02556 
02557                         for(x=tow;x--;)
02558                         {
02559                                 p = *fmp++;
02560                                 palptr = paldata + p*3;
02561                                 R  = palptr[0]; G  = palptr[1]; B  = palptr[2]; 
02562                                 p = *fmp++;
02563                                 palptr = paldata + p*3;
02564                                 R += palptr[0]; G += palptr[1]; B += palptr[2]; 
02565                                 p = *fmp2++;
02566                                 palptr = paldata + p*3;
02567                                 R += palptr[0]; G += palptr[1]; B += palptr[2]; 
02568                                 p = *fmp2++;
02569                                 palptr = paldata + p*3;
02570                                 R += palptr[0]; G += palptr[1]; B += palptr[2]; 
02571 
02572                                 R = (R+2)>>2;
02573                                 G = (G+2)>>2;
02574                                 B = (B+2)>>2;
02575 
02576                                 p = closestPal(R,G,B,PalInfo);
02577                                 *top++ = p;
02578                         }
02579                         fmp += fmxtra;
02580                         top += toxtra;
02581                 }
02582 
02583                 closestPalFree(PalInfo);
02584 
02585                 assert( top == (((uint8 *)ToBits) + ToInfo->Stride * ToInfo->Height * bpp ) );
02586                 assert( fmp == (((uint8 *)FmBits) + FmInfo->Stride * ToInfo->Height * 2 * bpp ) );
02587         }
02588         else
02589         {
02590                 // we just sub-sample to make mips, so we don't have to
02591                 //      know anything about pixelformat.
02592                 // (btw this spoils the whole point of mips, so we might as well kill the mip!)
02593 
02594                 //{} Blend correctly !?
02595 
02596                 switch( bpp )
02597                 {
02598                         default:
02599                         {
02600                                 return GE_FALSE;
02601                         }
02602                         case 1:
02603                         {
02604                                 uint8 *fmp,*top;
02605                                 fmp = FmBits;
02606                                 top = ToBits;
02607                                 for(y=toh;y--;)
02608                                 {
02609                                         for(x=tow;x--;)
02610                                         {
02611                                                 *top++ = *fmp;
02612                                                 fmp += fmstep;
02613                                         }
02614                                         fmp += fmxtra;
02615                                         top += toxtra;
02616                                 }
02617                                 break;
02618                         }
02619                         case 2:
02620                         {
02621                                 uint16 *fmp,*top;
02622                                 fmp = FmBits;
02623                                 top = ToBits;
02624                                 for(y=toh;y--;)
02625                                 {
02626                                         for(x=tow;x--;)
02627                                         {
02628                                                 *top++ = *fmp;
02629                                                 fmp += fmstep;
02630                                         }
02631                                         fmp += fmxtra;
02632                                         top += toxtra;
02633                                 }
02634                                 break;
02635                         }
02636                         case 4:
02637                         {
02638                                 uint32 *fmp,*top;
02639                                 fmp = FmBits;
02640                                 top = ToBits;
02641                                 for(y=toh;y--;)
02642                                 {
02643                                         for(x=tow;x--;)
02644                                         {
02645                                                 *top++ = *fmp;
02646                                                 fmp += fmstep;
02647                                         }
02648                                         fmp += fmxtra;
02649                                         top += toxtra;
02650                                 }
02651                                 break;
02652                         }
02653                         case 3:
02654                         {
02655                                 uint8 *fmp,*top;
02656                                 fmp = FmBits;
02657                                 top = ToBits;
02658                                 fmstep = (fmstep - 1) * 3;
02659                                 fmxtra *= 3;
02660                                 toxtra *= 3;
02661                                 for(y=toh;y--;)
02662                                 {
02663                                         for(x=tow;x--;)
02664                                         {
02665                                                 *top++ = *fmp++;
02666                                                 *top++ = *fmp++;
02667                                                 *top++ = *fmp++;
02668                                                 fmp += fmstep;
02669                                         }
02670                                         fmp += fmxtra;
02671                                         top += toxtra;
02672                                 }
02673                                 break;
02674                         }
02675                 }
02676         }
02677 
02678 return GE_TRUE;
02679 }

geBoolean geBitmap_UpdateMips_System geBitmap Bmp,
int  fm,
int  to
 

Definition at line 2346 of file bitmap.c.

References geBitmap::Data, geBitmap::DataOwner, geBitmap_Info::Format, GE_FALSE, GE_TRUE, geBitmap_AllocSystemMip(), geBitmap_IsValid(), geBitmap_UpdateMips_Data(), geBoolean, gePixelFormat_BytesPerPel(), geBitmap_Info::Height, geBitmap::Info, geBitmap::LockOwner, max, geBitmap_Info::MaximumMip, MAXMIPLEVELS, geBitmap_Info::MinimumMip, NULL, SHIFT_R_ROUNDUP, geBitmap_Info::Stride, and geBitmap_Info::Width.

Referenced by geBitmap_MakeSystemMips(), and geBitmap_UpdateMips().

02347 {
02348 geBitmap_Info FmInfo,ToInfo;
02349 geBoolean Ret;
02350 
02351         assert( geBitmap_IsValid(Bmp) );
02352 
02353         // this is called to create new mips in LockFor* -> CreateLockFrom* (through MakeSystemMips)
02354 
02355         if ( Bmp->LockOwner )
02356                 Bmp = Bmp->LockOwner;
02357 //      if ( Bmp->LockCount > 0 )
02358 //              return GE_FALSE;
02359         if ( Bmp->DataOwner )
02360                 return GE_FALSE;
02361 
02362         // {} for compressed data, just don't make mips and say we did!
02363         if ( gePixelFormat_BytesPerPel(Bmp->Info.Format) < 1 )
02364                 return GE_TRUE;
02365 
02366         while(Bmp->Data[fm] == NULL || fm == to )
02367         {
02368                 fm--;
02369                 if ( fm < 0 )
02370                         return GE_FALSE;
02371         }
02372 
02373         if ( fm < Bmp->Info.MinimumMip || fm > Bmp->Info.MaximumMip ||
02374              to < fm || to >= MAXMIPLEVELS )
02375                 return GE_FALSE;
02376 
02377         if ( ! Bmp->Data[to] )
02378         {
02379                 if ( ! geBitmap_AllocSystemMip(Bmp,to) )
02380                         return GE_FALSE;
02381         }
02382 
02383         assert( to > fm && fm >= 0 );
02384 
02385         FmInfo = ToInfo = Bmp->Info;
02386 
02387         FmInfo.Width = SHIFT_R_ROUNDUP(Bmp->Info.Width ,fm);
02388         FmInfo.Height= SHIFT_R_ROUNDUP(Bmp->Info.Height,fm);
02389         FmInfo.Stride= SHIFT_R_ROUNDUP(Bmp->Info.Stride,fm);
02390         ToInfo.Width = SHIFT_R_ROUNDUP(Bmp->Info.Width ,to);
02391         ToInfo.Height= SHIFT_R_ROUNDUP(Bmp->Info.Height,to);
02392         ToInfo.Stride= SHIFT_R_ROUNDUP(Bmp->Info.Stride,to);
02393 
02394         Ret = geBitmap_UpdateMips_Data( &FmInfo, Bmp->Data[fm],
02395                                                                         &ToInfo, Bmp->Data[to]);
02396 
02397         Bmp->Info.MaximumMip = max(Bmp->Info.MaximumMip,to);
02398 
02399 return Ret;
02400 }

geBoolean geBitmap_UsesColorKey const geBitmap Bmp  ) 
 

Definition at line 3370 of file bitmap.c.

References gePixelFormat_Operations::BytesPerPel, geBitmap_Info::ColorKey, geBitmap::Data, geBitmap_Info::Format, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_AddString, gePixelFormat_GetOperations(), geBitmap_Info::HasColorKey, geBitmap_Info::Height, geBitmap::Info, geBitmap_Info::MinimumMip, NULL, s, geBitmap_Info::Stride, uint16, uint32, uint8, geBitmap_Info::Width, and y.

Referenced by geBitmap_SetColorKey().

03371 {
03372 void * Bits;
03373 const gePixelFormat_Operations * ops;
03374 int x,y,w,h,s;
03375 uint32 pel,ColorKey;
03376 
03377         if ( ! Bmp->Info.HasColorKey )
03378                 return GE_FALSE;
03379 
03380         if ( ! Bmp->Data[0] )
03381         {
03382                 geErrorLog_AddString(-1,"UsesColorKey : no data!", NULL);
03383                 return GE_TRUE;
03384         }
03385 
03386         assert( Bmp->Info.MinimumMip == 0 );
03387 
03388         Bits = Bmp->Data[0];
03389         ops = gePixelFormat_GetOperations(Bmp->Info.Format);
03390         assert(ops);
03391 
03392         w = Bmp->Info.Width;
03393         h = Bmp->Info.Height;
03394         s = Bmp->Info.Stride;
03395 
03396         ColorKey = Bmp->Info.ColorKey;
03397 
03398         switch(ops->BytesPerPel)
03399         {
03400                 case 0:
03401                         geErrorLog_AddString(-1,"UsesColorKey : invalid format", NULL);
03402                         return GE_TRUE;
03403 //Start Dec2001DCS - Added new case 3 below
03404 //              case 3:
03405 //                      #pragma message("Bitmap : UsesColorKey : no 24bit Smart ColorKey")
03406 //                      geErrorLog_AddString(-1,"UsesColorKey : no 24bit Smart ColorKey", NULL);
03407 //                      return GE_TRUE; 
03408 //End Dec2001DCS
03409                 case 1:
03410                 {
03411                 uint8 * ptr;
03412                         ptr = Bits;
03413                         for(y=h;y--;)
03414                         {
03415                                 for(x=w;x--;)
03416                                 {
03417                                         pel = *ptr++;
03418                                         if ( pel == ColorKey )
03419                                         {
03420                                                 return GE_TRUE; 
03421                                         }
03422                                 }
03423                                 ptr += (s-w);
03424                         }
03425                         break;
03426                 }
03427                 case 2:
03428                 {
03429                 uint16 * ptr;
03430                         ptr = Bits;
03431                         for(y=h;y--;)
03432                         {
03433                                 for(x=w;x--;)
03434                                 {
03435                                         pel = *ptr++;
03436                                         if ( pel == ColorKey )
03437                                         {
03438                                                 return GE_TRUE; 
03439                                         }
03440                                 }
03441                                 ptr += (s-w);
03442                         }
03443                         break;
03444                 }
03445 //Start Dec2001DCS - Added new case 3 
03446                 case 3:
03447                 {
03448                 uint8 * ptr;
03449          uint8   ckR, ckG, ckB;
03450 
03451          ckB = (uint8) (ColorKey & 0x000000ff);
03452          ckG = (uint8) ((ColorKey >> 8) & 0x000000ff);
03453          ckR = (uint8) ((ColorKey >> 16) & 0x000000ff);
03454                         ptr = Bits;
03455                         for(y=h;y--;)
03456                         {
03457                                 for(x=w;x--;)
03458                                 {
03459                                         if ((*ptr == ckR) && (*(ptr+1) == ckG) && (*(ptr+2) == ckB))
03460                                         {
03461                                                 return GE_TRUE; 
03462                                         }
03463                ptr += 3;
03464                                 }
03465                                 ptr += ((s-w)*3);
03466                         }
03467                         break;
03468                 }
03469 //End Dec2001DCS
03470                 case 4:
03471                 {
03472                 uint32 * ptr;
03473                         ptr = Bits;
03474                         for(y=h;y--;)
03475                         {
03476                                 for(x=w;x--;)
03477                                 {
03478                                         pel = *ptr++;
03479                                         if ( pel == ColorKey )
03480                                         {
03481                                                 return GE_TRUE; 
03482                                         }
03483                                 }
03484                                 ptr += (s-w);
03485                         }
03486                         break;
03487                 }
03488         }
03489 return GE_FALSE;
03490 }

geBoolean geBitmap_WriteInfo const geBitmap Bmp,
geVFile F
 

Definition at line 4614 of file bitmap.c.

References geBitmap::Alpha, geBitmap_Info::ColorKey, geBitmap_Info::Format, GE_FALSE, GE_TRUE, geBoolean, gePixelFormat_BytesPerPel(), gePixelFormat_IsValid(), gePixelFormat_PutPixel(), geVFile_Write(), geBitmap_Info::HasColorKey, geBitmap_Info::Height, geBitmap::Info, INFO_FLAG_HAS_ALPHA, INFO_FLAG_HAS_CK, INFO_FLAG_HAS_PAL, INFO_FLAG_IF_NOT_LOG2_ARE_BYTE, INFO_FLAG_WH_ARE_LOG2, geBitmap_Info::MaximumMip, geBitmap_Info::MinimumMip, geBitmap_Info::Palette, geBitmap::SeekMipCount, uint16, uint8, and geBitmap_Info::Width.

Referenced by geBitmap_WriteToFile().

04615 {
04616 uint8 data[64];
04617 uint8 * ptr;
04618 uint8 flags;
04619 uint8 b;
04620 int len,logw,logh;
04621 const geBitmap_Info * pi;
04622 
04623 /*
04624         bit flags :
04625                 W&H are log2
04626                 HasCK
04627                 HasAlpha
04628                 HasPal
04629 
04630                 W&H logs in 1 byte, or W & H each in 2 bytes
04631 
04632                 Format in 5 bits
04633                 MaxMip in 3 bits
04634                 Bmp->SeekMipCount in 3 bits
04635 
04636                 CK in bpp bytes
04637 */
04638 
04639         pi = &(Bmp->Info);
04640         flags = 0;
04641         ptr = data + 1; // flags will go there
04642 
04643         assert( pi->Width < 65536 && pi->Height < 65536 );
04644         assert( pi->MinimumMip == 0 );
04645         assert( gePixelFormat_IsValid(pi->Format) );
04646 
04647         *ptr++ = pi->Format; // could go in 5 bits
04648 
04649         b = (pi->MaximumMip << 4) + Bmp->SeekMipCount; // could go in 6 bits
04650         *ptr++ = b;
04651 
04652         if ( pi->Palette )
04653                 flags |= INFO_FLAG_HAS_PAL;
04654         if ( Bmp->Alpha )
04655                 flags |= INFO_FLAG_HAS_ALPHA;
04656 
04657         for(logw=0;(1<<logw) < pi->Width;logw++);
04658         for(logh=0;(1<<logh) < pi->Height;logh++);
04659 
04660         if ( (1<<logw) == pi->Width && (1<<logh) == pi->Height )
04661         {
04662                 flags |= INFO_FLAG_WH_ARE_LOG2;
04663                 assert( logw <= 0xF && logh <= 0xF );
04664                 b = (logw<<4) + logh;
04665                 *ptr++ = b;
04666         }
04667         else
04668         {
04669                 if ( pi->Width < 256 && pi->Height < 256 )
04670                 {
04671                         flags |= INFO_FLAG_IF_NOT_LOG2_ARE_BYTE;
04672                         *ptr++ = pi->Width;
04673                         *ptr++ = pi->Height;
04674                 }
04675                 else
04676                 {
04677                         *((uint16 *)ptr) = pi->Width;  ptr += 2;
04678                         *((uint16 *)ptr) = pi->Height; ptr += 2;
04679                 }
04680         }
04681 
04682         if ( pi->HasColorKey && gePixelFormat_BytesPerPel(pi->Format) > 0 )
04683         {
04684                 flags |= INFO_FLAG_HAS_CK;
04685 
04686                 gePixelFormat_PutPixel(pi->Format,&ptr,pi->ColorKey);
04687         }
04688 
04689         *data = flags;
04690         len = (int)(ptr - data);
04691 
04692         if ( ! geVFile_Write(F,data,len) )
04693                 return GE_FALSE;
04694 
04695         return GE_TRUE;
04696 }


Generated on Tue Sep 30 12:37:02 2003 for GTestAndEngine by doxygen 1.3.2