summaryrefslogtreecommitdiff
path: root/progs/samples/rgbtoppm.c
diff options
context:
space:
mode:
Diffstat (limited to 'progs/samples/rgbtoppm.c')
-rw-r--r--progs/samples/rgbtoppm.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/progs/samples/rgbtoppm.c b/progs/samples/rgbtoppm.c
index dcb74228df..403578ef42 100644
--- a/progs/samples/rgbtoppm.c
+++ b/progs/samples/rgbtoppm.c
@@ -3,6 +3,7 @@
/* texload is a simplistic routine for reading an SGI .rgb image file. */
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -25,7 +26,7 @@ typedef struct _ImageRec {
int *rowSize;
} ImageRec;
-void
+static void
rgbtorgb(unsigned char *r,unsigned char *g,unsigned char *b,unsigned char *l,int n) {
while(n--) {
l[0] = r[0];
@@ -72,6 +73,7 @@ static ImageRec *ImageOpen(char *fileName)
ImageRec *image;
int swapFlag;
int x;
+ int result;
endianTest.testWord = 1;
if (endianTest.testByte[0] == 1) {
@@ -90,7 +92,8 @@ static ImageRec *ImageOpen(char *fileName)
return NULL;
}
- fread(image, 1, 12, image->file);
+ result = fread(image, 1, 12, image->file);
+ assert(result == 12);
if (swapFlag) {
ConvertShort(&image->imagic, 1);
@@ -117,8 +120,10 @@ static ImageRec *ImageOpen(char *fileName)
}
image->rleEnd = 512 + (2 * x);
fseek(image->file, 512, SEEK_SET);
- fread(image->rowStart, 1, x, image->file);
- fread(image->rowSize, 1, x, image->file);
+ result = fread(image->rowStart, 1, x, image->file);
+ assert(result == x);
+ result = fread(image->rowSize, 1, x, image->file);
+ assert(result == x);
if (swapFlag) {
ConvertUint(image->rowStart, x/(int) sizeof(unsigned));
ConvertUint((unsigned *)image->rowSize, x/(int) sizeof(int));
@@ -138,11 +143,13 @@ static void
ImageGetRow(ImageRec *image, unsigned char *buf, int y, int z) {
unsigned char *iPtr, *oPtr, pixel;
int count;
+ int result;
if ((image->type & 0xFF00) == 0x0100) {
fseek(image->file, (long) image->rowStart[y+z*image->ysize], SEEK_SET);
- fread(image->tmp, 1, (unsigned int)image->rowSize[y+z*image->ysize],
- image->file);
+ result = fread(image->tmp, 1, (unsigned int)image->rowSize[y+z*image->ysize],
+ image->file);
+ assert(result == (unsigned int)image->rowSize[y+z*image->ysize]);
iPtr = image->tmp;
oPtr = buf;
@@ -166,11 +173,13 @@ ImageGetRow(ImageRec *image, unsigned char *buf, int y, int z) {
} else {
fseek(image->file, 512+(y*image->xsize)+(z*image->xsize*image->ysize),
SEEK_SET);
- fread(buf, 1, image->xsize, image->file);
+ result = fread(buf, 1, image->xsize, image->file);
+ assert(result == image->xsize);
}
}
-GLubyte *
+#if 0
+static GLubyte *
read_alpha_texture(char *name, int *width, int *height)
{
unsigned char *base, *lptr;
@@ -199,8 +208,9 @@ read_alpha_texture(char *name, int *width, int *height)
return (unsigned char *) base;
}
+#endif
-GLubyte *
+static GLubyte *
read_rgb_texture(char *name, int *width, int *height)
{
unsigned char *base, *ptr;
@@ -261,7 +271,8 @@ read_rgb_texture(char *name, int *width, int *height)
int main(int argc, char **argv)
{
- int width, height;
+ int width = 0;
+ int height = 0;
GLubyte *data;
char buff[32];
int n;