/* * expand.c -- expand packed pixel to rgb * (C)Copyright 1998 by Hiroshi Takekawa * This is part of Enfle. * * Last Modified: Sun Sep 19 02:43:27 1999. * $Id: expand.c,v 1.6 1999/09/18 18:39:50 sian Exp $ * * Enfle is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Enfle is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include "enfle.h" #include "expand.h" unsigned char * expand_mono_index(Image *p) { unsigned char *s = p->image; unsigned char c = 0, *d, *dest; int x, y, b; if ((d = dest = malloc(p->width * p->height)) == NULL) return NULL; for (y = 0; y < p->height; y++) { b = 0; for (x = 0; x < p->width; x++, b = (b + 1) & 7) { if (b == 0) c = *s++; *d++ = (c & 0x80) ? 1 : 0; c <<= 1; } } p->colormap[0][0] = p->colormap[0][1] = p->colormap[0][2] = 255; p->colormap[1][0] = p->colormap[1][1] = p->colormap[1][2] = 0; return dest; } unsigned char * expand_gray_index(Image *p) { int i; for (i = 0; i < 256; i++) p->colormap[i][0] = p->colormap[i][1] = p->colormap[i][2] = i; return p->image; } unsigned char * expand_index_rgb24(Image *p) { int i, j; unsigned char *s, *d, *dest; s = p->image; if ((d = dest = malloc(p->width * p->height * 3)) == NULL) return NULL; for (i = 0; i < p->width * p->height; i++) { j = *s++; *d++ = p->colormap[j][0]; *d++ = p->colormap[j][1]; *d++ = p->colormap[j][2]; } return dest; } unsigned char * expand_rgb16_rgb24(Image *p) { int i; short *s = (short int *)p->image; unsigned char *d, *dest; if ((d = dest = malloc(p->width * p->height * 3)) == NULL) return NULL; for (i = 0; i < p->width * p->height; i++) { *d++ = (*s & RED_MASK) >> 8; *d++ = (*s & GREEN_MASK) >> 3; *d++ = (*s & BLUE_MASK) << 3; s++; } return dest; }