From a6109922162fe6b17cbfd40c1fdef9bd563be257 Mon Sep 17 00:00:00 2001 From: Miriam Ruiz Date: Wed, 3 Dec 2008 01:34:55 +0100 Subject: [PATCH] Convert end of line characters to UNIX --- Example/Test.c | 220 ++++++++++++++--------------- include/GL/glpng.h | 60 ++++---- src/glpng.c | 408 ++++++++++++++++++++++++++--------------------------- 3 files changed, 344 insertions(+), 344 deletions(-) diff --git a/Example/Test.c b/Example/Test.c index 9d20cff..7ab4444 100644 --- a/Example/Test.c +++ b/Example/Test.c @@ -1,110 +1,110 @@ -/* - * Test program for glpng - * by Ben Wyatt ben@wyatt100.freeserve.co.uk - * Featuring a shameless plug for my stunt course program - * Available from the same site as glpng - * http://www.wyatt100.freeserve.co.uk/download.htm - */ - -#include -#include -#include - -int angle = 0; - -/***** GLUT callback functions *****/ - -void KeyPress(unsigned char key, int x, int y) { - switch (key) { - case 27: /*ESC*/ glutDestroyWindow(glutGetWindow()); exit(0); break; - } -} - -void Update(void) { - angle = (angle+1)%360; - glutPostRedisplay(); -} - -void Display(void) { - const float w = 2, h = 2; - - glClear(GL_COLOR_BUFFER_BIT); - - glLoadIdentity(); - glTranslatef(0, 0, -10); - glRotatef(angle, 0, 1, 0); - - glBegin(GL_QUADS); - // Front - glTexCoord2f(1, 1); glVertex3f( w, -h, 0); - glTexCoord2f(1, 0); glVertex3f( w, h, 0); - glTexCoord2f(0, 0); glVertex3f(-w, h, 0); - glTexCoord2f(0, 1); glVertex3f(-w, -h, 0); - - // Back - glTexCoord2f(1, 1); glVertex3f(-w, -h, 0); - glTexCoord2f(1, 0); glVertex3f(-w, h, 0); - glTexCoord2f(0, 0); glVertex3f( w, h, 0); - glTexCoord2f(0, 1); glVertex3f( w, -h, 0); - glEnd(); - - glutSwapBuffers(); -} - -void Reshape(int w, int h) { - glViewport(0, 0, w, h); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(30, (float) w/h, 1, 100); - - glMatrixMode(GL_MODELVIEW); - Display(); -} - -/***** Main function *****/ - -void main() { - pngInfo info; - GLuint texture; - - glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); - glutInitWindowSize(300, 300); - glutCreateWindow("glpng test"); - - #if 0 // Using pngLoad and setting texture parameters manually. - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - - if (!pngLoad("Stunt.png", PNG_NOMIPMAP, PNG_SOLID, &info)) { - puts("Can't load file"); - exit(1); - } - #else // Using pngLoadAndBind to set texture parameters automatically. - texture = pngBind("Stunt.png", PNG_NOMIPMAP, PNG_ALPHA, &info, GL_CLAMP, GL_NEAREST, GL_NEAREST); - - if (texture == 0) { - puts("Can't load file"); - exit(1); - } - #endif - - printf("Size=%i,%i Depth=%i Alpha=%i\n", info.Width, info.Height, info.Depth, info.Alpha); - - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, texture); - glEnable(GL_CULL_FACE); - glColor3f(1, 1, 1); - - glutKeyboardFunc(KeyPress); - glutIdleFunc(Update); - glutDisplayFunc(Display); - glutReshapeFunc(Reshape); - - glutMainLoop(); -} +/* + * Test program for glpng + * by Ben Wyatt ben@wyatt100.freeserve.co.uk + * Featuring a shameless plug for my stunt course program + * Available from the same site as glpng + * http://www.wyatt100.freeserve.co.uk/download.htm + */ + +#include +#include +#include + +int angle = 0; + +/***** GLUT callback functions *****/ + +void KeyPress(unsigned char key, int x, int y) { + switch (key) { + case 27: /*ESC*/ glutDestroyWindow(glutGetWindow()); exit(0); break; + } +} + +void Update(void) { + angle = (angle+1)%360; + glutPostRedisplay(); +} + +void Display(void) { + const float w = 2, h = 2; + + glClear(GL_COLOR_BUFFER_BIT); + + glLoadIdentity(); + glTranslatef(0, 0, -10); + glRotatef(angle, 0, 1, 0); + + glBegin(GL_QUADS); + // Front + glTexCoord2f(1, 1); glVertex3f( w, -h, 0); + glTexCoord2f(1, 0); glVertex3f( w, h, 0); + glTexCoord2f(0, 0); glVertex3f(-w, h, 0); + glTexCoord2f(0, 1); glVertex3f(-w, -h, 0); + + // Back + glTexCoord2f(1, 1); glVertex3f(-w, -h, 0); + glTexCoord2f(1, 0); glVertex3f(-w, h, 0); + glTexCoord2f(0, 0); glVertex3f( w, h, 0); + glTexCoord2f(0, 1); glVertex3f( w, -h, 0); + glEnd(); + + glutSwapBuffers(); +} + +void Reshape(int w, int h) { + glViewport(0, 0, w, h); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(30, (float) w/h, 1, 100); + + glMatrixMode(GL_MODELVIEW); + Display(); +} + +/***** Main function *****/ + +void main() { + pngInfo info; + GLuint texture; + + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); + glutInitWindowSize(300, 300); + glutCreateWindow("glpng test"); + + #if 0 // Using pngLoad and setting texture parameters manually. + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + + if (!pngLoad("Stunt.png", PNG_NOMIPMAP, PNG_SOLID, &info)) { + puts("Can't load file"); + exit(1); + } + #else // Using pngLoadAndBind to set texture parameters automatically. + texture = pngBind("Stunt.png", PNG_NOMIPMAP, PNG_ALPHA, &info, GL_CLAMP, GL_NEAREST, GL_NEAREST); + + if (texture == 0) { + puts("Can't load file"); + exit(1); + } + #endif + + printf("Size=%i,%i Depth=%i Alpha=%i\n", info.Width, info.Height, info.Depth, info.Alpha); + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texture); + glEnable(GL_CULL_FACE); + glColor3f(1, 1, 1); + + glutKeyboardFunc(KeyPress); + glutIdleFunc(Update); + glutDisplayFunc(Display); + glutReshapeFunc(Reshape); + + glutMainLoop(); +} diff --git a/include/GL/glpng.h b/include/GL/glpng.h index b98ab88..c23ebcb 100644 --- a/include/GL/glpng.h +++ b/include/GL/glpng.h @@ -2,22 +2,22 @@ * PNG loader library for OpenGL v1.45 (10/07/00) * by Ben Wyatt ben@wyatt100.freeserve.co.uk * Using LibPNG 1.0.2 and ZLib 1.1.3 - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the author be held liable for any damages arising from the - * use of this software. - * - * Permission is hereby granted to use, copy, modify, and distribute this - * source code, or portions hereof, for any purpose, without fee, subject to - * the following restrictions: - * - * 1. The origin of this source code must not be misrepresented. You must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered versions must be plainly marked as such and must not be - * misrepresented as being the original source. - * 3. This notice must not be removed or altered from any source distribution. + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the author be held liable for any damages arising from the + * use of this software. + * + * Permission is hereby granted to use, copy, modify, and distribute this + * source code, or portions hereof, for any purpose, without fee, subject to + * the following restrictions: + * + * 1. The origin of this source code must not be misrepresented. You must not + * claim that you wrote the original software. If you use this software in + * a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered versions must be plainly marked as such and must not be + * misrepresented as being the original source. + * 3. This notice must not be removed or altered from any source distribution. */ #ifndef _GLPNG_H_ @@ -30,10 +30,10 @@ extern "C" { #endif #ifdef _MSC_VER - #ifdef _DEBUG - #pragma comment (lib, "glpngd.lib") - #else - #pragma comment (lib, "glpng.lib") + #ifdef _DEBUG + #pragma comment (lib, "glpngd.lib") + #else + #pragma comment (lib, "glpng.lib") #endif #endif @@ -48,15 +48,15 @@ extern "C" { /* Mipmapping parameters */ #define PNG_NOMIPMAPS 0 /* No mipmapping */ -#define PNG_BUILDMIPMAPS -1 /* Calls a clone of gluBuild2DMipmaps() */ -#define PNG_SIMPLEMIPMAPS -2 /* Generates mipmaps without filtering */ - -/* Who needs an "S" anyway? */ -#define PNG_NOMIPMAP PNG_NOMIPMAPS -#define PNG_BUILDMIPMAP PNG_BUILDMIPMAPS -#define PNG_SIMPLEMIPMAP PNG_SIMPLEMIPMAPS - -/* Transparency parameters */ +#define PNG_BUILDMIPMAPS -1 /* Calls a clone of gluBuild2DMipmaps() */ +#define PNG_SIMPLEMIPMAPS -2 /* Generates mipmaps without filtering */ + +/* Who needs an "S" anyway? */ +#define PNG_NOMIPMAP PNG_NOMIPMAPS +#define PNG_BUILDMIPMAP PNG_BUILDMIPMAPS +#define PNG_SIMPLEMIPMAP PNG_SIMPLEMIPMAPS + +/* Transparency parameters */ #define PNG_CALLBACK -3 /* Call the callback function to generate alpha */ #define PNG_ALPHA -2 /* Use alpha channel in PNG file, if there is one */ #define PNG_SOLID -1 /* No transparency */ @@ -100,7 +100,7 @@ extern unsigned int APIENTRY pngBindF(FILE *file, int mipmap, int trans, pngInfo extern void APIENTRY pngSetStencil(unsigned char red, unsigned char green, unsigned char blue); extern void APIENTRY pngSetAlphaCallback(unsigned char (*callback)(unsigned char red, unsigned char green, unsigned char blue)); extern void APIENTRY pngSetViewingGamma(double viewingGamma); -extern void APIENTRY pngSetStandardOrientation(int standardorientation); +extern void APIENTRY pngSetStandardOrientation(int standardorientation); #ifdef __cplusplus } diff --git a/src/glpng.c b/src/glpng.c index 194dfc1..edae8f5 100644 --- a/src/glpng.c +++ b/src/glpng.c @@ -1,40 +1,40 @@ -/* - * PNG loader library for OpenGL v1.45 (10/07/00) - * by Ben Wyatt ben@wyatt100.freeserve.co.uk - * Using LibPNG 1.0.2 and ZLib 1.1.3 - * - * This software is provided 'as-is', without any express or implied warranty. - * In no event will the author be held liable for any damages arising from the - * use of this software. - * - * Permission is hereby granted to use, copy, modify, and distribute this - * source code, or portions hereof, for any purpose, without fee, subject to - * the following restrictions: - * - * 1. The origin of this source code must not be misrepresented. You must not - * claim that you wrote the original software. If you use this software in - * a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered versions must be plainly marked as such and must not be - * misrepresented as being the original source. - * 3. This notice must not be removed or altered from any source distribution. - */ - +/* + * PNG loader library for OpenGL v1.45 (10/07/00) + * by Ben Wyatt ben@wyatt100.freeserve.co.uk + * Using LibPNG 1.0.2 and ZLib 1.1.3 + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the author be held liable for any damages arising from the + * use of this software. + * + * Permission is hereby granted to use, copy, modify, and distribute this + * source code, or portions hereof, for any purpose, without fee, subject to + * the following restrictions: + * + * 1. The origin of this source code must not be misrepresented. You must not + * claim that you wrote the original software. If you use this software in + * a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered versions must be plainly marked as such and must not be + * misrepresented as being the original source. + * 3. This notice must not be removed or altered from any source distribution. + */ + #ifdef _WIN32 /* Stupid Windows needs to include windows.h before gl.h */ #undef FAR #include #endif #include -#include +#include #include #include #include - -/* Used to decide if GL/gl.h supports the paletted extension */ -#ifdef GL_COLOR_INDEX1_EXT -#define SUPPORTS_PALETTE_EXT -#endif + +/* Used to decide if GL/gl.h supports the paletted extension */ +#ifdef GL_COLOR_INDEX1_EXT +#define SUPPORTS_PALETTE_EXT +#endif static unsigned char DefaultAlphaCallback(unsigned char red, unsigned char green, unsigned char blue) { return 255; @@ -42,13 +42,13 @@ static unsigned char DefaultAlphaCallback(unsigned char red, unsigned char green static unsigned char StencilRed = 0, StencilGreen = 0, StencilBlue = 0; static unsigned char (*AlphaCallback)(unsigned char red, unsigned char green, unsigned char blue) = DefaultAlphaCallback; -static int StandardOrientation = 0; +static int StandardOrientation = 0; -#ifdef SUPPORTS_PALETTE_EXT +#ifdef SUPPORTS_PALETTE_EXT #ifdef _WIN32 -static PFNGLCOLORTABLEEXTPROC glColorTableEXT = NULL; +static PFNGLCOLORTABLEEXTPROC glColorTableEXT = NULL; +#endif #endif -#endif static int PalettedTextures = -1; static GLint MaxTextureSize = 0; @@ -58,17 +58,17 @@ static GLint MaxTextureSize = 0; * viewingGamma depends on platform. PC is 1.0, Mac is 1.45, SGI defaults * to 1.7, but this can be checked and changed w/ /usr/sbin/gamma command. * If the environment variable VIEWING_GAMMA is set, adjust gamma per this value. - */ -#ifdef _MAC - static double screenGamma = 2.2 / 1.45; -#elif SGI - static double screenGamma = 2.2 / 1.7; + */ +#ifdef _MAC + static double screenGamma = 2.2 / 1.45; +#elif SGI + static double screenGamma = 2.2 / 1.7; #else /* PC/default */ - static double screenGamma = 2.2 / 1.0; -#endif - + static double screenGamma = 2.2 / 1.0; +#endif + static char gammaExplicit = 0; /*if */ - + static void checkForGammaEnv() { double viewingGamma; @@ -112,7 +112,7 @@ static void Resize(int components, const png_bytep d1, int w1, int h1, png_bytep } } } - + #ifdef _WIN32 static int ExtSupported(const char *x) { static const GLubyte *ext = NULL; @@ -131,110 +131,110 @@ static int ExtSupported(const char *x) { return 0; } #endif - -#define GET(o) ((int)*(data + (o))) - -static int HalfSize(GLint components, GLint width, GLint height, const unsigned char *data, unsigned char *d, int filter) { - int x, y, c; - int line = width*components; - - if (width > 1 && height > 1) { - if (filter) - for (y = 0; y < height; y += 2) { - for (x = 0; x < width; x += 2) { - for (c = 0; c < components; c++) { - *d++ = (GET(0)+GET(components)+GET(line)+GET(line+components)) / 4; - data++; - } - data += components; - } - data += line; - } - else - for (y = 0; y < height; y += 2) { - for (x = 0; x < width; x += 2) { - for (c = 0; c < components; c++) { - *d++ = GET(0); - data++; - } - data += components; - } - data += line; - } - } - else if (width > 1 && height == 1) { - if (filter) - for (y = 0; y < height; y += 1) { - for (x = 0; x < width; x += 2) { - for (c = 0; c < components; c++) { - *d++ = (GET(0)+GET(components)) / 2; - data++; - } - data += components; - } - } - else - for (y = 0; y < height; y += 1) { - for (x = 0; x < width; x += 2) { - for (c = 0; c < components; c++) { - *d++ = GET(0); - data++; - } - data += components; - } - } - } - else if (width == 1 && height > 1) { - if (filter) - for (y = 0; y < height; y += 2) { - for (x = 0; x < width; x += 1) { - for (c = 0; c < components; c++) { - *d++ = (GET(0)+GET(line)) / 2; - data++; - } - } - data += line; - } - else - for (y = 0; y < height; y += 2) { - for (x = 0; x < width; x += 1) { - for (c = 0; c < components; c++) { - *d++ = GET(0); - data++; - } - } - data += line; - } - } - else { - return 0; - } - - return 1; -} - -#undef GET - -/* Replacement for gluBuild2DMipmaps so GLU isn't needed */ -static void Build2DMipmaps(GLint components, GLint width, GLint height, GLenum format, const unsigned char *data, int filter) { - int level = 0; - unsigned char *d = (unsigned char *) malloc((width/2)*(height/2)*components+4); - const unsigned char *last = data; - - glTexImage2D(GL_TEXTURE_2D, level, components, width, height, 0, format, GL_UNSIGNED_BYTE, data); - level++; - - while (HalfSize(components, width, height, last, d, filter)) { - if (width > 1) width /= 2; - if (height > 1) height /= 2; - - glTexImage2D(GL_TEXTURE_2D, level, components, width, height, 0, format, GL_UNSIGNED_BYTE, d); - level++; - last = d; - } - - free(d); -} + +#define GET(o) ((int)*(data + (o))) + +static int HalfSize(GLint components, GLint width, GLint height, const unsigned char *data, unsigned char *d, int filter) { + int x, y, c; + int line = width*components; + + if (width > 1 && height > 1) { + if (filter) + for (y = 0; y < height; y += 2) { + for (x = 0; x < width; x += 2) { + for (c = 0; c < components; c++) { + *d++ = (GET(0)+GET(components)+GET(line)+GET(line+components)) / 4; + data++; + } + data += components; + } + data += line; + } + else + for (y = 0; y < height; y += 2) { + for (x = 0; x < width; x += 2) { + for (c = 0; c < components; c++) { + *d++ = GET(0); + data++; + } + data += components; + } + data += line; + } + } + else if (width > 1 && height == 1) { + if (filter) + for (y = 0; y < height; y += 1) { + for (x = 0; x < width; x += 2) { + for (c = 0; c < components; c++) { + *d++ = (GET(0)+GET(components)) / 2; + data++; + } + data += components; + } + } + else + for (y = 0; y < height; y += 1) { + for (x = 0; x < width; x += 2) { + for (c = 0; c < components; c++) { + *d++ = GET(0); + data++; + } + data += components; + } + } + } + else if (width == 1 && height > 1) { + if (filter) + for (y = 0; y < height; y += 2) { + for (x = 0; x < width; x += 1) { + for (c = 0; c < components; c++) { + *d++ = (GET(0)+GET(line)) / 2; + data++; + } + } + data += line; + } + else + for (y = 0; y < height; y += 2) { + for (x = 0; x < width; x += 1) { + for (c = 0; c < components; c++) { + *d++ = GET(0); + data++; + } + } + data += line; + } + } + else { + return 0; + } + + return 1; +} + +#undef GET + +/* Replacement for gluBuild2DMipmaps so GLU isn't needed */ +static void Build2DMipmaps(GLint components, GLint width, GLint height, GLenum format, const unsigned char *data, int filter) { + int level = 0; + unsigned char *d = (unsigned char *) malloc((width/2)*(height/2)*components+4); + const unsigned char *last = data; + + glTexImage2D(GL_TEXTURE_2D, level, components, width, height, 0, format, GL_UNSIGNED_BYTE, data); + level++; + + while (HalfSize(components, width, height, last, d, filter)) { + if (width > 1) width /= 2; + if (height > 1) height /= 2; + + glTexImage2D(GL_TEXTURE_2D, level, components, width, height, 0, format, GL_UNSIGNED_BYTE, d); + level++; + last = d; + } + + free(d); +} int APIENTRY pngLoadRaw(const char *filename, pngRawInfo *pinfo) { int result; @@ -277,14 +277,14 @@ int APIENTRY pngLoadRawF(FILE *fp, pngRawInfo *pinfo) { info = png_create_info_struct(png); endinfo = png_create_info_struct(png); - // DH: added following lines - if (setjmp(png->jmpbuf)) - { - png_destroy_read_struct(&png, &info, &endinfo); - return 0; - } - // ~DH - + // DH: added following lines + if (setjmp(png->jmpbuf)) + { + png_destroy_read_struct(&png, &info, &endinfo); + return 0; + } + // ~DH + png_init_io(png, fp); png_set_sig_bytes(png, 8); png_read_info(png, info); @@ -305,13 +305,13 @@ int APIENTRY pngLoadRawF(FILE *fp, pngRawInfo *pinfo) { data = (png_bytep) malloc(png_get_rowbytes(png, info)*height); row_p = (png_bytep *) malloc(sizeof(png_bytep)*height); - + for (i = 0; i < height; i++) { - if (StandardOrientation) - row_p[height - 1 - i] = &data[png_get_rowbytes(png, info)*i]; - else - row_p[i] = &data[png_get_rowbytes(png, info)*i]; - } + if (StandardOrientation) + row_p[height - 1 - i] = &data[png_get_rowbytes(png, info)*i]; + else + row_p[i] = &data[png_get_rowbytes(png, info)*i]; + } png_read_image(png, row_p); free(row_p); @@ -323,7 +323,7 @@ int APIENTRY pngLoadRawF(FILE *fp, pngRawInfo *pinfo) { else { pinfo->Palette = NULL; } - + if (color&PNG_COLOR_MASK_ALPHA) { if (color&PNG_COLOR_MASK_PALETTE || color == PNG_COLOR_TYPE_GRAY_ALPHA) pinfo->Components = 2; @@ -360,7 +360,7 @@ int APIENTRY pngLoad(const char *filename, int mipmap, int trans, pngInfo *pinfo } int APIENTRY pngLoadF(FILE *fp, int mipmap, int trans, pngInfo *pinfo) { - GLint pack, unpack; + GLint pack, unpack; unsigned char header[8]; png_structp png; png_infop info; @@ -381,14 +381,14 @@ int APIENTRY pngLoadF(FILE *fp, int mipmap, int trans, pngInfo *pinfo) { info = png_create_info_struct(png); endinfo = png_create_info_struct(png); - // DH: added following lines - if (setjmp(png->jmpbuf)) - { - png_destroy_read_struct(&png, &info, &endinfo); - return 0; - } - // ~DH - + // DH: added following lines + if (setjmp(png->jmpbuf)) + { + png_destroy_read_struct(&png, &info, &endinfo); + return 0; + } + // ~DH + png_init_io(png, fp); png_set_sig_bytes(png, 8); png_read_info(png, info); @@ -403,23 +403,23 @@ int APIENTRY pngLoadF(FILE *fp, int mipmap, int trans, pngInfo *pinfo) { if (MaxTextureSize == 0) glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTextureSize); - #ifdef SUPPORTS_PALETTE_EXT + #ifdef SUPPORTS_PALETTE_EXT #ifdef _WIN32 - if (PalettedTextures == -1) - PalettedTextures = ExtSupported("GL_EXT_paletted_texture") && (strstr((const char *) glGetString(GL_VERSION), "1.1.0 3Dfx Beta") == NULL); - + if (PalettedTextures == -1) + PalettedTextures = ExtSupported("GL_EXT_paletted_texture") && (strstr((const char *) glGetString(GL_VERSION), "1.1.0 3Dfx Beta") == NULL); + if (PalettedTextures) { if (glColorTableEXT == NULL) { glColorTableEXT = (PFNGLCOLORTABLEEXTPROC) wglGetProcAddress("glColorTableEXT"); if (glColorTableEXT == NULL) PalettedTextures = 0; } - } + } #endif #endif - - if (PalettedTextures == -1) - PalettedTextures = 0; + + if (PalettedTextures == -1) + PalettedTextures = 0; if (color == PNG_COLOR_TYPE_GRAY || color == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png); @@ -444,13 +444,13 @@ int APIENTRY pngLoadF(FILE *fp, int mipmap, int trans, pngInfo *pinfo) { data = (png_bytep) malloc(png_get_rowbytes(png, info)*height); row_p = (png_bytep *) malloc(sizeof(png_bytep)*height); - - for (i = 0; i < height; i++) { + + for (i = 0; i < height; i++) { if (StandardOrientation) - row_p[height - 1 - i] = &data[png_get_rowbytes(png, info)*i]; - else - row_p[i] = &data[png_get_rowbytes(png, info)*i]; - } + row_p[height - 1 - i] = &data[png_get_rowbytes(png, info)*i]; + else + row_p[i] = &data[png_get_rowbytes(png, info)*i]; + } png_read_image(png, row_p); free(row_p); @@ -473,12 +473,12 @@ int APIENTRY pngLoadF(FILE *fp, int mipmap, int trans, pngInfo *pinfo) { data = data2; } - { /* OpenGL stuff */ - glGetIntegerv(GL_PACK_ALIGNMENT, &pack); - glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack); - glPixelStorei(GL_PACK_ALIGNMENT, 1); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - + { /* OpenGL stuff */ + glGetIntegerv(GL_PACK_ALIGNMENT, &pack); + glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + #ifdef SUPPORTS_PALETTE_EXT if (PalettedTextures && mipmap >= 0 && trans == PNG_SOLID && color == PNG_COLOR_TYPE_PALETTE) { png_colorp pal; @@ -502,8 +502,8 @@ int APIENTRY pngLoadF(FILE *fp, int mipmap, int trans, pngInfo *pinfo) { glColorTableEXT(GL_TEXTURE_2D, GL_RGB8, cols, GL_RGB, GL_UNSIGNED_BYTE, pal); glTexImage2D(GL_TEXTURE_2D, mipmap, intf, width, height, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, data); } - else - #endif + else + #endif if (trans == PNG_SOLID || trans == PNG_ALPHA || color == PNG_COLOR_TYPE_RGB_ALPHA || color == PNG_COLOR_TYPE_GRAY_ALPHA) { GLenum glformat; GLint glcomponent; @@ -530,8 +530,8 @@ int APIENTRY pngLoadF(FILE *fp, int mipmap, int trans, pngInfo *pinfo) { } if (mipmap == PNG_BUILDMIPMAPS) - Build2DMipmaps(glcomponent, width, height, glformat, data, 1); - else if (mipmap == PNG_SIMPLEMIPMAPS) + Build2DMipmaps(glcomponent, width, height, glformat, data, 1); + else if (mipmap == PNG_SIMPLEMIPMAPS) Build2DMipmaps(glcomponent, width, height, glformat, data, 0); else glTexImage2D(GL_TEXTURE_2D, mipmap, glcomponent, width, height, 0, glformat, GL_UNSIGNED_BYTE, data); @@ -629,18 +629,18 @@ int APIENTRY pngLoadF(FILE *fp, int mipmap, int trans, pngInfo *pinfo) { #undef FOREND #undef ALPHA - if (mipmap == PNG_BUILDMIPMAPS) + if (mipmap == PNG_BUILDMIPMAPS) Build2DMipmaps(4, width, height, GL_RGBA, data2, 1); - else if (mipmap == PNG_SIMPLEMIPMAPS) - Build2DMipmaps(4, width, height, GL_RGBA, data2, 0); + else if (mipmap == PNG_SIMPLEMIPMAPS) + Build2DMipmaps(4, width, height, GL_RGBA, data2, 0); else glTexImage2D(GL_TEXTURE_2D, mipmap, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data2); free(data2); } - - glPixelStorei(GL_PACK_ALIGNMENT, pack); - glPixelStorei(GL_UNPACK_ALIGNMENT, unpack); + + glPixelStorei(GL_PACK_ALIGNMENT, pack); + glPixelStorei(GL_UNPACK_ALIGNMENT, unpack); } /* OpenGL end */ png_read_end(png, endinfo); @@ -703,7 +703,7 @@ void APIENTRY pngSetViewingGamma(double viewingGamma) { screenGamma = 2.2; } } - -void APIENTRY pngSetStandardOrientation(int standardorientation) { - StandardOrientation = standardorientation; -} + +void APIENTRY pngSetStandardOrientation(int standardorientation) { + StandardOrientation = standardorientation; +} -- 2.11.4.GIT