/* * rdcolmap.c * * Copyright (C) 1994-1996, Thomas G. Lane. * This file is part of the Independent JPEG Group's software. * For conditions of distribution and use, see the accompanying README.ijg * file. * * This file implements djpeg's "-map file" switch. It reads a source image * and constructs a colormap to be supplied to the JPEG decompressor. * * Currently, these file formats are supported for the map file: * GIF: the contents of the GIF's global colormap are used. * PPM (either text or raw flavor): the entire file is read and * each unique pixel value is entered in the map. * Note that reading a large PPM file will be horrendously slow. * Typically, a PPM-format map file should contain just one pixel * of each desired color. Such a file can be extracted from an * ordinary image PPM file with ppmtomap(1). * * Rescaling a PPM that has a maxval unequal to MAXJSAMPLE is not * currently implemented. */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ /* Portions of this code are based on the PBMPLUS library, which is: ** ** Copyright (C) 1988 by Jef Poskanzer. ** ** Permission to use, copy, modify, and distribute this software and its ** documentation for any purpose and without fee is hereby granted, provided ** that the above copyright notice appear in all copies and that both that ** copyright notice and this permission notice appear in supporting ** documentation. This software is provided "as is" without express or ** implied warranty. */ /* * Add a (potentially) new color to the color map. */ LOCAL(void) add_map_entry(j_decompress_ptr cinfo, int R, int G, int B) { … } /* * Extract color map from a GIF file. */ LOCAL(void) read_gif_map(j_decompress_ptr cinfo, FILE *infile) { … } /* Support routines for reading PPM */ LOCAL(int) pbm_getc(FILE *infile) /* Read next char, skipping over any comments */ /* A comment/newline sequence is returned as a newline */ { … } LOCAL(unsigned int) read_pbm_integer(j_decompress_ptr cinfo, FILE *infile) /* Read an unsigned decimal integer from the PPM file */ /* Swallows one trailing character after the integer */ /* Note that on a 16-bit-int machine, only values up to 64k can be read. */ /* This should not be a problem in practice. */ { … } /* * Extract color map from a PPM file. */ LOCAL(void) read_ppm_map(j_decompress_ptr cinfo, FILE *infile) { … } /* * Main entry point from djpeg.c. * Input: opened input file (from file name argument on command line). * Output: colormap and actual_number_of_colors fields are set in cinfo. */ GLOBAL(void) read_color_map(j_decompress_ptr cinfo, FILE *infile) { … } #endif /* QUANT_2PASS_SUPPORTED */