00001
00002 #include "SetFormat.h"
00003 #include "genesis.h"
00004 #include "errorlog.h"
00005 #include "ram.h"
00006 #include "gebmutil.h"
00007 #include <stdlib.h>
00008 #include <string.h>
00009 #include <assert.h>
00010
00011
00012
00013 Procedural *SetFormat_Create(geBitmap **ppBitmap, const char *ParmStart);
00014 void SetFormat_Destroy(Procedural *Proc);
00015 geBoolean SetFormat_Animate(Procedural *SetFormat, float ElapsedTime);
00016
00017 static Procedural_Table SetFormat_Table =
00018 {
00019 Procedurals_Version,Procedurals_Tag,
00020 "SetFormat",
00021 SetFormat_Create,
00022 SetFormat_Destroy,
00023 SetFormat_Animate
00024 };
00025
00026 Procedural_Table * SetFormat_GetProcedural_Table(void)
00027 {
00028 return &SetFormat_Table;
00029 }
00030
00031
00032
00033 typedef struct Procedural
00034 {
00035 geBitmap * Bitmap;
00036 } Procedural;
00037
00038
00039
00040 Procedural *SetFormat_Create(geBitmap **ppBitmap, const char *InParams)
00041 {
00042 Procedural * P;
00043 gePixelFormat Format;
00044 geBitmap_Info Info;
00045
00046 if ( ! ppBitmap || ! *ppBitmap )
00047 return NULL;
00048
00049 if ( ! InParams )
00050 {
00051 Format = GE_PIXELFORMAT_16BIT_4444_ARGB;
00052 }
00053 else
00054 {
00055 Format = atol(InParams);
00056 if ( ! gePixelFormat_IsValid(Format) )
00057 return NULL;
00058 }
00059
00060 P = geRam_Allocate(sizeof(Procedural));
00061 assert(P);
00062 memset(P,0,sizeof(Procedural));
00063
00064 P->Bitmap = *ppBitmap;
00065
00066 geBitmap_CreateRef(P->Bitmap);
00067
00068 geBitmap_GetInfo(P->Bitmap,&Info,NULL);
00069
00070 if ( gePixelFormat_HasAlpha(Format) && ! gePixelFormat_HasAlpha(Info.Format) )
00071 {
00072 geBitmapUtil_SetAlphaFromBrightness(P->Bitmap);
00073 }
00074
00075 if ( ! geBitmap_SetFormatMin(P->Bitmap,Format) )
00076 {
00077 geErrorLog_AddString(-1,"Setformat failed!",NULL);
00078 }
00079
00080 return P;
00081 }
00082
00083 void SetFormat_Destroy(Procedural * P)
00084 {
00085 if ( ! P )
00086 return;
00087 if ( P->Bitmap )
00088 geBitmap_Destroy(&(P->Bitmap));
00089 geRam_Free(P);
00090 }
00091
00092 geBoolean SetFormat_Animate(Procedural * P,float time)
00093 {
00094 return GE_TRUE;
00095 }