inline gfx::Color from_allegro(int color_depth, int color)
{
  return gfx::rgba(
    getr_depth(color_depth, color),
    getg_depth(color_depth, color),
    getb_depth(color_depth, color),
    // This condition is here because geta_depth() returns 0 if color depth != 32
    (color_depth == 32 ? geta32(color): 255));
}
Exemple #2
0
void IAGSEngine::GetRawColorComponents(int32 coldepth, int32 color, int32 *red, int32 *green, int32 *blue, int32 *alpha) {
  if (red)
    *red = getr_depth(coldepth, color);
  if (green)
    *green = getg_depth(coldepth, color);
  if (blue)
    *blue = getb_depth(coldepth, color);
  if (alpha)
    *alpha = geta_depth(coldepth, color);
}
Exemple #3
0
/* getg:
 *  Extracts the green component (ranging 0-255) from a pixel in the format
 *  being used by the current video mode.
 */
int getg(int c)
{
   return getg_depth(_color_depth, c);
}
Exemple #4
0
/* save_pcx:
 *  Writes a bitmap into a PCX file, using the specified palette (this
 *  should be an array of at least 256 RGB structures).
 */
int save_pcx (FILE* f, MYBITMAP *bmp, RGB *pal)
{
    FILE *f;
    PALETTE tmppal;
    int c;
    int x, y;
    int runcount;
    int depth, planes;
    char runchar;
    char ch;

    if (!pal) {
        get_palette(tmppal);
        pal = tmppal;
    }

    f = fp_fopen(filename, F_WRITE);
    if (!f)
        return *allegro_errno;

    depth = bitmap_color_depth(bmp);
    if (depth == 8)
        planes = 1;
    else
        planes = 3;

    fp_putc(10, f);                      /* manufacturer */
    fp_putc(5, f);                       /* version */
    fp_putc(1, f);                       /* run length encoding  */
    fp_putc(8, f);                       /* 8 bits per pixel */
    fp_iputw(0, f);                      /* xmin */
    fp_iputw(0, f);                      /* ymin */
    fp_iputw(bmp->w-1, f);               /* xmax */
    fp_iputw(bmp->h-1, f);               /* ymax */
    fp_iputw(320, f);                    /* HDpi */
    fp_iputw(200, f);                    /* VDpi */

    for (c=0; c<16; c++) {
        fp_putc(_rgb_scale_6[pal[c].r], f);
        fp_putc(_rgb_scale_6[pal[c].g], f);
        fp_putc(_rgb_scale_6[pal[c].b], f);
    }

    fp_putc(0, f);                       /* reserved */
    fp_putc(planes, f);                  /* one or three color planes */
    fp_iputw(bmp->w, f);                 /* number of bytes per scanline */
    fp_iputw(1, f);                      /* color palette */
    fp_iputw(bmp->w, f);                 /* hscreen size */
    fp_iputw(bmp->h, f);                 /* vscreen size */
    for (c=0; c<54; c++)                   /* filler */
        fp_putc(0, f);

    for (y=0; y<bmp->h; y++) {             /* for each scanline... */
        runcount = 0;
        runchar = 0;
        for (x=0; x<bmp->w*planes; x++) {   /* for each pixel... */
            if (depth == 8) {
                ch = getpixel(bmp, x, y);
            }
            else {
                if (x<bmp->w) {
                    c = getpixel(bmp, x, y);
                    ch = getr_depth(depth, c);
                }
                else if (x<bmp->w*2) {
                    c = getpixel(bmp, x-bmp->w, y);
                    ch = getg_depth(depth, c);
                }
                else {
                    c = getpixel(bmp, x-bmp->w*2, y);
                    ch = getb_depth(depth, c);
                }
            }
            if (runcount==0) {
                runcount = 1;
                runchar = ch;
            }
            else {
                if ((ch != runchar) || (runcount >= 0x3f)) {
                    if ((runcount > 1) || ((runchar & 0xC0) == 0xC0))
                        fp_putc(0xC0 | runcount, f);
                    fp_putc(runchar,f);
                    runcount = 1;
                    runchar = ch;
                }
                else
                    runcount++;
            }
        }
        if ((runcount > 1) || ((runchar & 0xC0) == 0xC0))
            fp_putc(0xC0 | runcount, f);
        fp_putc(runchar,f);
    }

    if (depth == 8) {                      /* 256 color palette */
        fp_putc(12, f);

        for (c=0; c<256; c++) {
            fp_putc(_rgb_scale_6[pal[c].r], f);
            fp_putc(_rgb_scale_6[pal[c].g], f);
            fp_putc(_rgb_scale_6[pal[c].b], f);
        }
    }

    fp_fclose(f);
    return *allegro_errno;
}