Example #1
0
/* save_hicolour:
 *  Core save routine for 15/16 bpp images, by Martijn Versteegh.
 */
static int save_hicolour(png_structp png_ptr, BITMAP *bmp, int depth)
{
    unsigned char *row, *p;
    int i, j, c;

    row = malloc(bmp->w * 3);
    if (!row)
	return 0;

    for (i=0; i<bmp->h; i++) {
	p = row;
        for (j = 0; j < bmp->w; j++) {
            c = getpixel(bmp, j, i);
            if (depth == 15) {
		*p++ = getr15(c);
		*p++ = getg15(c);
		*p++ = getb15(c);
            }
	    else {
		*p++ = getr16(c);
		*p++ = getg16(c);
		*p++ = getb16(c);
            }
        }

        png_write_row(png_ptr, row);
    }

    free(row);

    return 1;
}
Example #2
0
/* save_rgb:
 *  Core save routine for 15/16/24 bpp images (original by Martijn Versteegh).
 */
static int save_rgb(png_structp png_ptr, BITMAP *bmp)
{
    AL_CONST int depth = bitmap_color_depth(bmp);
    unsigned char *rowdata;
    int y, x;

    ASSERT(depth == 15 || depth == 16 || depth == 24);

    rowdata = (unsigned char *)malloc(bmp->w * 3);
    if (!rowdata)
	return 0;

    for (y=0; y<bmp->h; y++) {
	unsigned char *p = rowdata;

	if (depth == 15) {
	    for (x = 0; x < bmp->w; x++) {
		int c = getpixel(bmp, x, y);
		*p++ = getr15(c);
		*p++ = getg15(c);
		*p++ = getb15(c);
	    }
	}
	else if (depth == 16) {
	    for (x = 0; x < bmp->w; x++) {
		int c = getpixel(bmp, x, y);
		*p++ = getr16(c);
		*p++ = getg16(c);
		*p++ = getb16(c);
	    }
	}
	else { /* depth == 24 */
	    for (x = 0; x < bmp->w; x++) {
		int c = getpixel(bmp, x, y);
		*p++ = getr24(c);
		*p++ = getg24(c);
		*p++ = getb24(c);
	    }
	}

	png_write_row(png_ptr, rowdata);
    }

    free(rowdata);

    return 1;
}
Example #3
0
/* getg_depth:
 *  Extracts the green component (ranging 0-255) from a pixel in the format
 *  being used by the specified color depth.
 */
int getg_depth(int color_depth, int c)
{
   switch (color_depth) {

      case 8:
	 return getg8(c);

      case 15:
	 return getg15(c);

      case 16:
	 return getg16(c);

      case 24:
	 return getg24(c);

      case 32:
	 return getg32(c);
   }

   return 0;
}