static void ppmTo256ColorPcx(pixel ** const pixels, int const cols, int const rows, struct pcxCmapEntry const pcxcmap[], int const colors, colorhash_table const cht, unsigned int const xPos, unsigned int const yPos) { int row; unsigned int i; unsigned char *rawrow; rawrow = (unsigned char *)pm_allocrow(cols, sizeof(unsigned char)); /* 8 bits per pixel, 1 plane */ write_header(stdout, cols, rows, 8, 1, NULL, xPos, yPos); for (row = 0; row < rows; ++row) { int col; for (col = 0; col < cols; ++col) rawrow[col] = indexOfColor(cht, pixels[row][col]); PCXEncode(stdout, rawrow, cols); } Putbyte(PCX_256_COLORS, stdout); for (i = 0; i < MAXCOLORS; ++i) { Putbyte(pcxcmap[i].r, stdout); Putbyte(pcxcmap[i].g, stdout); Putbyte(pcxcmap[i].b, stdout); } pm_freerow((void*)rawrow); }
static void ppmTo16ColorPcx(pixel ** const pixels, int const cols, int const rows, struct pcxCmapEntry const pcxcmap[], int const colors, colorhash_table const cht, bool const packbits, unsigned int const planesRequested, unsigned int const xPos, unsigned int const yPos) { int Planes, BytesPerLine, BitsPerPixel; unsigned char *indexRow; /* malloc'ed */ /* indexRow[x] is the palette index of the pixel at column x of the row currently being processed */ unsigned char *planesrow; /* malloc'ed */ /* This is the input for a single row to the compressor */ int row; if (packbits) { Planes = 1; if (colors > 4) BitsPerPixel = 4; else if (colors > 2) BitsPerPixel = 2; else BitsPerPixel = 1; } else { BitsPerPixel = 1; if (planesRequested) Planes = planesRequested; else { if (colors > 8) Planes = 4; else if (colors > 4) Planes = 3; else if (colors > 2) Planes = 2; else Planes = 1; } } BytesPerLine = ((cols * BitsPerPixel) + 7) / 8; MALLOCARRAY_NOFAIL(indexRow, cols); MALLOCARRAY_NOFAIL(planesrow, BytesPerLine); write_header(stdout, cols, rows, BitsPerPixel, Planes, pcxcmap, xPos, yPos); for (row = 0; row < rows; ++row) { int col; for (col = 0; col < cols; ++col) indexRow[col] = indexOfColor(cht, pixels[row][col]); if (packbits) { PackBits(indexRow, cols, planesrow, BitsPerPixel); PCXEncode(stdout, planesrow, BytesPerLine); } else { unsigned int plane; for (plane = 0; plane < Planes; ++plane) { extractPlane(indexRow, cols, planesrow, plane); PCXEncode(stdout, planesrow, BytesPerLine); } } } free(planesrow); free(indexRow); }
bool Combinaison::contains(tColor color) const noexcept { return (indexOfColor(color) != -1); }