• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ FreeImage_GetPalette函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中FreeImage_GetPalette函数的典型用法代码示例。如果您正苦于以下问题:C++ FreeImage_GetPalette函数的具体用法?C++ FreeImage_GetPalette怎么用?C++ FreeImage_GetPalette使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了FreeImage_GetPalette函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:linpinger,项目名称:foxbook-ahk,代码行数:31,代码来源:imgsplit_V1.8.3.cpp


示例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;
	}
开发者ID:Talon1024,项目名称:SLADE,代码行数:60,代码来源:SIFormat.cpp


示例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) ; // 使用完缓存记得要释放
}
开发者ID:linpinger,项目名称:foxbook-ahk,代码行数:28,代码来源:imgsplit_V1.8.3.cpp


示例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;
}
开发者ID:mikanradojevic,项目名称:sdkpub,代码行数:30,代码来源:BitmapAccess.cpp


示例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;
}
开发者ID:OSB-AG,项目名称:IsoAgLib,代码行数:29,代码来源:vt2isoimagefreeimage_c.cpp


示例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;
}
开发者ID:MrMasterplan,项目名称:PIC-stuff,代码行数:27,代码来源:fipImage.cpp


示例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;
}
开发者ID:Ali-il,项目名称:gamekit,代码行数:64,代码来源:Colors.cpp


示例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);
    }
}
开发者ID:ChulseungYoo,项目名称:ofxGifEncoder,代码行数:8,代码来源:ofxGifEncoder.cpp


示例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;
}
开发者ID:BackupTheBerlios,项目名称:tap-svn,代码行数:61,代码来源:Channels.cpp


示例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;
}
开发者ID:mdecicco,项目名称:HelloWorld,代码行数:12,代码来源:PSDParser.cpp


示例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;
}
开发者ID:ockham,项目名称:posterazor,代码行数:14,代码来源:imageloaderfreeimage.cpp


示例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 ;
}
开发者ID:linpinger,项目名称:foxbook-ahk,代码行数:37,代码来源:imgsplit_V1.8.3.cpp


示例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);
		}
	}
}
开发者ID:jrsnail,项目名称:u2project_deps,代码行数:31,代码来源:Background.cpp


示例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;
}
开发者ID:BackupTheBerlios,项目名称:mimplugins-svn,代码行数:54,代码来源:testTools.cpp


示例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;
}
开发者ID:alfredoBorboa,项目名称:openFrameworks,代码行数:25,代码来源:ofImage.cpp


示例16: ColorQuantize

    ColorQuantize(PClip originClip, int paletteSize,
                  bool useGlobalPalette, FREE_IMAGE_QUANTIZE algorithm,
                  const char *globalPaletteOutputFile, IScriptEnvironment* env)
        : m_origin(originClip)
        , m_paletteSize(paletteSize)
        , m_useGlobalPalette(useGlobalPalette)
        , m_algorithm(algorithm)
        , m_targetVideoInfo(originClip->GetVideoInfo())
        , m_globalPalette(0)
    {
        if (!originClip->GetVideoInfo().IsRGB24()) {
            m_originRgb = env->Invoke("ConvertToRgb24", originClip).AsClip();
            m_targetVideoInfo.pixel_type = VideoInfo::CS_BGR24;
        } else {
            m_originRgb = originClip;
        }

        if (m_useGlobalPalette) {
            FIBITMAP *hugeImage =
                    FreeImage_Allocate(m_targetVideoInfo.width,
                                       m_targetVideoInfo.height * m_targetVideoInfo.num_frames,
                                       24);
            for (int frame = 0; frame < m_targetVideoInfo.num_frames; ++frame) {
                const PVideoFrame videoFrame = m_originRgb->GetFrame(frame, env);
                copyVideoFrameToImage(m_originRgb->GetFrame(frame, env),hugeImage, frame * m_targetVideoInfo.height);
            }
            FIBITMAP *quantizedImage =
                    FreeImage_ColorQuantizeEx(hugeImage, algorithm, m_paletteSize);
            FreeImage_Unload(hugeImage);
            m_globalPalette = new RGBQUAD[m_paletteSize];
            memcpy(m_globalPalette, FreeImage_GetPalette(quantizedImage), m_paletteSize * sizeof(RGBQUAD));
            FreeImage_Unload(quantizedImage);
            if (globalPaletteOutputFile)
                savePaletteImage(globalPaletteOutputFile, m_globalPalette, m_paletteSize);
        }
    }
开发者ID:aportale,项目名称:qtorials,代码行数:36,代码来源:colorquantize.cpp


示例17: FreeImage_Composite

/**
@brief Composite a foreground image against a background color or a background image.

The equation for computing a composited sample value is:<br>
output = alpha * foreground + (1-alpha) * background<br>
where alpha and the input and output sample values are expressed as fractions in the range 0 to 1. 
For colour images, the computation is done separately for R, G, and B samples.

@param fg Foreground image
@param useFileBkg If TRUE and a file background is present, use it as the background color
@param appBkColor If not equal to NULL, and useFileBkg is FALSE, use this color as the background color
@param bg If not equal to NULL and useFileBkg is FALSE and appBkColor is NULL, use this as the background image
@return Returns the composite image if successful, returns NULL otherwise
@see FreeImage_IsTransparent, FreeImage_HasBackgroundColor
*/
FIBITMAP * DLL_CALLCONV
FreeImage_Composite(FIBITMAP *fg, BOOL useFileBkg, RGBQUAD *appBkColor, FIBITMAP *bg) {
	if(!FreeImage_HasPixels(fg)) return NULL;

	int width  = FreeImage_GetWidth(fg);
	int height = FreeImage_GetHeight(fg);
	int bpp    = FreeImage_GetBPP(fg);

	if((bpp != 8) && (bpp != 32))
		return NULL;

	if(bg) {
		int bg_width  = FreeImage_GetWidth(bg);
		int bg_height = FreeImage_GetHeight(bg);
		int bg_bpp    = FreeImage_GetBPP(bg);
		if((bg_width != width) || (bg_height != height) || (bg_bpp != 24))
			return NULL;
	}

	int bytespp = (bpp == 8) ? 1 : 4;

	
	int x, y, c;
	BYTE alpha = 0, not_alpha;
	BYTE index;
	RGBQUAD fgc;	// foreground color
	RGBQUAD bkc;	// background color

	memset(&fgc, 0, sizeof(RGBQUAD));
	memset(&bkc, 0, sizeof(RGBQUAD));

	// allocate the composite image
	FIBITMAP *composite = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
	if(!composite) return NULL;

	// get the palette
	RGBQUAD *pal = FreeImage_GetPalette(fg);

	// retrieve the alpha table from the foreground image
	BOOL bIsTransparent = FreeImage_IsTransparent(fg);
	BYTE *trns = FreeImage_GetTransparencyTable(fg);

	// retrieve the background color from the foreground image
	BOOL bHasBkColor = FALSE;

	if(useFileBkg && FreeImage_HasBackgroundColor(fg)) {
		FreeImage_GetBackgroundColor(fg, &bkc);
		bHasBkColor = TRUE;
	} else {
		// no file background color
		// use application background color ?
		if(appBkColor) {
			memcpy(&bkc, appBkColor, sizeof(RGBQUAD));
			bHasBkColor = TRUE;
		}
		// use background image ?
		else if(bg) {
			bHasBkColor = FALSE;
		}
	}

	for(y = 0; y < height; y++) {
		// foreground
		BYTE *fg_bits = FreeImage_GetScanLine(fg, y);
		// background
		BYTE *bg_bits = FreeImage_GetScanLine(bg, y);
		// composite image
		BYTE *cp_bits = FreeImage_GetScanLine(composite, y);

		for(x = 0; x < width; x++) {

			// foreground color + alpha

			if(bpp == 8) {
				// get the foreground color
				index = fg_bits[0];
				memcpy(&fgc, &pal[index], sizeof(RGBQUAD));
				// get the alpha
				if(bIsTransparent) {
					alpha = trns[index];
				} else {
					alpha = 255;
				}
			}
			else if(bpp == 32) {
//.........这里部分代码省略.........
开发者ID:miranda-ng,项目名称:miranda-ng,代码行数:101,代码来源:Display.cpp


示例18: Save


//.........这里部分代码省略.........
			}

			FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
			if(image_type == FIT_BITMAP) {
				// standard image type
				bit_depth = (pixel_depth > 8) ? 8 : pixel_depth;
			} else {
				// 16-bit greyscale or 16-bit RGB(A)
				bit_depth = 16;
			}

			switch (FreeImage_GetColorType(dib)) {
				case FIC_MINISWHITE:
					// Invert monochrome files to have 0 as black and 1 as white (no break here)
					png_set_invert_mono(png_ptr);

				case FIC_MINISBLACK:
					png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, 
						PNG_COLOR_TYPE_GRAY, interlace_type, 
						PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);

					break;

				case FIC_PALETTE:
				{
					png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, 
						PNG_COLOR_TYPE_PALETTE, interlace_type, 
						PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);

					// set the palette

					palette_entries = 1 << bit_depth;
					palette = (png_colorp)png_malloc(png_ptr, palette_entries * sizeof (png_color));
					pal = FreeImage_GetPalette(dib);

					for (int i = 0; i < palette_entries; i++) {
						palette[i].red   = pal[i].rgbRed;
						palette[i].green = pal[i].rgbGreen;
						palette[i].blue  = pal[i].rgbBlue;
					}
					
					png_set_PLTE(png_ptr, info_ptr, palette, palette_entries);

					// You must not free palette here, because png_set_PLTE only makes a link to
					// the palette that you malloced.  Wait until you are about to destroy
					// the png structure.

					break;
				}

				case FIC_RGBALPHA :
					has_alpha_channel = TRUE;

					png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, 
						PNG_COLOR_TYPE_RGBA, interlace_type, 
						PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);

#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR
					// flip BGR pixels to RGB
					if(image_type == FIT_BITMAP) {
						png_set_bgr(png_ptr);
					}
#endif
					break;
	
				case FIC_RGB:
开发者ID:elfprince13,项目名称:G3D10,代码行数:67,代码来源:PluginPNG.cpp


示例19: Load


//.........这里部分代码省略.........

			// color type may have changed, due to our transformations

			color_type = png_get_color_type(png_ptr,info_ptr);

			// create a DIB and write the bitmap header
			// set up the DIB palette, if needed

			switch (color_type) {
				case PNG_COLOR_TYPE_RGB:
					png_set_invert_alpha(png_ptr);

					if(image_type == FIT_BITMAP) {
						dib = FreeImage_AllocateHeader(header_only, width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
					} else {
						dib = FreeImage_AllocateHeaderT(header_only, image_type, width, height, pixel_depth);
					}
					break;

				case PNG_COLOR_TYPE_RGB_ALPHA:
					if(image_type == FIT_BITMAP) {
						dib = FreeImage_AllocateHeader(header_only, width, height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
					} else {
						dib = FreeImage_AllocateHeaderT(header_only, image_type, width, height, pixel_depth);
					}
					break;

				case PNG_COLOR_TYPE_PALETTE:
					dib = FreeImage_AllocateHeader(header_only, width, height, pixel_depth);

					png_get_PLTE(png_ptr,info_ptr, &png_palette, &palette_entries);

					palette_entries = MIN((unsigned)palette_entries, FreeImage_GetColorsUsed(dib));
					palette = FreeImage_GetPalette(dib);

					// store the palette

					for (i = 0; i < palette_entries; i++) {
						palette[i].rgbRed   = png_palette[i].red;
						palette[i].rgbGreen = png_palette[i].green;
						palette[i].rgbBlue  = png_palette[i].blue;
					}
					break;

				case PNG_COLOR_TYPE_GRAY:
					dib = FreeImage_AllocateHeaderT(header_only, image_type, width, height, pixel_depth);

					if(pixel_depth <= 8) {
						palette = FreeImage_GetPalette(dib);
						palette_entries = 1 << pixel_depth;

						for (i = 0; i < palette_entries; i++) {
							palette[i].rgbRed   =
							palette[i].rgbGreen =
							palette[i].rgbBlue  = (BYTE)((i * 255) / (palette_entries - 1));
						}
					}
					break;

				default:
					throw FI_MSG_ERROR_UNSUPPORTED_FORMAT;
			}

			// store the transparency table

			if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
开发者ID:elfprince13,项目名称:G3D10,代码行数:67,代码来源:PluginPNG.cpp


示例20: Rotate8Bit

/** 
 Image translation and rotation using B-Splines.

 @param dib Input 8-bit greyscale image
 @param angle Output image rotation in degree
 @param x_shift Output image horizontal shift
 @param y_shift Output image vertical shift
 @param x_origin Output origin of the x-axis
 @param y_origin Output origin of the y-axis
 @param spline_degree Output degree of the B-spline model
 @param use_mask Whether or not to mask the image
 @return Returns the translated & rotated dib if successful, returns NULL otherwise
*/
static FIBITMAP * 
Rotate8Bit(FIBITMAP *dib, double angle, double x_shift, double y_shift, double x_origin, double y_origin, long spline_degree, BOOL use_mask) {
	double	*ImageRasterArray;
	double	p;
	double	a11, a12, a21, a22;
	double	x0, y0, x1, y1;
	long	x, y;
	long	spline;
	bool	bResult;

	int bpp = FreeImage_GetBPP(dib);
	if(bpp != 8) {
		return NULL;
	}
	
	int width = FreeImage_GetWidth(dib);
	int height = FreeImage_GetHeight(dib);
	switch(spline_degree) {
		case ROTATE_QUADRATIC:
			spline = 2L;	// Use splines of degree 2 (quadratic interpolation)
			break;
		case ROTATE_CUBIC:
			spline = 3L;	// Use splines of degree 3 (cubic interpolation)
			break;
		case ROTATE_QUARTIC:
			spline = 4L;	// Use splines of degree 4 (quartic interpolation)
			break;
		case ROTATE_QUINTIC:
			spline = 5L;	// Use splines of degree 5 (quintic interpolation)
			break;
		default:
			spline = 3L;
	}

	// allocate output image
	FIBITMAP *dst = FreeImage_Allocate(width, height, bpp);
	if(!dst)
		return NULL;
	// buid a grey scale palette
	RGBQUAD *pal = FreeImage_GetPalette(dst);
	for(int i = 0; i < 256; i++) {
		pal[i].rgbRed = pal[i].rgbGreen = pal[i].rgbBlue = (BYTE)i;
	}

	// allocate a temporary array
	ImageRasterArray = (double*)malloc(width * height * sizeof(double));
	if(!ImageRasterArray) {
		FreeImage_Unload(dst);
		return NULL;
	}
	// copy data samples
	for(y = 0; y < height; y++) {
		double *pImage = &ImageRasterArray[y*width];
		BYTE *src_bits = FreeImage_GetScanLine(dib, height-1-y);

		for(x = 0; x < width; x++) {
			pImage[x] = (double)src_bits[x];
		}
	}

	// convert between a representation based on image samples
	// and a representation based on image B-spline coefficients
	bResult = SamplesToCoefficients(ImageRasterArray, width, height, spline);
	if(!bResult) {
		FreeImage_Unload(dst);
		free(ImageRasterArray);
		return NULL;
	}

	// prepare the geometry
	angle *= PI / 180.0;
	a11 = cos(angle);
	a12 = -sin(angle);
	a21 = sin(angle);
	a22 = cos(angle);
	x0 = a11 * (x_shift + x_origin) + a12 * (y_shift + y_origin);
	y0 = a21 * (x_shift + x_origin) + a22 * (y_shift + y_origin);
	x_shift = x_origin - x0;
	y_shift = y_origin - y0;

	// visit all pixels of the output image and assign their value
	for(y = 0; y < height; y++) {
		BYTE *dst_bits = FreeImage_GetScanLine(dst, height-1-y);
		
		x0 = a12 * (double)y + x_shift;
		y0 = a22 * (double)y + y_shift;

//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:mimplugins-svn,代码行数:101,代码来源:BSplineRotate.cpp



注:本文中的FreeImage_GetPalette函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ FreeImage_GetPitch函数代码示例发布时间:2022-05-30
下一篇:
C++ FreeImage_GetHeight函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap