-/* Load a modified version of PPM format with an extra byte for alpha */
-GLubyte *LoadPPM4(const char *filename, int *width, int *height, int *format)
-{
- char buff[1024];
- GLubyte *data;
- int sizeX, sizeY;
- FILE *fp;
- int maxval;
-
- fp = fopen(filename, "rb");
- if (!fp)
- {
- fprintf(stderr, "%s: unable to open file '%s'\n", progname, filename);
- return Generate_Image(width, height, format);
- }
-
- if (!fgets(buff, sizeof(buff), fp))
- {
- perror("Unable to read header filename\n");
- return Generate_Image(width, height, format);
- }
-
- if (buff[0] != '6' || buff[1] != 'P')
- {
- fprintf(stderr, "%s: Invalid image format (must be `6P')\n", progname);
- return Generate_Image(width, height, format);
- }
-
- do
- {
- fgets(buff, sizeof(buff), fp);
- }
- while (buff[0] == '#');
-
- if (sscanf(buff, "%d %d", &sizeX, &sizeY) != 2)
- {
- fprintf(stderr, "%s: error loading image `%s'\n", progname, filename);
- return Generate_Image(width, height, format);
- }
-
- if (fscanf(fp, "%d", &maxval) != 1)
- {
- fprintf(stderr, "%s: error loading image `%s'\n", progname, filename);
- return Generate_Image(width, height, format);
- }
-
- while (fgetc(fp) != '\n')
- ;
-
- data = (GLubyte *)malloc(4 * sizeX * sizeY);
- if (data == NULL)
- {
- fprintf(stderr, "%s: unable to allocate memory\n", progname);
- exit(1);
- }
-
- if (fread(data, 4 * sizeX, sizeY, fp) != sizeY)
- {
- fprintf(stderr, "%s: error loading image `%s'\n", progname, filename);
- return Generate_Image(width, height, format);
- }
-
- fclose(fp);
-
- *width = sizeX;
- *height = sizeY;
- *format = GL_RGBA;
- return data;
-}