Referência do Arquivo /home/carolina/workspace/spvolren_cpu/ppm.h

Vá para o código-fonte deste arquivo.

Estruturas de Dados

struct  PPMFile

Funções

void ppmRead (char *filename, PPMFile *ppmFile)
void ppmWrite (char *filename, PPMFile *ppmFile)

Funções

void ppmRead ( char *  filename,
PPMFile ppmFile 
)

Definição na linha 59 do arquivo ppm.c.

00060 {
00061         char token[100], msg[100];
00062         int dataSize;
00063         FILE *fp;
00064         
00065         if (! (fp = fopen(filename, "rb"))) {
00066                 sprintf(msg, "opening image file \"%s\" failed", filename);
00067                 perror(msg);
00068                 exit(1);
00069         }
00070 
00071         /* Read magic number */
00072         readToken(fp, token);
00073         if (strcmp(MAGIC_NUMBER, token)) {
00074                 fprintf(stderr, "invalid magic number: %s\n", token);
00075                 exit(1);
00076         }
00077 
00078         /* Read dimensions */
00079         readToken(fp, token);
00080         if (sscanf(token, "%i", &ppmFile->width) != 1) {
00081                 fprintf(stderr, "invalid width: %s\n", token);
00082                 exit(1);
00083         }
00084         readToken(fp, token);
00085         if (sscanf(token, "%i", &ppmFile->height) != 1) {
00086                 fprintf(stderr, "invalid height: %s\n", token);
00087                 exit(1);
00088         }
00089 
00090         /* Allocate memory for image data */
00091         dataSize = ppmFile->width * ppmFile->height * 3;
00092         if (! (ppmFile->data = (unsigned char *)malloc(dataSize))) {
00093                 fprintf(stderr, "not enough memory for image data\n");
00094                 exit(1);
00095         }
00096 
00097         /* Read maximum value */
00098         readToken(fp, token);
00099         if (sscanf(token, "%i", &ppmFile->maxVal) != 1) {
00100                 fprintf(stderr, "invalid maximum value: %s\n", token);
00101                 exit(1);
00102         }
00103 
00104         /* Read image data */
00105         if (fread(ppmFile->data, dataSize, 1, fp) != 1) {
00106                 perror("reading image data failed");
00107                 exit(1);
00108         }
00109 
00110         fclose(fp);
00111 }

void ppmWrite ( char *  filename,
PPMFile ppmFile 
)

Definição na linha 113 do arquivo ppm.c.

00114 {
00115         int i, dataSize, maxVal;
00116         FILE *fp;
00117 
00118         if (! (fp = fopen(filename, "wb")) == -1) {
00119                 perror("opening image file failed");
00120                 exit(1);
00121         }
00122 
00123         /* Write magic number */
00124         fprintf(fp, "%s\n", MAGIC_NUMBER);
00125 
00126         /* Write dimensions */
00127         fprintf(fp, "%i %i\n", ppmFile->width, ppmFile->height); 
00128 
00129         /* Write maximum value */
00130         dataSize = ppmFile->width * ppmFile->height * 3;
00131         maxVal = 0;
00132         for (i = 0; i < dataSize; i++) {
00133                 if (ppmFile->data[i] > maxVal) {
00134                         maxVal = ppmFile->data[i];
00135                 }
00136         }
00137         fprintf(fp, "%i\n", maxVal);
00138 
00139         /* Write image data */
00140         if (fwrite(ppmFile->data, dataSize, 1, fp) != 1) {
00141                 fprintf(stderr, "writing image data failed\n");
00142                 exit(1);
00143         }
00144 
00145         fclose(fp);
00146 }

 Todos Estruturas de Dados Arquivos Funções Variáveis Definições de Tipos Enumerações Valores enumerados Definições e Macros

Gerado em Sat Dec 12 01:59:33 2009 para Carolina Simões Gomes (RA042533). Estudo de um framework para Raycasting em GPU por  doxygen 1.6.1