本文整理匯總了C++中FreeImage_GetPalette函數的典型用法代碼示例。如果您正苦於以下問題:C++ FreeImage_GetPalette函數的具體用法?C++ FreeImage_GetPalette怎麽用?C++ FreeImage_GetPalette使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了FreeImage_GetPalette函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: CreateTemplete
FIBITMAP * CreateTemplete(FIBITMAP * hImage, unsigned ScreenWidth, unsigned ScreenHeight) // 創建空白PNG模版
{
FIBITMAP * hPicTemplete;
RGBQUAD * palMain ;
RGBQUAD * palTemplete ;
unsigned ImgPitchLocal ;
BYTE * pBitLocal;
unsigned x, y, n;
hPicTemplete = FreeImage_Allocate(ScreenWidth, ScreenHeight, 8, 0, 0, 0); //創建目標圖像
palMain = FreeImage_GetPalette(hImage);
palTemplete = FreeImage_GetPalette(hPicTemplete);
for (n = 0 ; n < 256 ; n++) {
palTemplete[n].rgbRed = palMain[n].rgbRed ;
palTemplete[n].rgbGreen = palMain[n].rgbGreen ;
palTemplete[n].rgbBlue = palMain[n].rgbBlue ;
}
palTemplete[70].rgbRed = 255 ;
palTemplete[70].rgbGreen = 255 ;
palTemplete[70].rgbBlue = 255 ;
// FreeImage_SetTransparent(hPicTemplete, false);
// 所有像素顏色填充為 70 號索引
ImgPitchLocal = FreeImage_GetPitch(hPicTemplete) ;
pBitLocal = FreeImage_GetBits(hPicTemplete);
for (y = 0 ; y < ScreenHeight; y++) {
for (x = 0; x < ScreenWidth ; x++)
pBitLocal[x] = 70 ;
pBitLocal += ImgPitchLocal ; // 下一行
}
return hPicTemplete;
}
示例2: readImage
bool readImage(SImage& image, MemChunk& data, int index)
{
// Get image info
SImage::info_t info;
FIBITMAP* bm = getFIInfo(data, info);
// Check it created/read ok
if (!bm)
{
Global::error = "Unable to read image data (unsupported format?)";
return false;
}
// Get image palette if it exists
RGBQUAD* bm_pal = FreeImage_GetPalette(bm);
Palette palette;
if (bm_pal)
{
int a = 0;
int b = FreeImage_GetColorsUsed(bm);
if (b > 256)
b = 256;
for (; a < b; a++)
palette.setColour(a, rgba_t(bm_pal[a].rgbRed, bm_pal[a].rgbGreen, bm_pal[a].rgbBlue, 255));
}
// Create image
if (info.has_palette)
image.create(info, &palette);
else
image.create(info);
uint8_t* img_data = imageData(image);
// Convert to 32bpp & flip vertically
FIBITMAP* rgba = FreeImage_ConvertTo32Bits(bm);
if (!rgba)
{
LOG_MESSAGE(1, "FreeImage_ConvertTo32Bits failed for image data");
Global::error = "Error reading PNG data";
return false;
}
FreeImage_FlipVertical(rgba);
// Load raw RGBA data
uint8_t* bits_rgba = FreeImage_GetBits(rgba);
int c = 0;
for (int a = 0; a < info.width * info.height; a++)
{
img_data[c++] = bits_rgba[a * 4 + 2]; // Red
img_data[c++] = bits_rgba[a * 4 + 1]; // Green
img_data[c++] = bits_rgba[a * 4]; // Blue
img_data[c++] = bits_rgba[a * 4 + 3]; // Alpha
}
// Free memory
FreeImage_Unload(rgba);
FreeImage_Unload(bm);
return true;
}
示例3: gif2png_bufopen
// 獨立函數,讀取gif圖片,寫白背景,轉為PNG並寫入緩存,返回緩存地址
FOX_DLL FIMEMORY * gif2png_bufopen(char *gifpath, BYTE ** buffpointeraddr, DWORD * bufflenaddr)
{
FIBITMAP * hImage ;
RGBQUAD * pal ;
FIMEMORY * hMemory = NULL ;
BYTE *mem_buffer = NULL ;
DWORD size_in_bytes = 0 ;
hImage = FreeImage_Load(FIF_GIF, gifpath, 0);
pal = FreeImage_GetPalette(hImage);
pal[70].rgbRed = 255 ;
pal[70].rgbGreen = 255 ;
pal[70].rgbBlue = 255 ;
FreeImage_SetTransparent(hImage, false);
hMemory = FreeImage_OpenMemory() ;
FreeImage_SaveToMemory(FIF_PNG, hImage, hMemory, PNG_DEFAULT) ;
FreeImage_Unload(hImage) ;
FreeImage_AcquireMemory(hMemory, &mem_buffer, &size_in_bytes);
*buffpointeraddr = mem_buffer ;
*bufflenaddr = size_in_bytes ;
return hMemory ;
// FreeImage_CloseMemory(hMemory) ; // 使用完緩存記得要釋放
}
示例4: FreeImage_GetBackgroundColor
BOOL DLL_CALLCONV
FreeImage_GetBackgroundColor(FIBITMAP *dib, RGBQUAD *bkcolor) {
if(dib && bkcolor) {
if(FreeImage_HasBackgroundColor(dib)) {
// get the background color
RGBQUAD *bkgnd_color = &((FREEIMAGEHEADER *)dib->data)->bkgnd_color;
memcpy(bkcolor, bkgnd_color, sizeof(RGBQUAD));
// get the background index
if(FreeImage_GetBPP(dib) == 8) {
RGBQUAD *pal = FreeImage_GetPalette(dib);
for(unsigned i = 0; i < FreeImage_GetColorsUsed(dib); i++) {
if(bkgnd_color->rgbRed == pal[i].rgbRed) {
if(bkgnd_color->rgbGreen == pal[i].rgbGreen) {
if(bkgnd_color->rgbBlue == pal[i].rgbBlue) {
bkcolor->rgbReserved = i;
return TRUE;
}
}
}
}
}
bkcolor->rgbReserved = 0;
return TRUE;
}
}
return FALSE;
}
示例5: if
// this function is only called for the 8bit case!
int Vt2IsoImageFreeImage_c::getPaletteIndex (unsigned int aui_x, unsigned int aui_y)
{
if (mb_palettized)
{
// do this check here, because in case we only use 4bit bitmap, we don't have to care for the palette matching...
if (mi_colourMismatch >= 0)
{
if (isOstream()) getOstream() << "*** COULDN'T LOAD BITMAP: WRONG PALETTE. See (first) mismatching colour #"<<mi_colourMismatch<<" below. Please use the ISO11783-Part 6 (VT)-Palette for bitmaps you have saved palettized and use in 8bit-mode. Use 'vt2iso -p' to generate an .act file and resample your bitmap to use this palette! ***" << std::endl;
if (isOstream()) getOstream() << "HAS TO BE | you had" << std::hex << std::setfill('0');
for (int i=0; i<(16+216); i++)
{
if ((i % 8) == 0) { if (isOstream()) getOstream() << std::endl; }
else { if (isOstream()) getOstream() << " "; }
if (isOstream()) getOstream() << std::setw(2) << fiuint16_t(vtColourTable[i].bgrRed) << std::setw(2) << fiuint16_t(vtColourTable[i].bgrGreen) << std::setw(2) << fiuint16_t(vtColourTable[i].bgrBlue);
if (i == mi_colourMismatch) { if (isOstream()) getOstream() << "*|*"; } else { if (isOstream()) getOstream() << " | "; }
if (isOstream()) getOstream() << std::setw(2) << fiuint16_t(FreeImage_GetPalette (bitmap)[i].rgbRed) << std::setw(2) << fiuint16_t(FreeImage_GetPalette (bitmap)[i].rgbGreen) << std::setw(2) << fiuint16_t(FreeImage_GetPalette (bitmap)[i].rgbBlue);
}
if (isOstream()) getOstream() << std::endl;
b_isInvalidPalette = true;
return -1;
}
fiuint8_t idx;
FreeImage_GetPixelIndex (bitmap, aui_x, (ui_height - 1) - aui_y, &idx);
return idx;
}
else return -1;
}
示例6: FreeImage_Unload
BOOL fipImage::setSize(FREE_IMAGE_TYPE image_type, WORD width, WORD height, WORD bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask) {
if(_dib) {
FreeImage_Unload(_dib);
}
if((_dib = FreeImage_AllocateT(image_type, width, height, bpp, red_mask, green_mask, blue_mask)) == NULL)
return FALSE;
if(image_type == FIT_BITMAP) {
// Create palette if needed
switch(bpp) {
case 1:
case 4:
case 8:
RGBQUAD *pal = FreeImage_GetPalette(_dib);
for(unsigned i = 0; i < FreeImage_GetColorsUsed(_dib); i++) {
pal[i].rgbRed = i;
pal[i].rgbGreen = i;
pal[i].rgbBlue = i;
}
break;
}
}
_bHasChanged = TRUE;
return TRUE;
}
示例7: FreeImage_Invert
/** @brief Inverts each pixel data.
@param src Input image to be processed.
@return Returns TRUE if successful, FALSE otherwise.
*/
BOOL DLL_CALLCONV
FreeImage_Invert(FIBITMAP *src) {
unsigned i, x, y, k;
BYTE *bits;
if (!src) return FALSE;
int bpp = FreeImage_GetBPP(src);
switch(bpp) {
case 1 :
case 4 :
case 8 :
{
// if the dib has a colormap, just invert it
// else, keep the linear grayscale
if (FreeImage_GetColorType(src) == FIC_PALETTE) {
RGBQUAD *pal = FreeImage_GetPalette(src);
for(i = 0; i < FreeImage_GetColorsUsed(src); i++) {
pal[i].rgbRed = 255 - pal[i].rgbRed;
pal[i].rgbGreen = 255 - pal[i].rgbGreen;
pal[i].rgbBlue = 255 - pal[i].rgbBlue;
}
} else {
for(y = 0; y < FreeImage_GetHeight(src); y++) {
bits = FreeImage_GetScanLine(src, y);
for (x = 0; x < FreeImage_GetLine(src); x++) {
bits[x] = ~bits[x];
}
}
}
break;
}
case 24 :
case 32 :
{
unsigned bytespp = FreeImage_GetLine(src) / FreeImage_GetWidth(src);
for(y = 0; y < FreeImage_GetHeight(src); y++) {
bits = FreeImage_GetScanLine(src, y);
for(x = 0; x < FreeImage_GetWidth(src); x++) {
for(k = 0; k < bytespp; k++) {
bits[k] = ~bits[k];
}
bits += bytespp;
}
}
break;
}
}
return TRUE;
}
示例8: FreeImage_GetPalette
void ofxGifEncoder::calculatePalette(FIBITMAP * bmp){
RGBQUAD *pal = FreeImage_GetPalette(bmp);
for (int i = 0; i < 256; i++) {
palette.push_back(ofColor(pal[i].rgbRed, pal[i].rgbGreen, pal[i].rgbBlue));
ofLog() << palette.at(i);
}
}
示例9: FreeImage_GetChannel
/** @brief Retrieves the red, green, blue or alpha channel of a 24- or 32-bit BGR[A] image.
@param src Input image to be processed.
@param channel Color channel to extract
@return Returns the extracted channel if successful, returns NULL otherwise.
*/
FIBITMAP * DLL_CALLCONV
FreeImage_GetChannel(FIBITMAP *src, FREE_IMAGE_COLOR_CHANNEL channel) {
int c;
if(!src) return NULL;
unsigned bpp = FreeImage_GetBPP(src);
if((bpp == 24) || (bpp == 32)) {
// select the channel to extract
switch(channel) {
case FICC_BLUE:
c = FI_RGBA_BLUE;
break;
case FICC_GREEN:
c = FI_RGBA_GREEN;
break;
case FICC_RED:
c = FI_RGBA_RED;
break;
case FICC_ALPHA:
if(bpp != 32) return NULL;
c = FI_RGBA_ALPHA;
break;
default:
return NULL;
}
// allocate a 8-bit dib
unsigned width = FreeImage_GetWidth(src);
unsigned height = FreeImage_GetHeight(src);
FIBITMAP *dst = FreeImage_Allocate(width, height, 8) ;
if(!dst) return NULL;
// build a greyscale palette
RGBQUAD *pal = FreeImage_GetPalette(dst);
for(int i = 0; i < 256; i++) {
pal[i].rgbBlue = pal[i].rgbGreen = pal[i].rgbRed = i;
}
// perform extraction
int bytespp = bpp / 8; // bytes / pixel
for(unsigned y = 0; y < height; y++) {
BYTE *src_bits = FreeImage_GetScanLine(src, y);
BYTE *dst_bits = FreeImage_GetScanLine(dst, y);
for(unsigned x = 0; x < width; x++) {
dst_bits[x] = src_bits[c];
src_bits += bytespp;
}
}
return dst;
}
return NULL;
}
示例10: FreeImage_GetPalette
bool psdColourModeData::FillPalette(FIBITMAP *dib) {
RGBQUAD *pal = FreeImage_GetPalette(dib);
if(pal) {
for (int i = 0; i < 256; i++) {
pal[i].rgbRed = _plColourData[i + 0*256];
pal[i].rgbGreen = _plColourData[i + 1*256];
pal[i].rgbBlue = _plColourData[i + 2*256];
}
return true;
}
return false;
}
示例11: FreeImage_GetPalette
const QVector<QRgb> ImageLoaderFreeImage::colorTable() const
{
QVector<QRgb> result;
const RGBQUAD* const palette = FreeImage_GetPalette(m_bitmap);
if (palette) {
const int count = FreeImage_GetColorsUsed(m_bitmap);
result.resize(count);
for (int i = 0; i < count; i++)
result.replace(i, qRgb(palette[i].rgbRed, palette[i].rgbGreen, palette[i].rgbBlue));
}
return result;
}
示例12: gifcat
FIBITMAP * gifcat(char gifpath[MAXGIFCOUNT][MAXPATHCHAR], unsigned gifPathCount) // 將多張圖片連接為一張圖片
{
FIBITMAP * hImageAll ;
unsigned ImgHeightAll = 0 ;
FIBITMAP * hImage[MAXGIFCOUNT] ;
unsigned ImgHeight[MAXGIFCOUNT] ;
unsigned ImgWidth ;
RGBQUAD * palSrc ;
RGBQUAD * palAll ;
unsigned n , NowYPos = 0 ;
// ---
for ( n=0; n < gifPathCount; ++n) {
hImage[n] = FreeImage_Load(FIF_GIF, gifpath[n], 0);
ImgHeight[n] = FreeImage_GetHeight(hImage[n]) ;
ImgHeightAll += ImgHeight[n] ;
}
ImgWidth = FreeImage_GetWidth(hImage[0]) ;
hImageAll = FreeImage_Allocate(ImgWidth, ImgHeightAll, 8, 0, 0, 0); //創建目標圖像
palAll = FreeImage_GetPalette(hImageAll); // 複製調色板
palSrc = FreeImage_GetPalette(hImage[0]);
for (n = 0; n < 256; ++n) {
palAll[n].rgbRed = palSrc[n].rgbRed ;
palAll[n].rgbGreen = palSrc[n].rgbGreen ;
palAll[n].rgbBlue = palSrc[n].rgbBlue ;
}
palAll[70].rgbRed = 255 ;
palAll[70].rgbGreen = 255 ;
palAll[70].rgbBlue = 255 ;
for ( n=0; n < gifPathCount; ++n) { // 粘貼圖像
FreeImage_Paste(hImageAll, hImage[n], 0, NowYPos, 300) ;
NowYPos += ImgHeight[n] ;
FreeImage_Unload(hImage[n]) ;
}
return hImageAll ;
}
示例13: IsVisualGreyscaleImage
/** @brief Determines, whether a palletized image is visually greyscale or not.
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 to be tested.
@return Returns TRUE if the palette of the image specified contains only
greyscales, FALSE otherwise.
*/
static BOOL
IsVisualGreyscaleImage(FIBITMAP *dib) {
switch (FreeImage_GetBPP(dib)) {
case 1:
case 4:
case 8: {
unsigned ncolors = FreeImage_GetColorsUsed(dib);
RGBQUAD *rgb = FreeImage_GetPalette(dib);
for (unsigned i = 0; i< ncolors; i++) {
if ((rgb->rgbRed != rgb->rgbGreen) || (rgb->rgbRed != rgb->rgbBlue)) {
return FALSE;
}
}
return TRUE;
}
default: {
return (FreeImage_GetColorType(dib) == FIC_MINISBLACK);
}
}
}
示例14: createZonePlateImage
/** Create a Zone Plate test pattern.
The circular zone plate has zero horizontal and vertical frequencies at the center.
Horizontal frequencies increase as you move horizontally, and vertical frequencies increase as you move vertically.
These patterns are useful to:
<ul>
<li> evaluate image compression
<li> evaluate filter properties
<li> evaluate the quality of resampling algorithms
<li> adjust gamma correction - at the proper gamma setting, the møires should be minimized
</ul>
Reference:
[1] Ken Turkowski, Open Source Repository. [Online] http://www.worldserver.com/turk/opensource/
*/
FIBITMAP* createZonePlateImage(unsigned width, unsigned height, int scale) {
const double PI = 3.1415926535898;
BYTE sinTab[256];
FIBITMAP *dst;
int i, j, x, y;
int cX, cY, d;
// allocate a 8-bit dib
dst = FreeImage_Allocate(width, height, 8);
if(!dst)
return NULL;
// build a greyscale palette
RGBQUAD *pal = FreeImage_GetPalette(dst);
for(i = 0; i < 256; i++) {
pal[i].rgbRed = i;
pal[i].rgbGreen = i;
pal[i].rgbBlue = i;
}
// build the sinus table
for(i = 0; i < 256; i++) {
sinTab[i] = (BYTE)(127.5 * sin(PI * (i - 127.5) / 127.5) + 127.5);
}
cX = width / 2;
cY = height / 2;
// create a zone plate
for(i = height, y = -cY; i--; y++) {
BYTE *dst_bits = FreeImage_GetScanLine(dst, i);
for (j = width, x = -cX; j--; x++) {
d = ((x * x + y * y) * scale) >> 8;
dst_bits[j] = sinTab[d & 0xFF];
}
}
return dst;
}
示例15: getBmpFromPixels
//----------------------------------------------------
FIBITMAP * getBmpFromPixels(ofPixels &pix){
FIBITMAP * bmp = NULL;
int w = pix.getWidth();
int h = pix.getHeight();
unsigned char * pixels = pix.getPixels();
int bpp = pix.getBitsPerPixel();
int bytesPerPixel = pix.getBytesPerPixel();
bmp = FreeImage_ConvertFromRawBits(pixels, w,h, w*bytesPerPixel, bpp, 0,0,0, true);
//this is for grayscale images they need to be paletted from: http://sourceforge.net/forum/message.php?msg_id=2856879
if( pix.getImageType() == OF_IMAGE_GRAYSCALE ){
RGBQUAD *pal = FreeImage_GetPalette(bmp);
for(int i = 0; i < 256; i++) {
pal[i].rgbRed = i;
pal[i].rgbGreen = i;
pal[i].rgbBlue = i;
}
}
return bmp;
}