[MPlayer-cvslog] CVS: main/libvo gl_common.c, 1.27, 1.28 gl_common.h, 1.17, 1.18
Reimar Döffinger CVS
syncmail at mplayerhq.hu
Sun Sep 25 18:30:02 CEST 2005
CVS change done by Reimar Döffinger CVS
Update of /cvsroot/mplayer/main/libvo
In directory mail:/var2/tmp/cvs-serv27228
Modified Files:
gl_common.c gl_common.h
Log Message:
support loading a texture from a PPM file
Index: gl_common.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/gl_common.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- gl_common.c 25 Sep 2005 16:17:03 -0000 1.27
+++ gl_common.c 25 Sep 2005 16:30:00 -0000 1.28
@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <ctype.h>
#include <math.h>
#include "gl_common.h"
@@ -328,6 +329,65 @@
}
/**
+ * \brief skips whitespace and comments
+ * \param f file to read from
+ */
+static void ppm_skip(FILE *f) {
+ int c, comment = 0;
+ do {
+ c = fgetc(f);
+ if (c == '#')
+ comment = 1;
+ if (c == '\n')
+ comment = 0;
+ } while (c != EOF && (isspace(c) || comment));
+ if (c != EOF)
+ ungetc(c, f);
+}
+
+/**
+ * \brief creates a texture from a PPM file
+ * \param target texture taget, usually GL_TEXTURE_2D
+ * \param fmt internal texture format
+ * \param filter filter used for scaling, e.g. GL_LINEAR
+ * \param f file to read PPM from
+ * \param width [out] width of texture
+ * \param height [out] height of texture
+ * \param maxval [out] maxval value from PPM file
+ * \return 0 on error, 1 otherwise
+ */
+int glCreatePPMTex(GLenum target, GLenum fmt, GLint filter,
+ FILE *f, int *width, int *height, int *maxval) {
+ int w, h, m, val;
+ char *data;
+ ppm_skip(f);
+ if (fgetc(f) != 'P' || fgetc(f) != '6')
+ return 0;
+ ppm_skip(f);
+ if (fscanf(f, "%i", &w) != 1)
+ return 0;
+ ppm_skip(f);
+ if (fscanf(f, "%i", &h) != 1)
+ return 0;
+ ppm_skip(f);
+ if (fscanf(f, "%i", &m) != 1)
+ return 0;
+ val = fgetc(f);
+ if (!isspace(val))
+ return 0;
+ data = (char *)malloc(w * h * 3);
+ if (fread(data, w * 3, h, f) != h)
+ return 0;
+ glCreateClearTex(target, fmt, filter, w, h, 0);
+ glUploadTex(target, GL_RGB, GL_UNSIGNED_BYTE, data, w * 3, 0, 0, w, h, 0);
+ free(data);
+ if (width) *width = w;
+ if (height) *height = h;
+ if (maxval) *maxval = m;
+ return 1;
+}
+
+/**
* \brief return the number of bytes oer pixel for the given format
* \param format OpenGL format
* \param type OpenGL type
Index: gl_common.h
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/gl_common.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- gl_common.h 25 Sep 2005 16:07:54 -0000 1.17
+++ gl_common.h 25 Sep 2005 16:30:00 -0000 1.18
@@ -141,6 +141,8 @@
int glFmt2bpp(GLenum format, GLenum type);
void glCreateClearTex(GLenum target, GLenum fmt, GLint filter,
int w, int h, unsigned char val);
+int glCreatePPMTex(GLenum target, GLenum fmt, GLint filter,
+ FILE *f, int *width, int *height, int *maxval);
void glUploadTex(GLenum target, GLenum format, GLenum type,
const char *data, int stride,
int x, int y, int w, int h, int slice);
More information about the MPlayer-cvslog
mailing list