Graphics code optimizations, updated TODO to correspond all recent changes

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@169 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
gewlitys
2002-10-28 02:00:12 +00:00
parent b5a577b156
commit 37aea8de90
6 changed files with 34 additions and 155 deletions
+1 -1
View File
@@ -45,7 +45,7 @@ enum
int TFB_InitGraphics (int driver, int flags, int width, int height, int bpp);
void TFB_UninitGraphics ();
void TFB_UninitGraphics (void);
void TFB_ProcessEvents (void);
// 3DO Graphics Stuff
+7 -12
View File
@@ -52,8 +52,8 @@ blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr)
GetFrameHotX (_CurFramePtr);
DrawCommand.y = pClipRect->corner.y -
GetFrameHotY (_CurFramePtr);
DrawCommand.w = img->NormalImg->clip_rect.w;
DrawCommand.h = img->NormalImg->clip_rect.h;
DrawCommand.w = img->NormalImg->w;
DrawCommand.h = img->NormalImg->h;
if (gscale != 0 && gscale != 256)
{
@@ -88,7 +88,7 @@ blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr)
if (new_surf)
{
if (new_surf->format->BytesPerPixel > 1)
if (!new_surf->format->palette)
{
img->ScaledImg = TFB_DisplayFormatAlpha (new_surf);
if (img->ScaledImg)
@@ -157,7 +157,7 @@ blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr)
}
else
{
SDL_Rect SDL_SrcRect, SDL_DstRect;
SDL_Rect SDL_DstRect;
TFB_Image *dst_img;
dst_img = ((TFB_Image *) ((BYTE *) _CurFramePtr +
@@ -165,19 +165,14 @@ blt (PRECT pClipRect, PRIMITIVEPTR PrimPtr)
LockMutex (dst_img->mutex);
SDL_SrcRect.x = (short) img->NormalImg->clip_rect.x;
SDL_SrcRect.y = (short) img->NormalImg->clip_rect.y;
SDL_SrcRect.w = (short) img->NormalImg->clip_rect.w;
SDL_SrcRect.h = (short) img->NormalImg->clip_rect.h;
SDL_DstRect.x = (short) pClipRect->corner.x -
GetFrameHotX (_CurFramePtr) + SDL_SrcRect.x;
GetFrameHotX (_CurFramePtr);
SDL_DstRect.y = (short) pClipRect->corner.y -
GetFrameHotY (_CurFramePtr) + SDL_SrcRect.y;
GetFrameHotY (_CurFramePtr);
SDL_BlitSurface (
img->NormalImg,
&SDL_SrcRect,
NULL,
dst_img->NormalImg,
&SDL_DstRect
);
@@ -30,10 +30,6 @@ typedef struct anidata
{
int transparent_color;
int colormap_index;
int clip_x;
int clip_y;
int clip_w;
int clip_h;
int hotspot_x;
int hotspot_y;
} AniData;
@@ -54,24 +50,12 @@ process_image (FRAMEPTR FramePtr, SDL_Surface *img[], AniData *ani, int cel_ct)
{
if (ani[cel_ct].transparent_color != -1)
SDL_SetColorKey(img[cel_ct], SDL_SRCCOLORKEY, ani[cel_ct].transparent_color);
if (ani[cel_ct].clip_x != -1)
img[cel_ct]->clip_rect.x = ani[cel_ct].clip_x;
if (ani[cel_ct].clip_y != -1)
img[cel_ct]->clip_rect.y = ani[cel_ct].clip_y;
if (ani[cel_ct].clip_w != -1)
img[cel_ct]->clip_rect.w = ani[cel_ct].clip_w;
if (ani[cel_ct].clip_h != -1)
img[cel_ct]->clip_rect.h = ani[cel_ct].clip_h;
if (ani[cel_ct].hotspot_x != -1)
hx = ani[cel_ct].hotspot_x;
if (ani[cel_ct].hotspot_y != -1)
hy = ani[cel_ct].hotspot_y;
}
hx -= img[cel_ct]->clip_rect.x;
hy -= img[cel_ct]->clip_rect.y;
FramePtr->DataOffs = (BYTE *)TFB_LoadImage (img[cel_ct]) - (BYTE *)FramePtr;
@@ -79,18 +63,8 @@ process_image (FRAMEPTR FramePtr, SDL_Surface *img[], AniData *ani, int cel_ct)
tfbimg->colormap_index = ani[cel_ct].colormap_index;
img[cel_ct] = tfbimg->NormalImg;
hx += img[cel_ct]->clip_rect.x;
hy += img[cel_ct]->clip_rect.y;
SetFrameHotSpot (FramePtr, MAKE_HOT_SPOT (hx, hy));
SetFrameBounds (FramePtr, img[cel_ct]->clip_rect.w, img[cel_ct]->clip_rect.h);
#if 0
fprintf (stderr, "\thot[%d, %d], rect[%d, %d, %d, %d]\n",
hx, hy,
img[cel_ct]->clip_rect.x, img[cel_ct]->clip_rect.y,
img[cel_ct]->clip_rect.w, img[cel_ct]->clip_rect.h);
#endif
SetFrameBounds (FramePtr, img[cel_ct]->w, img[cel_ct]->h);
}
static void
@@ -149,18 +123,12 @@ process_font (FRAMEPTR FramePtr, SDL_Surface *img[], int cel_ct)
SDL_FreeSurface (img[cel_ct]);
img[cel_ct] = new_surf;
hx -= img[cel_ct]->clip_rect.x;
hy -= img[cel_ct]->clip_rect.y;
FramePtr->DataOffs = (BYTE *)TFB_LoadImage (img[cel_ct]) - (BYTE *)FramePtr;
img[cel_ct] = ((TFB_Image *)((BYTE *)FramePtr + FramePtr->DataOffs))->NormalImg;
hx += img[cel_ct]->clip_rect.x;
hy += img[cel_ct]->clip_rect.y;
SetFrameHotSpot (FramePtr, MAKE_HOT_SPOT (hx, hy));
SetFrameBounds (FramePtr, img[cel_ct]->clip_rect.w, img[cel_ct]->clip_rect.h);
SetFrameBounds (FramePtr, img[cel_ct]->w, img[cel_ct]->h);
}
MEM_HANDLE
@@ -208,11 +176,6 @@ _GetCelData (FILE *fp, DWORD length)
sscanf (CurrentLine, "%s %d %d %d %d", &filename[n],
&ani[cel_ct].transparent_color, &ani[cel_ct].colormap_index,
&ani[cel_ct].hotspot_x, &ani[cel_ct].hotspot_y);
ani[cel_ct].clip_x = -1;
ani[cel_ct].clip_y = -1;
ani[cel_ct].clip_w = -1;
ani[cel_ct].clip_h = -1;
if ((img[cel_ct] = IMG_Load (filename)) && img[cel_ct]->w > 0 &&
img[cel_ct]->h > 0 && img[cel_ct]->format->BitsPerPixel >= 8)
@@ -385,14 +348,14 @@ _GetFontData (FILE *fp, DWORD length)
int tune_amount = 0;
if (img[0]->clip_rect.h == 8)
if (img[0]->h == 8)
tune_amount = -1;
else if (img[0]->clip_rect.h == 9)
else if (img[0]->h == 9)
tune_amount = -2;
else if (img[0]->clip_rect.h > 9)
else if (img[0]->h > 9)
tune_amount = -3;
SetFrameHotSpot (FramePtr, MAKE_HOT_SPOT (0, img[0]->clip_rect.h + tune_amount));
SetFrameHotSpot (FramePtr, MAKE_HOT_SPOT (0, img[0]->h + tune_amount));
}
if (GetFrameHeight (FramePtr) > FontPtr->Leading)
+12 -76
View File
@@ -140,89 +140,29 @@ TFB_LoadImage (SDL_Surface *img)
TFB_Image *myImage;
myImage = (TFB_Image*) HMalloc (sizeof (TFB_Image));
myImage->mutex = CreateMutex();
myImage->mutex = CreateMutex ();
myImage->ScaledImg = NULL;
myImage->Palette = NULL;
myImage->colormap_index = -1;
if (img->format->BytesPerPixel == 1)
if (img->format->palette)
{
int x,y;
Uint8 *src_p,*dst_p;
SDL_Surface *full_surf;
SDL_Rect SDL_DstRect;
full_surf = SDL_CreateRGBSurface (SDL_SWSURFACE, img->clip_rect.w, img->clip_rect.h,
8, 0, 0, 0, 0);
SDL_DstRect.x = SDL_DstRect.y = 0;
SDL_LockSurface(img);
SDL_LockSurface(full_surf);
src_p = (Uint8*)img->pixels;
dst_p = (Uint8*)full_surf->pixels;
for (y = img->clip_rect.y; y < img->clip_rect.y + img->clip_rect.h; ++y)
{
for (x = img->clip_rect.x; x < img->clip_rect.x + img->clip_rect.w; ++x)
{
dst_p[(y - img->clip_rect.y) * full_surf->pitch + (x - img->clip_rect.x)]=
src_p[y * img->pitch + x];
}
}
full_surf->clip_rect.x = full_surf->clip_rect.y = 0;
full_surf->clip_rect.w = img->clip_rect.w;
full_surf->clip_rect.h = img->clip_rect.h;
int i;
myImage->Palette = (SDL_Color*) HMalloc (sizeof (SDL_Color) * 256);
for (x = 0; x < 256; ++x)
for (i = 0; i < 256; ++i)
{
myImage->Palette[x].r = img->format->palette->colors[x].r;
myImage->Palette[x].g = img->format->palette->colors[x].g;
myImage->Palette[x].b = img->format->palette->colors[x].b;
myImage->Palette[i].r = img->format->palette->colors[i].r;
myImage->Palette[i].g = img->format->palette->colors[i].g;
myImage->Palette[i].b = img->format->palette->colors[i].b;
}
SDL_SetColors (full_surf, myImage->Palette, 0, 256);
if (img->flags & SDL_SRCCOLORKEY)
{
SDL_SetColorKey (full_surf, SDL_SRCCOLORKEY, img->format->colorkey);
}
SDL_UnlockSurface(full_surf);
SDL_UnlockSurface(img);
SDL_FreeSurface (img);
img = full_surf;
myImage->NormalImg = img;
}
else if (img->format->BytesPerPixel == 2 || img->format->BytesPerPixel == 3) {
SDL_Surface *full_surf;
SDL_Rect SDL_DstRect;
full_surf = SDL_CreateRGBSurface (SDL_SWSURFACE, img->clip_rect.w, img->clip_rect.h,
32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
SDL_DstRect.x = SDL_DstRect.y = 0;
SDL_BlitSurface (img, &img->clip_rect, full_surf, &SDL_DstRect);
full_surf->clip_rect.x = full_surf->clip_rect.y = 0;
full_surf->clip_rect.w = img->clip_rect.w;
full_surf->clip_rect.h = img->clip_rect.h;
SDL_FreeSurface (img);
img = full_surf;
}
if (img->format->BytesPerPixel > 1)
else
{
myImage->Palette = NULL;
myImage->NormalImg = TFB_DisplayFormatAlpha (img);
if (myImage->NormalImg)
{
SDL_FreeSurface(img);
SDL_FreeSurface (img);
}
else
{
@@ -230,10 +170,6 @@ TFB_LoadImage (SDL_Surface *img)
myImage->NormalImg = img;
}
}
else
{
myImage->NormalImg = img;
}
return(myImage);
}
@@ -689,7 +625,7 @@ TFB_FlushGraphics () // Only call from main thread!!
else
surf = DC_image->NormalImg;
if (surf->format->BytesPerPixel == 1)
if (surf->format->palette)
{
if (DC.UsePalette)
{