MCPcopy Index your code
hub / github.com/MapServer/MapServer / readPalette

Function readPalette

mapimageio.c:318–362  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

316}
317
318int readPalette(const char *palette, rgbaPixel *entries, unsigned int *nEntries, int useAlpha) {
319 FILE *stream = NULL;
320 char buffer[MS_BUFFER_LENGTH];
321 int r,g,b,a;
322 *nEntries = 0;
323
324 stream = fopen(palette, "r");
325 if(!stream) {
326 msSetError(MS_IOERR, "Error opening palette file %s.", "readPalette()", palette);
327 return MS_FAILURE;
328 }
329
330 while(fgets(buffer, MS_BUFFER_LENGTH, stream) && *nEntries<256)
331 { /* while there are colors to load */
332 if(buffer[0] == '#' || buffer[0] == '\n' || buffer[0] == '\r')
333 continue; /* skip comments and blank lines */
334 if(!useAlpha) {
335 if(3 != sscanf(buffer,"%d,%d,%d\n",&r,&g,&b)) {
336 msSetError(MS_MISCERR,"failed to parse color %d r,g,b triplet in line \"%s\" from file %s","readPalette()",*nEntries+1,buffer,palette);
337 return MS_FAILURE;
338 }
339 }
340 else {
341 if(4 != sscanf(buffer,"%d,%d,%d,%d\n",&r,&g,&b,&a)) {
342 msSetError(MS_MISCERR,"failed to parse color %d r,g,b,a quadruplet in line \"%s\" from file %s","readPalette()",*nEntries+1,buffer,palette);
343 return MS_FAILURE;
344 }
345 }
346 if(useAlpha && a != 255) {
347 double da = a/255.0;
348 entries[*nEntries].r = r * da;
349 entries[*nEntries].g = g * da;
350 entries[*nEntries].b = b * da;
351 entries[*nEntries].a = a;
352 } else {
353 entries[*nEntries].r = r;
354 entries[*nEntries].g = g;
355 entries[*nEntries].b = b;
356 entries[*nEntries].a = 255;
357 }
358 (*nEntries)++;
359 }
360 fclose(stream);
361 return MS_SUCCESS;
362}
363
364int saveAsPNG(mapObj *map,rasterBufferObj *rb, streamInfo *info, outputFormatObj *format) {
365 int force_pc256 = MS_FALSE;

Callers 1

saveAsPNGFunction · 0.85

Calls 1

msSetErrorFunction · 0.85

Tested by

no test coverage detected