/* * This is a very simple and experimental deinterlacer, * there is a lot of room for improvement here. * * (For example: Making it work) * */ gdImage *fx_deinterlace(gdImage *src, char *options) { int x, y; MSG("Deinterlacing image."); for(y = 1; y < gdImageSY(src) - 1; y += 2) { for(x = 0; x < gdImageSX(src); x++) { int c, cu, cd, d; c = gdImageGetPixel(src, x, y); cu = gdImageGetPixel(src, x, y - 1); cd = gdImageGetPixel(src, x, y + 1); /* Calculate the difference of the pixel (x,y) from * the average of it's neighbours above and below. */ d = 0xFF - abs(GREY(cu) - GREY(cd)); d = (abs(GREY(cu) - (0xFF - GREY(c)) - GREY(cd)) * d) / 0xFF; c = RGBMIX(c, RGBMIX(cu, cd, 128), d); gdImageSetPixel(src, x, y, c); } } return(src); }
/* * Greyscale images with less than 8 bits/sample are handled * with a table to avoid lots of shifts and masks. The table * is setup so that put*bwtile (below) can retrieve 8/bitspersample * pixel values simply by indexing into the table with one * number. */ static int makebwmap(TIFFRGBAImage* img) { TIFFRGBValue* Map = img->Map; int bitspersample = img->bitspersample; int nsamples = 8 / bitspersample; int i; uint32* p; img->BWmap = (uint32**) _TIFFmalloc( 256*sizeof (uint32 *)+(256*nsamples*sizeof(uint32))); if (img->BWmap == NULL) { TIFFError(TIFFFileName(img->tif), "No space for B&W mapping table"); return (0); } p = (uint32*)(img->BWmap + 256); for (i = 0; i < 256; i++) { TIFFRGBValue c; img->BWmap[i] = p; switch (bitspersample) { #define GREY(x) c = Map[x]; *p++ = PACK(c,c,c); case 1: GREY(i>>7); GREY((i>>6)&1); GREY((i>>5)&1); GREY((i>>4)&1); GREY((i>>3)&1); GREY((i>>2)&1); GREY((i>>1)&1); GREY(i&1); break; case 2: GREY(i>>6); GREY((i>>4)&3); GREY((i>>2)&3); GREY(i&3); break; case 4: GREY(i>>4); GREY(i&0xf); break; case 8: GREY(i); break; } #undef GREY } return (1); }
void CVisualizerScope::ClearBackground() { for (int y = 0; y < m_iHeight; ++y) { COLORREF col = GREY((unsigned char)(std::sinf((float(y) * 3.14f) / float(m_iHeight)) * 40.0f)); // // // for (int x = 0; x < m_iWidth; ++x) m_pBlitBuffer[y * m_iWidth + x] = col; } }
/* * Greyscale images with less than 8 bits/sample are handled * with a table to avoid lots of shifts and masks. The table * is setup so that put*bwtile (below) can retrieve 8/bitspersample_ * pixel values simply by indexing into the table with one * number. */ boolean TIFFRasterImpl::makebwmap(RGBvalue* Map) { register int i; int nsamples = 8 / bitspersample_; BWmap_ = (u_long **)malloc( 256*sizeof (u_long *)+(256*nsamples*sizeof(u_long)) ); if (BWmap_ == nil) { TIFFError(TIFFFileName(tif_), "No space for B&W mapping table"); return false; } register u_long* p = (u_long*)(BWmap_ + 256); for (i = 0; i < 256; i++) { BWmap_[i] = p; switch (bitspersample_) { register RGBvalue c; #define GREY(x) c = Map[x]; *p++ = PACK(c,c,c); case 1: GREY(i>>7); GREY((i>>6)&1); GREY((i>>5)&1); GREY((i>>4)&1); GREY((i>>3)&1); GREY((i>>2)&1); GREY((i>>1)&1); GREY(i&1); break; case 2: GREY(i>>6); GREY((i>>4)&3); GREY((i>>2)&3); GREY(i&3); break; case 4: GREY(i>>4); GREY(i&0xf); break; } #undef GREY } return true; }
gdImage *fx_greyscale(gdImage *src, char *options) { int x, y; MSG("Greyscaling image."); for(y = 0; y < gdImageSY(src); y++) for(x = 0; x < gdImageSX(src); x++) { uint8_t c = GREY(gdImageGetPixel(src, x, y)); gdImageSetPixel(src, x, y, RGB(c, c, c)); } return(src); }
/*luadoc @function GREY() Returns gray value which can be used in LCD functions @retval (number) a value that represents amount of *greyness* (from 0 to 15) */ static int luaGrey(lua_State *L) { int index = luaL_checkinteger(L, 1); lua_pushunsigned(L, GREY(index)); return 1; }
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR ** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES ** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, ** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS ** SOFTWARE. */ #include "Platform.h" #include "Scroller.h" #define GREY(_x) (((_x & 0xF8) << 8) | ((_x & 0xFC) << 3) | ((_x & 0xF8) >> 3)) extern const short _greys[8] PROGMEM; const short _greys[8] = { GREY(0x60),GREY(0x70),GREY(0x80),GREY(0x90),GREY(0xA0),GREY(0xB0),GREY(0xC0),GREY(0xD0) }; // dark to light short Mod320(long y) { short m = y % 320; if (m < 0) m += 320; return m; } // Fill above and below the image void FillScrollBG(long y, int height, int t) { long end = y + height; while (y < end)
/** @brief Computes image histogram For 24-bit and 32-bit images, histogram can be computed from red, green, blue and black channels. For 8-bit images, histogram is computed from the black channel. Other bit depth is not supported (nothing is done). @param src Input image to be processed. @param histo Histogram array to fill. <b>The size of 'histo' is assumed to be 256.</b> @param channel Color channel to use @return Returns TRUE if succesful, returns FALSE if the image bit depth isn't supported. */ BOOL DLL_CALLCONV FreeImage_GetHistogram(FIBITMAP *src, DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel) { BYTE pixel; BYTE *bits = NULL; unsigned x, y; if(!src || !histo) return FALSE; unsigned width = FreeImage_GetWidth(src); unsigned height = FreeImage_GetHeight(src); unsigned bpp = FreeImage_GetBPP(src); if(bpp == 8) { // clear histogram array memset(histo, 0, 256 * sizeof(DWORD)); // compute histogram for black channel for(y = 0; y < height; y++) { bits = FreeImage_GetScanLine(src, y); for(x = 0; x < width; x++) { // get pixel value pixel = bits[x]; histo[pixel]++; } } return TRUE; } else if((bpp == 24) || (bpp == 32)) { int bytespp = bpp / 8; // bytes / pixel // clear histogram array memset(histo, 0, 256 * sizeof(DWORD)); switch(channel) { case FICC_RED: // compute histogram for red channel for(y = 0; y < height; y++) { bits = FreeImage_GetScanLine(src, y); for(x = 0; x < width; x++) { pixel = bits[FI_RGBA_RED]; // R histo[pixel]++; bits += bytespp; } } return TRUE; case FICC_GREEN: // compute histogram for green channel for(y = 0; y < height; y++) { bits = FreeImage_GetScanLine(src, y); for(x = 0; x < width; x++) { pixel = bits[FI_RGBA_GREEN]; // G histo[pixel]++; bits += bytespp; } } return TRUE; case FICC_BLUE: // compute histogram for blue channel for(y = 0; y < height; y++) { bits = FreeImage_GetScanLine(src, y); for(x = 0; x < width; x++) { pixel = bits[FI_RGBA_BLUE]; // B histo[pixel]++; bits += bytespp; } } return TRUE; case FICC_BLACK: case FICC_RGB: // compute histogram for black channel for(y = 0; y < height; y++) { bits = FreeImage_GetScanLine(src, y); for(x = 0; x < width; x++) { // RGB to GREY conversion pixel = GREY(bits[FI_RGBA_RED], bits[FI_RGBA_GREEN], bits[FI_RGBA_BLUE]); histo[pixel]++; bits += bytespp; } } return TRUE; default: return FALSE; } } return FALSE; }
/** @brief Looks up a specified color in a FIBITMAP's palette and returns the color's palette index or -1 if the color was not found. Unlike with FreeImage_GetColorType, which returns either FIC_MINISBLACK or FIC_MINISWHITE for a greyscale image with a linear ramp palette, the return value of this function does not depend on the palette's order, but only on the palette's individual colors. @param dib The image, whose palette should be searched through. @param color The color to be searched in the palette. @param options Options that affect the color search process. @param color_type A pointer, that optionally specifies the image's color type as returned by FreeImage_GetColorType. If invalid or NULL, this function determines the color type with FreeImage_GetColorType. @return Returns the specified color's palette index, the color's rgbReserved member if option FI_COLOR_ALPHA_IS_INDEX was specified or -1, if the color was not found in the image's palette or if the specified image is non-palletized. */ static int GetPaletteIndex(FIBITMAP *dib, const RGBQUAD *color, int options, FREE_IMAGE_COLOR_TYPE *color_type) { int result = -1; if ((!dib) || (!color)) { return result; } int bpp = FreeImage_GetBPP(dib); // First check trivial case: return color->rgbReserved if only // FI_COLOR_ALPHA_IS_INDEX is set. if ((options & FI_COLOR_ALPHA_IS_INDEX) == FI_COLOR_ALPHA_IS_INDEX) { if (bpp == 1) { return color->rgbReserved & 0x01; } else if (bpp == 4) { return color->rgbReserved & 0x0F; } return color->rgbReserved; } if (bpp == 8) { FREE_IMAGE_COLOR_TYPE ct = (color_type == NULL || *color_type < 0) ? FreeImage_GetColorType(dib) : *color_type; if (ct == FIC_MINISBLACK) { return GREY(color->rgbRed, color->rgbGreen, color->rgbBlue); } if (ct == FIC_MINISWHITE) { return 255 - GREY(color->rgbRed, color->rgbGreen, color->rgbBlue); } } else if (bpp > 8) { // for palettized images only return result; } if (options & FI_COLOR_FIND_EQUAL_COLOR) { // Option FI_COLOR_ALPHA_IS_INDEX is implicit here so, set // index to color->rgbReserved result = color->rgbReserved; if (bpp == 1) { result &= 0x01; } else if (bpp == 4) { result &= 0x0F; } unsigned ucolor; if (!IsVisualGreyscaleImage(dib)) { ucolor = (*((unsigned *)color)) & 0xFFFFFF; } else { ucolor = GREY(color->rgbRed, color->rgbGreen, color->rgbBlue) * 0x010101; //ucolor = (ucolor | (ucolor << 8) | (ucolor << 16)); } unsigned ncolors = FreeImage_GetColorsUsed(dib); unsigned *palette = (unsigned *)FreeImage_GetPalette(dib); for (unsigned i = 0; i < ncolors; i++) { if ((palette[i] & 0xFFFFFF) == ucolor) { result = i; break; } } } else { unsigned minimum = UINT_MAX; unsigned ncolors = FreeImage_GetColorsUsed(dib); BYTE *palette = (BYTE *)FreeImage_GetPalette(dib); BYTE red, green, blue; if (!IsVisualGreyscaleImage(dib)) { red = color->rgbRed; green = color->rgbGreen; blue = color->rgbBlue; } else { red = GREY(color->rgbRed, color->rgbGreen, color->rgbBlue); green = blue = red; } for (unsigned i = 0; i < ncolors; i++) { unsigned m = abs(palette[FI_RGBA_BLUE] - blue) + abs(palette[FI_RGBA_GREEN] - green) + abs(palette[FI_RGBA_RED] - red); if (m < minimum) { minimum = m; result = i; if (m == 0) { break; } } palette += sizeof(RGBQUAD); } } return result; }