Doxygen Source Code Documentation
rdcolmap.c File Reference
#include "cdjpeg.h"
Go to the source code of this file.
Functions | |
add_map_entry (j_decompress_ptr cinfo, int R, int G, int B) | |
read_gif_map (j_decompress_ptr cinfo, FILE *infile) | |
pbm_getc (FILE *infile) | |
read_pbm_integer (j_decompress_ptr cinfo, FILE *infile) | |
read_ppm_map (j_decompress_ptr cinfo, FILE *infile) | |
read_color_map (j_decompress_ptr cinfo, FILE *infile) |
Function Documentation
|
Definition at line 46 of file rdcolmap.c. References jpeg_decompress_struct::actual_number_of_colors, jpeg_decompress_struct::colormap, ERREXIT1, GETJSAMPLE, JSAMPROW, MAXJSAMPLE, and ncolors. Referenced by read_gif_map(), and read_ppm_map().
00047 { 00048 JSAMPROW colormap0 = cinfo->colormap[0]; 00049 JSAMPROW colormap1 = cinfo->colormap[1]; 00050 JSAMPROW colormap2 = cinfo->colormap[2]; 00051 int ncolors = cinfo->actual_number_of_colors; 00052 int index; 00053 00054 /* Check for duplicate color. */ 00055 for (index = 0; index < ncolors; index++) { 00056 if (GETJSAMPLE(colormap0[index]) == R && 00057 GETJSAMPLE(colormap1[index]) == G && 00058 GETJSAMPLE(colormap2[index]) == B) 00059 return; /* color is already in map */ 00060 } 00061 00062 /* Check for map overflow. */ 00063 if (ncolors >= (MAXJSAMPLE+1)) 00064 ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, (MAXJSAMPLE+1)); 00065 00066 /* OK, add color to map. */ 00067 colormap0[ncolors] = (JSAMPLE) R; 00068 colormap1[ncolors] = (JSAMPLE) G; 00069 colormap2[ncolors] = (JSAMPLE) B; 00070 cinfo->actual_number_of_colors++; 00071 } |
|
Definition at line 121 of file rdcolmap.c. Referenced by read_pbm_integer().
00124 { 00125 register int ch; 00126 00127 ch = getc(infile); 00128 if (ch == '#') { 00129 do { 00130 ch = getc(infile); 00131 } while (ch != '\n' && ch != EOF); 00132 } 00133 return ch; 00134 } |
|
Definition at line 231 of file rdcolmap.c. References jpeg_decompress_struct::colormap, ERREXIT, JERR_BAD_CMAP_FILE, JPOOL_IMAGE, MAXJSAMPLE, read_gif_map(), and read_ppm_map().
00232 { 00233 /* Allocate space for a color map of maximum supported size. */ 00234 cinfo->colormap = (*cinfo->mem->alloc_sarray) 00235 ((j_common_ptr) cinfo, JPOOL_IMAGE, 00236 (JDIMENSION) (MAXJSAMPLE+1), (JDIMENSION) 3); 00237 cinfo->actual_number_of_colors = 0; /* initialize map to empty */ 00238 00239 /* Read first byte to determine file format */ 00240 switch (getc(infile)) { 00241 case 'G': 00242 read_gif_map(cinfo, infile); 00243 break; 00244 case 'P': 00245 read_ppm_map(cinfo, infile); 00246 break; 00247 default: 00248 ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 00249 break; 00250 } 00251 } |
|
Definition at line 79 of file rdcolmap.c. References add_map_entry(), BITS_IN_JSAMPLE, ERREXIT, i, and JERR_BAD_CMAP_FILE. Referenced by read_color_map().
00080 { 00081 int header[13]; 00082 int i, colormaplen; 00083 int R, G, B; 00084 00085 /* Initial 'G' has already been read by read_color_map */ 00086 /* Read the rest of the GIF header and logical screen descriptor */ 00087 for (i = 1; i < 13; i++) { 00088 if ((header[i] = getc(infile)) == EOF) 00089 ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 00090 } 00091 00092 /* Verify GIF Header */ 00093 if (header[1] != 'I' || header[2] != 'F') 00094 ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 00095 00096 /* There must be a global color map. */ 00097 if ((header[10] & 0x80) == 0) 00098 ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 00099 00100 /* OK, fetch it. */ 00101 colormaplen = 2 << (header[10] & 0x07); 00102 00103 for (i = 0; i < colormaplen; i++) { 00104 R = getc(infile); 00105 G = getc(infile); 00106 B = getc(infile); 00107 if (R == EOF || G == EOF || B == EOF) 00108 ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 00109 add_map_entry(cinfo, 00110 R << (BITS_IN_JSAMPLE-8), 00111 G << (BITS_IN_JSAMPLE-8), 00112 B << (BITS_IN_JSAMPLE-8)); 00113 } 00114 } |
|
Definition at line 138 of file rdcolmap.c. References ERREXIT, JERR_BAD_CMAP_FILE, and pbm_getc(). Referenced by read_ppm_map().
00143 { 00144 register int ch; 00145 register unsigned int val; 00146 00147 /* Skip any leading whitespace */ 00148 do { 00149 ch = pbm_getc(infile); 00150 if (ch == EOF) 00151 ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 00152 } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); 00153 00154 if (ch < '0' || ch > '9') 00155 ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 00156 00157 val = ch - '0'; 00158 while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { 00159 val *= 10; 00160 val += ch - '0'; 00161 } 00162 return val; 00163 } |
|
Definition at line 171 of file rdcolmap.c. References add_map_entry(), c, ERREXIT, JERR_BAD_CMAP_FILE, MAXJSAMPLE, maxval, and read_pbm_integer(). Referenced by read_color_map().
00172 { 00173 int c; 00174 unsigned int w, h, maxval, row, col; 00175 int R, G, B; 00176 00177 /* Initial 'P' has already been read by read_color_map */ 00178 c = getc(infile); /* save format discriminator for a sec */ 00179 00180 /* while we fetch the remaining header info */ 00181 w = read_pbm_integer(cinfo, infile); 00182 h = read_pbm_integer(cinfo, infile); 00183 maxval = read_pbm_integer(cinfo, infile); 00184 00185 if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ 00186 ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 00187 00188 /* For now, we don't support rescaling from an unusual maxval. */ 00189 if (maxval != (unsigned int) MAXJSAMPLE) 00190 ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 00191 00192 switch (c) { 00193 case '3': /* it's a text-format PPM file */ 00194 for (row = 0; row < h; row++) { 00195 for (col = 0; col < w; col++) { 00196 R = read_pbm_integer(cinfo, infile); 00197 G = read_pbm_integer(cinfo, infile); 00198 B = read_pbm_integer(cinfo, infile); 00199 add_map_entry(cinfo, R, G, B); 00200 } 00201 } 00202 break; 00203 00204 case '6': /* it's a raw-format PPM file */ 00205 for (row = 0; row < h; row++) { 00206 for (col = 0; col < w; col++) { 00207 R = getc(infile); 00208 G = getc(infile); 00209 B = getc(infile); 00210 if (R == EOF || G == EOF || B == EOF) 00211 ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 00212 add_map_entry(cinfo, R, G, B); 00213 } 00214 } 00215 break; 00216 00217 default: 00218 ERREXIT(cinfo, JERR_BAD_CMAP_FILE); 00219 break; 00220 } 00221 } |