stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus/src/video graphic.c


From: Jimmy Salmon
Subject: [Stratagus-CVS] stratagus/src/video graphic.c
Date: Sat, 27 Sep 2003 14:26:27 -0400

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Jimmy Salmon <address@hidden>   03/09/27 14:26:27

Modified files:
        src/video      : graphic.c 

Log message:
        Cleanup

Patches:
Index: stratagus/src/video/graphic.c
diff -u stratagus/src/video/graphic.c:1.44 stratagus/src/video/graphic.c:1.45
--- stratagus/src/video/graphic.c:1.44  Sat Aug  9 16:08:39 2003
+++ stratagus/src/video/graphic.c       Sat Sep 27 14:26:27 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: graphic.c,v 1.44 2003/08/09 20:08:39 martinxyz Exp $
+//     $Id: graphic.c,v 1.45 2003/09/27 18:26:27 jsalmon3 Exp $
 
 //@{
 
@@ -46,7 +46,7 @@
 --     Declarations
 ----------------------------------------------------------------------------*/
 
-global PaletteLink *PaletteList;       /// List of all used palettes.
+global PaletteLink* PaletteList;       /// List of all used palettes.
 
 /*----------------------------------------------------------------------------
 --     Variables
@@ -70,9 +70,8 @@
 **     @param x        X screen position
 **     @param y        Y screen position
 */
-local void VideoDrawSub8to8(
-       const Graphic* graphic,int gx,int gy,int w,int h,
-       int x,int y)
+local void VideoDrawSub8to8(const Graphic* graphic, int gx, int gy,
+    int w, int h, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* lp;
@@ -82,24 +81,24 @@
     int sa;
     int da;
 
-    pixels=graphic->Pixels;
-    sp=(const unsigned char*)graphic->Frames+gx+gy*graphic->Width;
-    gp=sp+graphic->Width*h;
-    sa=graphic->Width-w;
-    dp=VideoMemory8+x+y*VideoWidth;
-    da=VideoWidth-w--;
-
-    while( sp<gp ) {
-       lp=sp+w;
-       while( sp<lp ) {
-           *dp++=pixels[*sp++];        // unroll
-           *dp++=pixels[*sp++];
+    pixels = graphic->Pixels;
+    sp = (const unsigned char*)graphic->Frames + gx + gy * graphic->Width;
+    gp = sp + graphic->Width * h;
+    sa = graphic->Width - w;
+    dp = VideoMemory8 + x + y * VideoWidth;
+    da = VideoWidth - w--;
+
+    while (sp < gp) {
+       lp = sp + w;
+       while (sp < lp) {
+           *dp++ = pixels[*sp++];      // unroll
+           *dp++ = pixels[*sp++];
        }
-       if( sp<=lp ) {
-           *dp++=pixels[*sp++];
+       if (sp <= lp) {
+           *dp++ = pixels[*sp++];
        }
-       sp+=sa;
-       dp+=da;
+       sp += sa;
+       dp += da;
     }
 }
 
@@ -114,9 +113,8 @@
 **     @param x        X screen position
 **     @param y        Y screen position
 */
-local void VideoDrawSub8to16(
-       const Graphic* graphic,int gx,int gy,int w,int h,
-       int x,int y)
+local void VideoDrawSub8to16(const Graphic* graphic, int gx, int gy,
+    int w, int h, int x,int y)
 {
     const unsigned char* sp;
     const unsigned char* lp;
@@ -126,24 +124,24 @@
     VMemType16* dp;
     int da;
 
-    pixels=(VMemType16*)graphic->Pixels;
-    sp=(const unsigned char*)graphic->Frames+gx+gy*graphic->Width;
-    gp=sp+graphic->Width*h;
-    sa=graphic->Width-w;
-    dp=VideoMemory16+x+y*VideoWidth;
-    da=VideoWidth-w--;
-
-    while( sp<gp ) {
-       lp=sp+w;
-       while( sp<lp ) {
-           *dp++=pixels[*sp++];        // unroll
-           *dp++=pixels[*sp++];
+    pixels = (VMemType16*)graphic->Pixels;
+    sp = (const unsigned char*)graphic->Frames + gx + gy * graphic->Width;
+    gp = sp + graphic->Width * h;
+    sa = graphic->Width - w;
+    dp = VideoMemory16 + x + y * VideoWidth;
+    da = VideoWidth - w--;
+
+    while (sp < gp) {
+       lp = sp + w;
+       while (sp < lp) {
+           *dp++ = pixels[*sp++];      // unroll
+           *dp++ = pixels[*sp++];
        }
-       if( sp<=lp ) {
-           *dp++=pixels[*sp++];
+       if (sp <= lp) {
+           *dp++ = pixels[*sp++];
        }
-       sp+=sa;
-       dp+=da;
+       sp += sa;
+       dp += da;
     }
 }
 
@@ -160,9 +158,8 @@
 **     @param x        X screen position
 **     @param y        Y screen position
 */
-local void VideoDrawSub8to24(
-       const Graphic* graphic,int gx,int gy,int w,int h,
-       int x,int y)
+local void VideoDrawSub8to24(const Graphic* graphic, int gx, int gy,
+    int w, int h, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* lp;
@@ -172,24 +169,24 @@
     VMemType24* dp;
     int da;
 
-    pixels=(VMemType24*)graphic->Pixels;
-    sp=(const unsigned char*)graphic->Frames+gx+gy*graphic->Width;
-    gp=sp+graphic->Width*h;
-    sa=graphic->Width-w;
-    dp=VideoMemory24+x+y*VideoWidth;
-    da=VideoWidth-w--;
-
-    while( sp<gp ) {
-       lp=sp+w;
-       while( sp<lp ) {
-           *dp++=pixels[*sp++];        // unroll
-           *dp++=pixels[*sp++];
+    pixels = (VMemType24*)graphic->Pixels;
+    sp = (const unsigned char*)graphic->Frames + gx + gy * graphic->Width;
+    gp = sp + graphic->Width * h;
+    sa = graphic->Width - w;
+    dp = VideoMemory24 + x + y * VideoWidth;
+    da = VideoWidth - w--;
+
+    while (sp < gp) {
+       lp = sp + w;
+       while (sp < lp) {
+           *dp++ = pixels[*sp++];      // unroll
+           *dp++ = pixels[*sp++];
        }
-       if( sp<=lp ) {
-           *dp++=pixels[*sp++];
+       if (sp <= lp) {
+           *dp++ = pixels[*sp++];
        }
-       sp+=sa;
-       dp+=da;
+       sp += sa;
+       dp += da;
     }
 }
 
@@ -204,9 +201,8 @@
 **     @param x        X screen position
 **     @param y        Y screen position
 */
-local void VideoDrawSub8to32(
-       const Graphic* graphic,int gx,int gy,int w,int h,
-       int x,int y)
+local void VideoDrawSub8to32(const Graphic* graphic, int gx, int gy,
+    int w, int h, int x, int y)
 {
     const unsigned char* sp;
     const unsigned char* lp;
@@ -216,24 +212,24 @@
     VMemType32* dp;
     int da;
 
-    pixels=(VMemType32*)graphic->Pixels;
-    sp=(const unsigned char*)graphic->Frames+gx+gy*graphic->Width;
-    gp=sp+graphic->Width*h;
-    sa=graphic->Width-w;
-    dp=VideoMemory32+x+y*VideoWidth;
-    da=VideoWidth-w--;
-
-    while( sp<gp ) {
-       lp=sp+w;
-       while( sp<lp ) {
-           *dp++=pixels[*sp++];        // unroll
-           *dp++=pixels[*sp++];
+    pixels = (VMemType32*)graphic->Pixels;
+    sp = (const unsigned char*)graphic->Frames + gx + gy * graphic->Width;
+    gp = sp + graphic->Width * h;
+    sa = graphic->Width - w;
+    dp = VideoMemory32 + x + y * VideoWidth;
+    da = VideoWidth - w--;
+
+    while (sp < gp) {
+       lp = sp + w;
+       while (sp < lp) {
+           *dp++ = pixels[*sp++];      // unroll
+           *dp++ = pixels[*sp++];
        }
-       if( sp<=lp ) {
-           *dp++=pixels[*sp++];
+       if (sp <= lp) {
+           *dp++ = pixels[*sp++];
        }
-       sp+=sa;
-       dp+=da;
+       sp += sa;
+       dp += da;
     }
 }
 
@@ -249,32 +245,37 @@
 **     @param y        Y screen position
 */
 #ifdef USE_OPENGL
-local void VideoDrawSubOpenGL(
-       const Graphic* graphic,int gx,int gy,int w,int h,
-       int x,int y)
-{
-    int sx,ex,sy,ey;
-    GLfloat stx,etx,sty,ety;
-
-    sx=x;
-    ex=sx+w;
-    ey=VideoHeight-y;
-    sy=ey-h;
-
-    stx=(GLfloat)gx/graphic->Width*graphic->TextureWidth;
-    etx=(GLfloat)(gx+w)/graphic->Width*graphic->TextureWidth;
-    sty=(GLfloat)gy/graphic->Height*graphic->TextureHeight;
-    ety=(GLfloat)(gy+h)/graphic->Height*graphic->TextureHeight;
+local void VideoDrawSubOpenGL(const Graphic* graphic, int gx, int gy,
+    int w, int h, int x, int y)
+{
+    int sx;
+    int ex;
+    int sy;
+    int ey;
+    GLfloat stx;
+    GLfloat etx;
+    GLfloat sty;
+    GLfloat ety;
+
+    sx = x;
+    ex = sx + w;
+    ey = VideoHeight - y;
+    sy = ey - h;
+
+    stx = (GLfloat)gx / graphic->Width * graphic->TextureWidth;
+    etx = (GLfloat)(gx + w) / graphic->Width * graphic->TextureWidth;
+    sty = (GLfloat)gy / graphic->Height * graphic->TextureHeight;
+    ety = (GLfloat)(gy + h) / graphic->Height * graphic->TextureHeight;
 
     glBindTexture(GL_TEXTURE_2D, graphic->TextureNames[0]);
     glBegin(GL_QUADS);
-    glTexCoord2f(stx, 1.0f-ety);
+    glTexCoord2f(stx, 1.0f - ety);
     glVertex2i(sx, sy);
-    glTexCoord2f(stx, 1.0f-sty);
+    glTexCoord2f(stx, 1.0f - sty);
     glVertex2i(sx, ey);
-    glTexCoord2f(etx, 1.0f-sty);
+    glTexCoord2f(etx, 1.0f - sty);
     glVertex2i(ex, ey);
-    glTexCoord2f(etx, 1.0f-ety);
+    glTexCoord2f(etx, 1.0f - ety);
     glVertex2i(ex, sy);
     glEnd();
 }
@@ -291,12 +292,11 @@
 **     @param x        X screen position
 **     @param y        Y screen position
 */
-local void VideoDrawSub8to8Clip(
-       const Graphic* graphic,int gx,int gy,int w,int h,
-       int x,int y)
+local void VideoDrawSub8to8Clip(const Graphic* graphic, int gx, int gy,
+    int w, int h, int x, int y)
 {
-    CLIP_RECTANGLE(x,y,w,h);
-    VideoDrawSub8to8(graphic,gx,gy,w,h,x,y);
+    CLIP_RECTANGLE(x, y, w, h);
+    VideoDrawSub8to8(graphic, gx, gy, w, h, x, y);
 }
 
 /**
@@ -310,12 +310,11 @@
 **     @param x        X screen position
 **     @param y        Y screen position
 */
-local void VideoDrawSub8to16Clip(
-       const Graphic* graphic,int gx,int gy,int w,int h,
-       int x,int y)
+local void VideoDrawSub8to16Clip(const Graphic* graphic, int gx, int gy,
+    int w, int h, int x, int y)
 {
-    CLIP_RECTANGLE(x,y,w,h);
-    VideoDrawSub8to16(graphic,gx,gy,w,h,x,y);
+    CLIP_RECTANGLE(x, y, w, h);
+    VideoDrawSub8to16(graphic, gx, gy, w, h, x, y);
 }
 
 /**
@@ -329,12 +328,11 @@
 **     @param x        X screen position
 **     @param y        Y screen position
 */
-local void VideoDrawSub8to24Clip(
-       const Graphic* graphic,int gx,int gy,int w,int h,
-       int x,int y)
+local void VideoDrawSub8to24Clip(const Graphic* graphic, int gx, int gy,
+    int w, int h, int x, int y)
 {
-    CLIP_RECTANGLE(x,y,w,h);
-    VideoDrawSub8to24(graphic,gx,gy,w,h,x,y);
+    CLIP_RECTANGLE(x, y, w, h);
+    VideoDrawSub8to24(graphic, gx, gy, w, h, x, y);
 }
 
 /**
@@ -348,12 +346,11 @@
 **     @param x        X screen position
 **     @param y        Y screen position
 */
-local void VideoDrawSub8to32Clip(
-       const Graphic* graphic,int gx,int gy,int w,int h,
-       int x,int y)
+local void VideoDrawSub8to32Clip(const Graphic* graphic, int gx, int gy,
+    int w, int h, int x, int y)
 {
-    CLIP_RECTANGLE(x,y,w,h);
-    VideoDrawSub8to32(graphic,gx,gy,w,h,x,y);
+    CLIP_RECTANGLE(x, y, w, h);
+    VideoDrawSub8to32(graphic, gx, gy, w, h, x, y);
 }
 
 /**
@@ -368,12 +365,11 @@
 **     @param y        Y screen position
 */
 #ifdef USE_OPENGL
-local void VideoDrawSubOpenGLClip(
-       const Graphic* graphic,int gx,int gy,int w,int h,
-       int x,int y)
+local void VideoDrawSubOpenGLClip(const Graphic* graphic, int gx, int gy,
+    int w, int h, int x, int y)
 {
-    CLIP_RECTANGLE(x,y,w,h);
-    VideoDrawSubOpenGL(graphic,gx,gy,w,h,x,y);
+    CLIP_RECTANGLE(x, y, w, h);
+    VideoDrawSubOpenGL(graphic, gx, gy, w, h, x, y);
 }
 #endif
 
@@ -382,11 +378,13 @@
 */
 local void FreeGraphic8(Graphic* graphic)
 {
-    IfDebug(AllocatedGraphicMemory -= graphic->Size);
-    IfDebug(AllocatedGraphicMemory -= sizeof(Graphic));
+#ifdef DEBUG
+    AllocatedGraphicMemory -= graphic->Size;
+    AllocatedGraphicMemory -= sizeof(Graphic);
+#endif
 
 #ifdef USE_OPENGL
-    if( graphic->NumTextureNames ) {
+    if (graphic->NumTextureNames) {
        glDeleteTextures(graphic->NumTextureNames, graphic->TextureNames);
        free(graphic->TextureNames);
     }
@@ -422,12 +420,11 @@
 **     @param y        Y screen position
 **     @param fade     Amount faded, from 0 (black) to 255 (no fading)
 */
-global void VideoDrawSubClipFaded(
-       Graphic* graphic,int gx,int gy,int w,int h,
-       int x,int y,unsigned char fade)
+global void VideoDrawSubClipFaded(Graphic* graphic, int gx, int gy,
+    int w, int h, int x, int y, unsigned char fade)
 {
-    VideoDrawSubClip(graphic,gx,gy,w,h,x,y);
-    VideoFillTransRectangle(ColorBlack,x,y,w,h,fade);
+    VideoDrawSubClip(graphic, gx, gy, w, h, x, y);
+    VideoFillTransRectangle(ColorBlack, x, y, w, h, fade);
 }
 
 /**
@@ -441,37 +438,39 @@
 **
 **     @return         New graphic object (malloced).
 */
-global Graphic* MakeGraphic(
-       unsigned depth,int width,int height,void* data,unsigned size)
+global Graphic* MakeGraphic(unsigned depth, int width, int height,
+    void* data, unsigned size)
 {
     Graphic* graphic;
 
-    graphic=malloc(sizeof(Graphic));
-    IfDebug( AllocatedGraphicMemory+=sizeof(Graphic) );
+    graphic = malloc(sizeof(Graphic));
+#ifdef DEBUG
+    AllocatedGraphicMemory += sizeof(Graphic);
+#endif
 
-    if( !graphic ) {
-       fprintf(stderr,"Out of memory\n");
+    if (!graphic) {
+       fprintf(stderr, "Out of memory\n");
        ExitFatal(-1);
     }
-    if( depth==8 ) {
-       graphic->Type=&GraphicImage8Type;
-    } else if( depth==16 ) {
-       graphic->Type=&GraphicImage16Type;
+    if (depth == 8) {
+       graphic->Type = &GraphicImage8Type;
+    } else if (depth == 16) {
+       graphic->Type = &GraphicImage16Type;
     } else {
-       fprintf(stderr,"Unsported image depth\n");
+       fprintf(stderr, "Unsported image depth\n");
        ExitFatal(-1);
     }
-    graphic->Width=width;
-    graphic->Height=height;
+    graphic->Width = width;
+    graphic->Height = height;
 
-    graphic->Pixels=NULL;
-    graphic->Palette=NULL;
+    graphic->Pixels = NULL;
+    graphic->Palette = NULL;
 
-    graphic->NumFrames=0;
-    graphic->Frames=data;
-    graphic->Size=size;
+    graphic->NumFrames = 0;
+    graphic->Frames = data;
+    graphic->Size = size;
 #ifdef USE_OPENGL
-    graphic->NumTextureNames=0;
+    graphic->NumTextureNames = 0;
 #endif
 
     return graphic;
@@ -484,17 +483,18 @@
 **     @param width    Pixel width.
 **     @param height   Pixel height.
 */
-global Graphic* NewGraphic(
-       unsigned depth,int width,int height)
+global Graphic* NewGraphic(unsigned depth, int width, int height)
 {
     void* data;
     int size;
 
-    size=width*height*(depth+7)/8;
-    data=malloc(size);
-    IfDebug( AllocatedGraphicMemory+=size );
+    size = width * height * (depth + 7) / 8;
+    data = malloc(size);
+#ifdef DEBUG
+    AllocatedGraphicMemory += size;
+#endif
 
-    return MakeGraphic(depth,width,height,data,size);
+    return MakeGraphic(depth, width, height, data, size);
 }
 
 /**
@@ -505,7 +505,7 @@
 **     @param height   Graphic height.
 */
 #ifdef USE_OPENGL
-global void MakeTexture(Graphic* graphic,int width,int height)
+global void MakeTexture(Graphic* graphic, int width, int height)
 {
     int i;
     int j;
@@ -517,55 +517,56 @@
     const unsigned char* sp;
     int fl;
 
-    n=(graphic->Width/width)*(graphic->Height/height);
-    fl=graphic->Width/width;
+    n = (graphic->Width / width) * (graphic->Height / height);
+    fl = graphic->Width / width;
 
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
     graphic->NumTextureNames = n;
-    graphic->TextureNames = (GLuint*)malloc(n*sizeof(GLuint));
+    graphic->TextureNames = (GLuint*)malloc(n * sizeof(GLuint));
     glGenTextures(n, graphic->TextureNames);
-    for( i=1; i<width; i<<=1 ) {
+    for (i = 1; i < width; i <<= 1) {
     }
-    w=i;
-    for( i=1; i<height; i<<=1 ) {
+    w = i;
+    for (i = 1; i < height; i <<= 1) {
     }
-    h=i;
-    graphic->TextureWidth = (float)width/w;
-    graphic->TextureHeight = (float)height/h;
-    tex = (unsigned char*)malloc(w*h*4);
-    for( x=0; x<n; ++x ) {
+    h = i;
+    graphic->TextureWidth = (float)width / w;
+    graphic->TextureHeight = (float)height / h;
+    tex = (unsigned char*)malloc(w * h * 4);
+    for (x = 0; x < n; ++x) {
        glBindTexture(GL_TEXTURE_2D, graphic->TextureNames[x]);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-       for( i=0; i<height; ++i ) {
-           sp=(const unsigned 
char*)graphic->Frames+(x%fl)*width+((x/fl)*height+i)*graphic->Width;
-           for( j=0; j<width; ++j ) {
+       for (i = 0; i < height; ++i) {
+           sp = (const unsigned char*)graphic->Frames + (x % fl) * width +
+               ((x / fl) * height + i) * graphic->Width;
+           for (j = 0; j < width; ++j) {
                int c;
                Palette p;
 
-               c = (h-i-1)*w*4+j*4;
-               if( *sp==255 ) {
-                   tex[c+3] = 0;
+               c = (h - i - 1) * w * 4 + j * 4;
+               if (*sp == 255) {
+                   tex[c + 3] = 0;
                } else {
                    p = graphic->Palette[*sp];
-                   tex[c+0] = p.r;
-                   tex[c+1] = p.g;
-                   tex[c+2] = p.b;
-                   tex[c+3] = 0xff;
+                   tex[c + 0] = p.r;
+                   tex[c + 1] = p.g;
+                   tex[c + 2] = p.b;
+                   tex[c + 3] = 0xff;
                }
                ++sp;
            }
        }
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
            GL_UNSIGNED_BYTE, tex);
-       IfDebug(
-           i = glGetError();
-           if (i) {
-               DebugLevel0Fn("glTexImage2D(%x)\n" _C_ i);
-           }
-       );
+#ifdef DEBUG
+       i = glGetError();
+       if (i) {
+           DebugLevel0Fn("glTexImage2D(%x)\n" _C_ i);
+       }
+#endif
     }
     free(tex);
 }
@@ -575,8 +576,8 @@
 **
 **     FIXME: Docu
 */
-global void MakePlayerColorTexture(Graphic** g,Graphic* graphic,int frame,
-       unsigned char *map,int maplen)
+global void MakePlayerColorTexture(Graphic** g, Graphic* graphic, int frame,
+       unsigned char* map, int maplen)
 {
     int i;
     int j;
@@ -587,8 +588,8 @@
     const unsigned char* sp;
     int fl;
 
-    if( !*g ) {
-       *g = calloc(1,sizeof(Graphic));
+    if (!*g) {
+       *g = calloc(1, sizeof(Graphic));
 
        n = graphic->NumFrames;
 
@@ -605,55 +606,56 @@
        (*g)->TextureHeight = graphic->TextureHeight;
     }
 
-    fl = graphic->GraphicWidth/graphic->Width;
+    fl = graphic->GraphicWidth / graphic->Width;
     glGenTextures(1, &(*g)->TextureNames[frame]);
 
-    for( i=1; i<graphic->Width; i<<=1 ) {
+    for (i = 1; i < graphic->Width; i <<= 1) {
     }
-    w=i;
-    for( i=1; i<graphic->Height; i<<=1 ) {
+    w = i;
+    for (i = 1; i < graphic->Height; i <<= 1) {
     }
-    h=i;
+    h = i;
 
-    tex = (unsigned char*)malloc(w*h*4);
+    tex = (unsigned char*)malloc(w * h * 4);
 
     glBindTexture(GL_TEXTURE_2D, (*g)->TextureNames[frame]);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    for( i=0; i<graphic->Height; ++i ) {
-       sp=(const unsigned char*)graphic->Frames + (frame%fl)*graphic->Width + 
((frame/fl)*graphic->Height+i)*graphic->GraphicWidth;
-       for( j=0; j<graphic->Width; ++j ) {
+    for (i = 0; i < graphic->Height; ++i) {
+       sp = (const unsigned char*)graphic->Frames + (frame % fl) * 
graphic->Width +
+           ((frame / fl) * graphic->Height + i) * graphic->GraphicWidth;
+       for (j = 0; j < graphic->Width; ++j) {
            int c;
            int z;
            Palette p;
 
-           c=(h-i-1)*w*4+j*4;
-           for( z=0; z<maplen; ++z ) {
-               if( *sp==map[z*2] ) {
-                   p=GlobalPalette[map[z*2+1]];
-                   tex[c+0] = p.r;
-                   tex[c+1] = p.g;
-                   tex[c+2] = p.b;
-                   tex[c+3] = 0xff;
+           c = (h - i - 1) * w * 4 + j * 4;
+           for (z = 0; z < maplen; ++z) {
+               if (*sp == map[z * 2]) {
+                   p = GlobalPalette[map[z * 2 + 1]];
+                   tex[c + 0] = p.r;
+                   tex[c + 1] = p.g;
+                   tex[c + 2] = p.b;
+                   tex[c + 3] = 0xff;
                    break;
                }
            }
-           if( z==maplen ) {
-               tex[c+3] = 0;
+           if (z == maplen) {
+               tex[c + 3] = 0;
            }
            ++sp;
        }
     }
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
        GL_UNSIGNED_BYTE, tex);
-    IfDebug(
-       i = glGetError();
-       if (i) {
-           DebugLevel0Fn("glTexImage2D(%x)\n" _C_ i);
-       }
-    );
+#ifdef DEBUG
+    i = glGetError();
+    if (i) {
+       DebugLevel0Fn("glTexImage2D(%x)\n" _C_ i);
+    }
+#endif
     free(tex);
 }
 #endif
@@ -668,33 +670,37 @@
 **     @todo   FIXME: Higher quality resizing.
 **             FIXME: Works only with 8bit indexed graphic objects.
 */
-global void ResizeGraphic(Graphic *g,int w,int h)
+global void ResizeGraphic(Graphic *g, int w, int h)
 {
     int i;
     int j;
-    unsigned char *data;
+    unsigned char* data;
     int x;
 
-    DebugCheck( g->Type!=&GraphicImage8Type );
+    DebugCheck(g->Type != &GraphicImage8Type);
 
-    if( g->Width==w && g->Height==h ) {
+    if (g->Width == w && g->Height == h) {
        return;
     }
 
-    data = (unsigned char*)malloc(w*h);
-    IfDebug( AllocatedGraphicMemory+=w*h );
-    x=0;
+    data = (unsigned char*)malloc(w * h);
+#ifdef DEBUG
+    AllocatedGraphicMemory += w * h;
+#endif
+    x = 0;
 
-    for( i=0; i<h; ++i ) {
-       for( j=0; j<w; ++j ) {
+    for (i = 0; i < h; ++i) {
+       for (j = 0; j < w; ++j) {
            data[x] = ((unsigned char*)g->Frames)[
-               (i*g->Height/h)*g->Width + j*g->Width/w];
+               (i * g->Height / h) * g->Width + j * g->Width / w];
            ++x;
        }
     }
 
     free(g->Frames);
-    IfDebug( AllocatedGraphicMemory-=g->Width*g->Height );
+#ifdef DEBUG
+    AllocatedGraphicMemory -= g->Width * g->Height;
+#endif
     g->Frames = data;
     g->Width = w;
     g->Height = h;
@@ -711,7 +717,7 @@
 **                     FIXME: I want to support our own binary format!
 **                     FIXME: Add support for 16bit indexed format!
 */
-global Graphic* LoadGraphic(const char *name)
+global Graphic* LoadGraphic(const char* name)
 {
     Graphic* graphic;
     char buf[1024];
@@ -738,29 +744,29 @@
 global void InitGraphic(void)
 {
 #ifdef USE_OPENGL
-    GraphicImage8Type.DrawSub=VideoDrawSubOpenGL;
-    GraphicImage8Type.DrawSubClip=VideoDrawSubOpenGLClip;
+    GraphicImage8Type.DrawSub = VideoDrawSubOpenGL;
+    GraphicImage8Type.DrawSubClip = VideoDrawSubOpenGLClip;
 #else
     switch( VideoBpp ) {
        case 8:
-           GraphicImage8Type.DrawSub=VideoDrawSub8to8;
-           GraphicImage8Type.DrawSubClip=VideoDrawSub8to8Clip;
+           GraphicImage8Type.DrawSub = VideoDrawSub8to8;
+           GraphicImage8Type.DrawSubClip = VideoDrawSub8to8Clip;
            break;
 
        case 15:
        case 16:
-           GraphicImage8Type.DrawSub=VideoDrawSub8to16;
-           GraphicImage8Type.DrawSubClip=VideoDrawSub8to16Clip;
+           GraphicImage8Type.DrawSub = VideoDrawSub8to16;
+           GraphicImage8Type.DrawSubClip = VideoDrawSub8to16Clip;
            break;
 
        case 24:
-           GraphicImage8Type.DrawSub=VideoDrawSub8to24;
-           GraphicImage8Type.DrawSubClip=VideoDrawSub8to24Clip;
+           GraphicImage8Type.DrawSub = VideoDrawSub8to24;
+           GraphicImage8Type.DrawSubClip = VideoDrawSub8to24Clip;
            break;
 
        case 32:
-           GraphicImage8Type.DrawSub=VideoDrawSub8to32;
-           GraphicImage8Type.DrawSubClip=VideoDrawSub8to32Clip;
+           GraphicImage8Type.DrawSub = VideoDrawSub8to32;
+           GraphicImage8Type.DrawSubClip = VideoDrawSub8to32Clip;
            break;
 
        default:
@@ -768,7 +774,7 @@
            abort();
     }
 #endif
-    GraphicImage8Type.Free=FreeGraphic8;
+    GraphicImage8Type.Free = FreeGraphic8;
 }
 
 //@}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]