Пример #1
0
static void
remap(xel **       const xels,
      unsigned int const cols,
      unsigned int const rows,
      xelval       const maxval,
      int          const format,
      bool         const monoOnly,
      const gray * const lumamap) {
/*----------------------------------------------------------------------------
   Update the array 'xels' to have the new intensities.
-----------------------------------------------------------------------------*/
    switch (PNM_FORMAT_TYPE(format)) {
    case PPM_TYPE: {
        unsigned int row;
        for (row = 0; row < rows; ++row) {
            unsigned int col;
            for (col = 0; col < cols; ++col) {
                xel const thisXel = xels[row][col];
                if (monoOnly && PPM_ISGRAY(thisXel)) {
                    /* Leave this pixel alone */
                } else {
                    struct hsv hsv;
                    xelval iv;

                    hsv = ppm_hsv_from_color(thisXel, maxval);
                    iv = MIN(maxval, ROUNDU(hsv.v * maxval));
                    
                    hsv.v = MIN(1.0, 
                                ((double) lumamap[iv]) / ((double) maxval));

                    xels[row][col] = ppm_color_from_hsv(hsv, maxval);
                }
            }
        }
    }
    break;

    case PBM_TYPE:
    case PGM_TYPE: {
        unsigned int row;
        for (row = 0; row < rows; ++row) {
            unsigned int col;
            for (col = 0; col < cols; ++col)
                PNM_ASSIGN1(xels[row][col],
                            lumamap[PNM_GET1(xels[row][col])]);
        }
    }
    break;
    }
}
Пример #2
0
static void
matchBk(pixel     const color,
        pixval    const maxval,
        fzLog (* const bkMatchP)[BKCOLOR_COUNT]) {

    struct hsv const hsv = ppm_hsv_from_color(color, maxval);

    fzLog const satVeryLow = satIsVeryLow(hsv.s);
    fzLog const satLow     = satIsLow(hsv.s);
    fzLog const satMedium  = satIsMedium(hsv.s);
    fzLog const satHigh    = satIsHigh(hsv.s);

    fzLog const valVeryLow  = valIsVeryLow(hsv.v);
    fzLog const valLow      = valIsLow(hsv.v);
    fzLog const valMedium   = valIsMedium(hsv.v);
    fzLog const valHigh     = valIsHigh(hsv.v);
    fzLog const valVeryHigh = valIsVeryHigh(hsv.v);

    fzLog const hueAround000 = hueIsAround000(hsv.h);
    fzLog const hueAround015 = hueIsAround015(hsv.h);
    fzLog const hueAround030 = hueIsAround030(hsv.h);
    fzLog const hueAround060 = hueIsAround060(hsv.h);
    fzLog const hueAround120 = hueIsAround120(hsv.h);
    fzLog const hueAround180 = hueIsAround180(hsv.h);
    fzLog const hueAround270 = hueIsAround270(hsv.h);
    fzLog const hueAround320 = hueIsAround320(hsv.h);
    fzLog const hueAround360 = hueIsAround360(hsv.h);

    (*bkMatchP)[BKCOLOR_BLACK]  =
        fzAnd(fzOr(satVeryLow, satLow), fzOr(valVeryLow, valLow));

    (*bkMatchP)[BKCOLOR_GRAY]   =
        fzAnd(satVeryLow, fzAnd(fzNot(valVeryLow), fzNot(valVeryHigh)));

    (*bkMatchP)[BKCOLOR_WHITE]  =
        fzAnd(satVeryLow, valVeryHigh);
    
    (*bkMatchP)[BKCOLOR_RED]    =
        fzAnd(fzAnd(fzOr(hueAround000, hueAround360), fzNot(satVeryLow)),
              fzOr(valMedium, valHigh)
             );

    (*bkMatchP)[BKCOLOR_ORANGE] =
        fzAnd(fzAnd(hueAround030, fzOr(satMedium, satHigh)),
              fzOr(fzOr(valMedium, valHigh), valVeryHigh)
             );

    (*bkMatchP)[BKCOLOR_YELLOW] =
        fzAnd(fzAnd(hueAround060, fzOr(satMedium, satHigh)),
              fzOr(valHigh, valVeryHigh)
             );

    (*bkMatchP)[BKCOLOR_GREEN]  =
        fzAnd(fzAnd(hueAround120, fzOr(satMedium, satHigh)),
              fzAnd(fzNot(valVeryLow), fzNot(valLow))
             );

    (*bkMatchP)[BKCOLOR_BLUE]   =
        fzAnd(fzAnd(hueAround180, fzNot(satVeryLow)),
              fzNot(valVeryLow)
             );

    (*bkMatchP)[BKCOLOR_VIOLET] =
        fzAnd(fzAnd(hueAround270, fzOr(satMedium, satHigh)),
              fzOr(valMedium, valHigh)
             );

    (*bkMatchP)[BKCOLOR_PURPLE] =
        fzAnd(fzAnd(hueAround320, fzOr(satMedium, satHigh)),
              fzOr(valMedium, valHigh)
             );

    (*bkMatchP)[BKCOLOR_BROWN]  =
	fzOr(
             fzAnd(fzOr(hueAround015, hueAround360),
                   fzAnd(fzNot(satVeryLow), fzOr(valLow, valMedium))),
             fzAnd(hueAround015, satLow)
	    );
}