From fc6019ae7bed4cf1d0981e51add7050af884cca7 Mon Sep 17 00:00:00 2001 From: Xane Date: Sat, 7 Mar 2009 22:21:43 +0000 Subject: [PATCH] [CHG] Pure cosmetic update - Made the code more readable and fixed some spelling errors. --- GRRLIB/GRRLIB/GRRLIB.c | 423 ++++++++++++++++++++--------------------- 1 file changed, 207 insertions(+), 216 deletions(-) diff --git a/GRRLIB/GRRLIB/GRRLIB.c b/GRRLIB/GRRLIB/GRRLIB.c index ed8eb87..0e28862 100644 --- a/GRRLIB/GRRLIB/GRRLIB.c +++ b/GRRLIB/GRRLIB/GRRLIB.c @@ -27,7 +27,7 @@ static void RawTo4x4RGBA(const unsigned char *src, void *dst, const unsigned int /** * Clear screen with a specific color. - * @param color the color to use to fill the screen. + * @param color The color to use to fill the screen. */ inline void GRRLIB_FillScreen(u32 color) { GRRLIB_Rectangle(-40, -40, 680, 520, color, 1); @@ -35,9 +35,9 @@ inline void GRRLIB_FillScreen(u32 color) { /** * Draw a dot. - * @param x specifies the x-coordinate of the dot. - * @param y specifies the y-coordinate of the dot. - * @param color the color of the dot in RGBA format. + * @param x Specifies the x-coordinate of the dot. + * @param y Specifies the y-coordinate of the dot. + * @param color The color of the dot in RGBA format. */ inline void GRRLIB_Plot(f32 x, f32 y, u32 color) { Vector v[] = {{x,y,0.0f}}; @@ -47,9 +47,9 @@ inline void GRRLIB_Plot(f32 x, f32 y, u32 color) { /** * Draw an array of points. - * @param v array containing the points. - * @param color the color of the points in RGBA format. - * @param n number of points in the vector array. + * @param v Array containing the points. + * @param color The color of the points in RGBA format. + * @param n Number of points in the vector array. */ void GRRLIB_NPlot(Vector v[], u32 color, long n) { GRRLIB_GXEngine(v, color, n, GX_POINTS); @@ -57,11 +57,11 @@ void GRRLIB_NPlot(Vector v[], u32 color, long n) { /** * Draw a line. - * @param x1 start point for line for the x coordinate. - * @param y1 start point for line for the y coordinate. - * @param x2 end point for line for the x coordinate. - * @param y2 end point for line for the x coordinate. - * @param color line color in RGBA format. + * @param x1 Starting point for line for the x coordinate. + * @param y1 Starting point for line for the y coordinate. + * @param x2 Ending point for line for the x coordinate. + * @param y2 Ending point for line for the x coordinate. + * @param color Line color in RGBA format. */ inline void GRRLIB_Line(f32 x1, f32 y1, f32 x2, f32 y2, u32 color) { Vector v[] = {{x1,y1,0.0f}, {x2,y2,0.0f}}; @@ -71,22 +71,22 @@ inline void GRRLIB_Line(f32 x1, f32 y1, f32 x2, f32 y2, u32 color) { /** * Draw a rectangle. - * @param x specifies the x-coordinate of the upper-left corner of the rectangle. - * @param y specifies the y-coordinate of the upper-left corner of the rectangle. - * @param width the width of the rectangle. - * @param height the height of the rectangle. - * @param color the color of the rectangle in RGBA format. - * @param filled true to fill the rectangle with a color. + * @param x Specifies the x-coordinate of the upper-left corner of the rectangle. + * @param y Specifies the y-coordinate of the upper-left corner of the rectangle. + * @param width The width of the rectangle. + * @param height The height of the rectangle. + * @param color The color of the rectangle in RGBA format. + * @param filled Set to true to fill the rectangle. */ inline void GRRLIB_Rectangle(f32 x, f32 y, f32 width, f32 height, u32 color, u8 filled) { f32 x2 = x+width; f32 y2 = y+height; Vector v[] = {{x,y,0.0f}, {x2,y,0.0f}, {x2,y2,0.0f}, {x,y2,0.0f}, {x,y,0.0f}}; - if(!filled) { + if (!filled) { GRRLIB_NGone(v, color, 5); } - else{ + else { GRRLIB_NGoneFilled(v, color, 4); } } @@ -94,11 +94,11 @@ inline void GRRLIB_Rectangle(f32 x, f32 y, f32 width, f32 height, u32 color, u8 /** * Draw a circle. * @author Dark_Link - * @param x - * @param y - * @param radius the radius of the circle. - * @param color the color of the circle in RGBA format. - * @param filled true to fill the circle with a color. + * @param x Specifies the x-coordinate of the circle. + * @param y Specifies the y-coordinate of the circle. + * @param radius The radius of the circle. + * @param color The color of the circle in RGBA format. + * @param filled Set to true to fill the circle. */ inline void GRRLIB_Circle(f32 x, f32 y, f32 radius, u32 color, u8 filled) { Vector v[36]; @@ -124,9 +124,9 @@ inline void GRRLIB_Circle(f32 x, f32 y, f32 radius, u32 color, u8 filled) { /** * Draw a polygon. - * @param v - * @param color the color of the polygon in RGBA format. - * @param n + * @param v The vector containing the coordinates of the polygon. + * @param color The color of the filled polygon in RGBA format. + * @param n Number of points in the vector. */ void GRRLIB_NGone(Vector v[], u32 color, long n) { GRRLIB_GXEngine(v, color, n, GX_LINESTRIP); @@ -134,9 +134,9 @@ void GRRLIB_NGone(Vector v[], u32 color, long n) { /** * Draw a filled polygon. - * @param v - * @param color the color of the filled polygon in RGBA format. - * @param n + * @param v The vector containing the coordinates of the polygon. + * @param color The color of the filled polygon in RGBA format. + * @param n Number of points in the vector. */ void GRRLIB_NGoneFilled(Vector v[], u32 color, long n) { GRRLIB_GXEngine(v, color, n, GX_TRIANGLEFAN); @@ -144,17 +144,17 @@ void GRRLIB_NGoneFilled(Vector v[], u32 color, long n) { /** * Initialize a tile set. - * @param tex texture to initialize. - * @param tilew widht of the tile. - * @param tileh height of the tile. - * @param tilestart offset for starting position. + * @param tex The texture to initialize. + * @param tilew Width of the tile. + * @param tileh Height of the tile. + * @param tilestart Offset for starting position. (Used in fonts) */ void GRRLIB_InitTileSet(struct GRRLIB_texImg *tex, unsigned int tilew, unsigned int tileh, unsigned int tilestart) { tex->tilew = tilew; tex->tileh = tileh; - if(tilew) // Avoid division by zero + if (tilew) // Avoid division by zero tex->nbtilew = tex->w / tilew; - if(tileh) // Avoid division by zero + if (tileh) // Avoid division by zero tex->nbtileh = tex->h / tileh; tex->tilestart = tilestart; } @@ -162,7 +162,7 @@ void GRRLIB_InitTileSet(struct GRRLIB_texImg *tex, unsigned int tilew, unsigned /** * Load a texture from a buffer. * @param my_png the PNG buffer to load. - * @return A GRRLIB_texImg structure filled with PNG informations. + * @return A GRRLIB_texImg structure filled with image informations. */ GRRLIB_texImg GRRLIB_LoadTexturePNG(const unsigned char my_png[]) { PNGUPROP imgProp; @@ -182,7 +182,7 @@ GRRLIB_texImg GRRLIB_LoadTexturePNG(const unsigned char my_png[]) { } /** - * Convert a raw bmp (RGB, no alpha) to 4x4RGBA. + * Convert a raw BMP (RGB, no alpha) to 4x4RGBA. * @author DragonMinded * @param src * @param dst @@ -197,11 +197,11 @@ static void RawTo4x4RGBA(const unsigned char *src, void *dst, const unsigned int unsigned int gb; unsigned char *p = (unsigned char*)dst; - for(block = 0; block < height; block += 4) { - for(i = 0; i < width; i += 4) { + for (block = 0; block < height; block += 4) { + for (i = 0; i < width; i += 4) { /* Alpha and Red */ - for(c = 0; c < 4; ++c) { - for(ar = 0; ar < 4; ++ar) { + for (c = 0; c < 4; ++c) { + for (ar = 0; ar < 4; ++ar) { /* Alpha pixels */ *p++ = 255; /* Red pixels */ @@ -210,8 +210,8 @@ static void RawTo4x4RGBA(const unsigned char *src, void *dst, const unsigned int } /* Green and Blue */ - for(c = 0; c < 4; ++c) { - for(gb = 0; gb < 4; ++gb) { + for (c = 0; c < 4; ++c) { + for (gb = 0; gb < 4; ++gb) { /* Green pixels */ *p++ = src[(((i + gb) + ((block + c) * width)) * 3) + 1]; /* Blue pixels */ @@ -224,10 +224,10 @@ static void RawTo4x4RGBA(const unsigned char *src, void *dst, const unsigned int /** * Load a texture from a buffer. - * Take Care to have a JPG finnishing by 0xFF 0xD9 !!!! + * Take care to have the JPG finnish with 0xFF 0xD9!! * @author DrTwox - * @param my_jpg the JPEG buffer to load. - * @return A GRRLIB_texImg structure filled with PNG informations. + * @param my_jpg The JPEG buffer to load. + * @return A GRRLIB_texImg structure filled with image informations. */ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) { struct jpeg_decompress_struct cinfo; @@ -236,9 +236,9 @@ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) { int n = 0; unsigned int i; - if((my_jpg[0]==0xff) && (my_jpg[1]==0xd8) && (my_jpg[2]==0xff)) { - while(1) { - if((my_jpg[n]==0xff) && (my_jpg[n+1]==0xd9)) + if ((my_jpg[0]==0xff) && (my_jpg[1]==0xd8) && (my_jpg[2]==0xff)) { + while(true) { + if ((my_jpg[n]==0xff) && (my_jpg[n+1]==0xd9)) break; n++; } @@ -255,9 +255,9 @@ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) { JSAMPROW row_pointer[1]; row_pointer[0] = (unsigned char*) malloc(cinfo.output_width * cinfo.num_components); size_t location = 0; - while(cinfo.output_scanline < cinfo.output_height) { + while (cinfo.output_scanline < cinfo.output_height) { jpeg_read_scanlines(&cinfo, row_pointer, 1); - for(i = 0; i < cinfo.image_width * cinfo.num_components; i++) { + for (i = 0; i < cinfo.image_width * cinfo.num_components; i++) { /* Put the decoded scanline into the tempBuffer */ tempBuffer[ location++ ] = row_pointer[0][i]; } @@ -267,7 +267,7 @@ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) { my_texture.data = memalign(32, cinfo.output_width * cinfo.output_height * 4); RawTo4x4RGBA(tempBuffer, my_texture.data, cinfo.output_width, cinfo.output_height); - /* Done - do cleanup and release memory */ + /* Done - Do cleanup and release allocated memory */ jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); free(row_pointer[0]); @@ -283,11 +283,11 @@ GRRLIB_texImg GRRLIB_LoadTextureJPG(const unsigned char my_jpg[]) { /** * Print formatted output. - * @param xpos - * @param ypos - * @param bmf - * @param zoom - * @param text text to draw. + * @param xpos Specifies the x-coordinate of the upper-left corner of the text. + * @param ypos Specifies the y-coordinate of the upper-left corner of the text. + * @param bmf The ByteMap font to use. + * @param zoom This is a factor by which the text size will be increase or decrease. + * @param text Text to draw. * @param ... Optional arguments. */ void GRRLIB_PrintBMF(f32 xpos, f32 ypos, GRRLIB_bytemapFont bmf, f32 zoom, const char *text, ...) { @@ -301,13 +301,13 @@ void GRRLIB_PrintBMF(f32 xpos, f32 ypos, GRRLIB_bytemapFont bmf, f32 zoom, const GRRLIB_texImg tex_BMfont = GRRLIB_CreateEmptyTexture(640, 480); - for(i=0; ifbWidth, rmode->efbHeight ); } - /** - * Sets a texture's X and Y handles. (e.g. for rotation) - * @param tex GRRLIB Texture + * Set a texture's X and Y handles. (e.g. for rotation) + * @param tex The texture to set the handle on. * @param x The handle's x-coordinate * @param y The handle's y-coordinate */ @@ -667,8 +664,8 @@ void GRRLIB_SetHandle( GRRLIB_texImg * tex, int x, int y ) { } /** - * Centers a texture's handles. (e.g. for rotation) - * @param tex GRRLIB Texture + * Center a texture's handles. (e.g. for rotation) + * @param tex The texture to center. */ void GRRLIB_SetMidHandle( GRRLIB_texImg * tex ) { tex->handlex = 0; @@ -680,9 +677,9 @@ void GRRLIB_SetMidHandle( GRRLIB_texImg * tex ) { /** * Return the color value of a pixel from a GRRLIB_texImg. - * @param x specifies the x-coordinate of the pixel in the texture. - * @param y specifies the y-coordinate of the pixel in the texture. - * @param tex texture to get the color from. + * @param x Specifies the x-coordinate of the pixel in the texture. + * @param y Specifies the y-coordinate of the pixel in the texture. + * @param tex The texture to get the color from. * @return The color of a pixel in RGBA format. */ u32 GRRLIB_GetPixelFromtexImg(int x, int y, GRRLIB_texImg tex) { @@ -697,16 +694,16 @@ u32 GRRLIB_GetPixelFromtexImg(int x, int y, GRRLIB_texImg tex) { g=*(truc+offset+32); b=*(truc+offset+33); - return((r<<24) | (g<<16) | (b<<8) | a); + return ((r<<24) | (g<<16) | (b<<8) | a); } /** * Set the color value of a pixel to a GRRLIB_texImg. * @see GRRLIB_FlushTex - * @param x specifies the x-coordinate of the pixel in the texture. - * @param y specifies the y-coordinate of the pixel in the texture. - * @param tex texture to set the color to. - * @param color the color of the pixel in RGBA format. + * @param x Specifies the x-coordinate of the pixel in the texture. + * @param y Specifies the y-coordinate of the pixel in the texture. + * @param tex The texture to set the color to. + * @param color The color of the pixel in RGBA format. */ void GRRLIB_SetPixelTotexImg(int x, int y, GRRLIB_texImg tex, u32 color) { u8 *truc = (u8*)tex.data; @@ -721,28 +718,27 @@ void GRRLIB_SetPixelTotexImg(int x, int y, GRRLIB_texImg tex, u32 color) { } /** - * Writes the contents of a texture in the data cache down to main memory. + * Write the contents of a texture in the data cache down to main memory. * For performance the CPU holds a data cache where modifications are stored before they get written down to mainmemory. - * @param tex the texture to flush. + * @param tex The texture to flush. */ -void GRRLIB_FlushTex(GRRLIB_texImg tex) -{ +void GRRLIB_FlushTex(GRRLIB_texImg tex) { DCFlushRange(tex.data, tex.w * tex.h * 4); } /** * Change a texture to gray scale. * @see GRRLIB_FlushTex - * @param texsrc the texture source. - * @param texdest the texture grayscaled destination. + * @param texsrc The texture source. + * @param texdest The texture grayscaled destination. */ void GRRLIB_BMFX_Grayscale(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) { unsigned int x, y; u8 gray; u32 color; - for(y=0; y> 24 & 0xFF)*77 + (color >> 16 & 0xFF)*150 + (color >> 8 & 0xFF)*28) / (255)); @@ -756,17 +752,16 @@ void GRRLIB_BMFX_Grayscale(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) { /** * Invert colors of the texture. * @see GRRLIB_FlushTex - * @param texsrc the texture source. - * @param texdest the texture destination. + * @param texsrc The texture source. + * @param texdest The texture destination. */ void GRRLIB_BMFX_Invert(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) { unsigned int x, y; u32 color; - for(y=0; y> 8 & 0xFFFFFF)) << 8) | (color & 0xFF)); } @@ -776,14 +771,14 @@ void GRRLIB_BMFX_Invert(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) { /** * Flip texture horizontal. * @see GRRLIB_FlushTex - * @param texsrc the texture source. - * @param texdest the texture destination. + * @param texsrc The texture source. + * @param texdest The texture destination. */ void GRRLIB_BMFX_FlipH(GRRLIB_texImg texsrc, GRRLIB_texImg texdest) { unsigned int x, y, txtWidth = texsrc.w - 1; - for(y=0; y= texsrc.w) { colours[tmp] = thiscol; } - else if(l < 0) { colours[tmp] = thiscol; } - else if(l >= texsrc.h) { colours[tmp] = thiscol; } + for (k = x - factor; k <= x + factor; k++) { + for (l = y - factor; l <= y + factor; l++) { + if (k < 0) { colours[tmp] = thiscol; } + else if (k >= texsrc.w) { colours[tmp] = thiscol; } + else if (l < 0) { colours[tmp] = thiscol; } + else if (l >= texsrc.h) { colours[tmp] = thiscol; } else { colours[tmp] = GRRLIB_GetPixelFromtexImg(k, l, texsrc); } tmp++; } } - for(tmp = 0; tmp < numba; tmp++) { + for (tmp = 0; tmp < numba; tmp++) { newr += (colours[tmp] >> 24) & 0xFF; newg += (colours[tmp] >> 16) & 0xFF; newb += (colours[tmp] >> 8) & 0xFF; @@ -863,10 +858,10 @@ void GRRLIB_BMFX_Blur(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) { } /** - * A texture effect. + * A texture effect. (Pixelate) * @see GRRLIB_FlushTex - * @param texsrc the texture source. - * @param texdest the texture destination. + * @param texsrc The texture source. + * @param texdest The texture destination. * @param factor The factor level of the effect. */ void GRRLIB_BMFX_Pixelate(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor) { @@ -874,11 +869,11 @@ void GRRLIB_BMFX_Pixelate(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int facto unsigned int xx, yy; u32 rgb; - for(x=0; x= texsrc.w) || (val1 <0) || (val2 >= texsrc.h) || (val2 <0)) { + if ((val1 >= texsrc.w) || (val1 < 0) || (val2 >= texsrc.h) || (val2 < 0)) { } else { val3 = GRRLIB_GetPixelFromtexImg(x, y, texsrc); @@ -917,17 +912,13 @@ void GRRLIB_BMFX_Scatter(GRRLIB_texImg texsrc, GRRLIB_texImg texdest, int factor } /** - * - * @param v - * @param color - * @param n - * @param fmt + * Draws a vector. */ void GRRLIB_GXEngine(Vector v[], u32 color, long n, u8 fmt) { int i; GX_Begin(fmt, GX_VTXFMT0, n); - for(i=0; iviWidth = 678; rmode->viXOrigin = (VI_MAX_WIDTH_NTSC - 678)/2; } @@ -957,26 +948,26 @@ void GRRLIB_Init() { VIDEO_Configure(rmode); xfb[0] = (u32 *)MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); xfb[1] = (u32 *)MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); - if(xfb[0] == NULL || xfb[1] == NULL) + if (xfb[0] == NULL || xfb[1] == NULL) return; VIDEO_SetNextFramebuffer(xfb[fb]); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); - if(rmode->viTVMode&VI_NON_INTERLACE) + if (rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); gp_fifo = (u8 *) memalign(32, DEFAULT_FIFO_SIZE); - if(gp_fifo == NULL) + if (gp_fifo == NULL) return; memset(gp_fifo, 0, DEFAULT_FIFO_SIZE); GX_Init(gp_fifo, DEFAULT_FIFO_SIZE); - // clears the bg to color and clears the z buffer + // Clears the BG to color and clears the z-buffer GX_SetCopyClear((GXColor){ 0, 0, 0, 0xff }, GX_MAX_Z24); - // other gx setup + // Other GX setup yscale = GX_GetYScaleFactor(rmode->efbHeight, rmode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0, 0, rmode->fbWidth, rmode->efbHeight); @@ -985,7 +976,7 @@ void GRRLIB_Init() { GX_SetCopyFilter(rmode->aa, rmode->sample_pattern, GX_TRUE, rmode->vfilter); GX_SetFieldMode(rmode->field_rendering, ((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); - if(rmode->aa) + if (rmode->aa) GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); else GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); @@ -993,8 +984,8 @@ void GRRLIB_Init() { GX_SetDispCopyGamma(GX_GM_1_0); - // setup the vertex descriptor - // tells the flipper to expect direct data + // Setup the vertex descriptor + // Tells the flipper to expect direct data GX_ClearVtxDesc(); GX_InvVtxCache(); GX_InvalidateTexAll(); @@ -1035,7 +1026,7 @@ void GRRLIB_Init() { void GRRLIB_Render() { GX_DrawDone(); - fb ^= 1; // flip framebuffer + fb ^= 1; // Flip framebuffer GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetColorUpdate(GX_TRUE); GX_CopyDisp(xfb[fb], GX_TRUE); @@ -1049,21 +1040,21 @@ void GRRLIB_Render() { */ void GRRLIB_Exit() { GX_SetClipMode( GX_CLIP_DISABLE ); - GX_SetScissor( 0, 0, WinW, WinH ); + GX_SetScissor( 0, 0, rmode->fbWidth, rmode->efbHeight ); GRRLIB_FillScreen( 0x000000FF ); GRRLIB_Render(); GX_Flush(); GX_AbortFrame(); - if(xfb[0] != NULL) { + if (xfb[0] != NULL) { free(MEM_K1_TO_K0(xfb[0])); xfb[0] = NULL; } - if(xfb[1] != NULL) { + if (xfb[1] != NULL) { free(MEM_K1_TO_K0(xfb[1])); xfb[1] = NULL; } - if(gp_fifo != NULL) { + if (gp_fifo != NULL) { free(gp_fifo); gp_fifo = NULL; }