예제 #1
0
static void
create_8bit_images(const char* logoBaseName, int logoWidth, int logoHeight,
	png_bytep* logoRowPtrs, const char* iconsBaseName, int iconsWidth,
	int iconsHeight, png_bytep* iconsRowPtrs)
{
	// Generate 8-bit palette
	BColorQuantizer quantizer(256, 8);
	quantizer.ProcessImage(logoRowPtrs, logoWidth, logoHeight);
	quantizer.ProcessImage(iconsRowPtrs, iconsWidth, iconsHeight);

	RGBA palette[256];
	quantizer.GetColorTable(palette);

	// convert 24-bit logo image to 8-bit indexed color
	uint8* logoIndexedImageRows[logoHeight];
	for (int y = 0; y < logoHeight; y++) {
		logoIndexedImageRows[y] = new uint8[logoWidth];
		for (int x = 0; x < logoWidth; x++)	{
			logoIndexedImageRows[y][x] = nearest_color(&logoRowPtrs[y][x*3],
				palette);
		}
	}

	// convert 24-bit icons image to 8-bit indexed color
	uint8* iconsIndexedImageRows[iconsHeight];
	for (int y = 0; y < iconsHeight; y++) {
		iconsIndexedImageRows[y] = new uint8[iconsWidth];
		for (int x = 0; x < iconsWidth; x++)	{
			iconsIndexedImageRows[y][x] = nearest_color(&iconsRowPtrs[y][x*3],
				palette);
		}
	}


	fprintf(sOutput, "#ifndef __BOOTSPLASH_KERNEL__\n");

	// write the 8-bit color palette
	fprintf(sOutput, "static const uint8 k8BitPalette[] = {\n");
	for (int c = 0; c < 256; c++) {
		fprintf(sOutput, "\t0x%x, 0x%x, 0x%x,\n",
			palette[c].r, palette[c].g, palette[c].b);
	}
	fprintf(sOutput, "\t};\n\n");

	// write the 8-bit images
	write_8bit_image(logoBaseName, logoWidth, logoHeight, logoIndexedImageRows);
	write_8bit_image(iconsBaseName, iconsWidth, iconsHeight,
		iconsIndexedImageRows);

	fprintf(sOutput, "#endif\n\n");

	// free memory
	for (int y = 0; y < logoHeight; y++)
		delete[] logoIndexedImageRows[y];

	for (int y = 0; y < iconsHeight; y++)
		delete[] iconsIndexedImageRows[y];
}
예제 #2
0
파일: dfimcomp.c 프로젝트: schwehr/hdf4
PRIVATE     VOID
map(int blocks)
{
    int         i, k;
    uint8       r, g, b;

    for (i = 0; i < (2 * blocks); i++)
      {
          k = indx(color_pt[i].c[RED], color_pt[i].c[GREEN], color_pt[i].c[BLUE]);

          if (trans[k] == -1)
            {
                r = (uint8) (color_pt[i].c[RED] << 3);
                g = (uint8) (color_pt[i].c[GREEN] << 3);
                b = (uint8) (color_pt[i].c[BLUE] << 3);
                trans[k] = nearest_color(r, g, b);
                /*
                   printf("map: %d %d %d mapped to %d %d %d\n", r, g, b, new_pal[tran
                   s[k]*3
                   ],
                   new_pal[trans[k]*3+1], new_pal[trans[k]*3+2]);
                 */
            }
      }
}   /* end of map */
예제 #3
0
/**
 * Converts a string in the form XXXXX to the 256 color with the nearest value.
 *
 * @param color pointer to an array of chars holding the color int he form ABCDEF
 */
int hex_to_256(char *color)
{
    int color_result;
    int color_error;
    int gray_result;
    int gray_error;

    /* Check if input is valid */
    for (int i = 0; i < 6; i++) {
        if (!isxdigit(toupper(color[i]))) {
            return -1;
        }
    }

    nearest_color(color, &color_result, &color_error);
    nearest_grayscale(color, &gray_result, &gray_error);

    /* Decide whether to go for a grayscale or for a color */
    if (color_error < gray_error) {
        return color_result;
    } else {
        return gray_result;
    }
}