Alien-FreeImage

 view release on metacpan or  search on metacpan

src/Source/FreeImage.h  view on Meta::CPAN

#define FI_COLOR_IS_RGB_COLOR			0x00	//! RGBQUAD color is a RGB color (contains no valid alpha channel)
#define FI_COLOR_IS_RGBA_COLOR			0x01	//! RGBQUAD color is a RGBA color (contains a valid alpha channel)
#define FI_COLOR_FIND_EQUAL_COLOR		0x02	//! For palettized images: lookup equal RGB color from palette
#define FI_COLOR_ALPHA_IS_INDEX			0x04	//! The color's rgbReserved member (alpha) contains the palette index to be used
#define FI_COLOR_PALETTE_SEARCH_MASK	(FI_COLOR_FIND_EQUAL_COLOR | FI_COLOR_ALPHA_IS_INDEX)	// No color lookup is performed

// RescaleEx options ---------------------------------------------------------
// Constants used in FreeImage_RescaleEx

#define FI_RESCALE_DEFAULT			0x00    //! default options; none of the following other options apply
#define FI_RESCALE_TRUE_COLOR		0x01	//! for non-transparent greyscale images, convert to 24-bit if src bitdepth <= 8 (default is a 8-bit greyscale image). 
#define FI_RESCALE_OMIT_METADATA	0x02	//! do not copy metadata to the rescaled image


#ifdef __cplusplus
extern "C" {
#endif

// Init / Error routines ----------------------------------------------------

DLL_API void DLL_CALLCONV FreeImage_Initialise(BOOL load_local_plugins_only FI_DEFAULT(FALSE));

src/Source/FreeImage.h  view on Meta::CPAN

DLL_API BITMAPINFOHEADER *DLL_CALLCONV FreeImage_GetInfoHeader(FIBITMAP *dib);
DLL_API BITMAPINFO *DLL_CALLCONV FreeImage_GetInfo(FIBITMAP *dib);
DLL_API FREE_IMAGE_COLOR_TYPE DLL_CALLCONV FreeImage_GetColorType(FIBITMAP *dib);

DLL_API unsigned DLL_CALLCONV FreeImage_GetRedMask(FIBITMAP *dib);
DLL_API unsigned DLL_CALLCONV FreeImage_GetGreenMask(FIBITMAP *dib);
DLL_API unsigned DLL_CALLCONV FreeImage_GetBlueMask(FIBITMAP *dib);

DLL_API unsigned DLL_CALLCONV FreeImage_GetTransparencyCount(FIBITMAP *dib);
DLL_API BYTE * DLL_CALLCONV FreeImage_GetTransparencyTable(FIBITMAP *dib);
DLL_API void DLL_CALLCONV FreeImage_SetTransparent(FIBITMAP *dib, BOOL enabled);
DLL_API void DLL_CALLCONV FreeImage_SetTransparencyTable(FIBITMAP *dib, BYTE *table, int count);
DLL_API BOOL DLL_CALLCONV FreeImage_IsTransparent(FIBITMAP *dib);
DLL_API void DLL_CALLCONV FreeImage_SetTransparentIndex(FIBITMAP *dib, int index);
DLL_API int DLL_CALLCONV FreeImage_GetTransparentIndex(FIBITMAP *dib);

DLL_API BOOL DLL_CALLCONV FreeImage_HasBackgroundColor(FIBITMAP *dib);
DLL_API BOOL DLL_CALLCONV FreeImage_GetBackgroundColor(FIBITMAP *dib, RGBQUAD *bkcolor);
DLL_API BOOL DLL_CALLCONV FreeImage_SetBackgroundColor(FIBITMAP *dib, RGBQUAD *bkcolor);

DLL_API FIBITMAP *DLL_CALLCONV FreeImage_GetThumbnail(FIBITMAP *dib);
DLL_API BOOL DLL_CALLCONV FreeImage_SetThumbnail(FIBITMAP *dib, FIBITMAP *thumbnail);

// ICC profile routines -----------------------------------------------------

src/Source/FreeImage/BitmapAccess.cpp  view on Meta::CPAN

	RGBQUAD bkgnd_color;

	/**@name transparency management */
	//@{
	/**
	why another table ? for easy transparency table retrieval !
	transparency could be stored in the palette, which is better
	overall, but it requires quite some changes and it will render
	FreeImage_GetTransparencyTable obsolete in its current form;
	*/
	BYTE transparent_table[256];
	/** number of transparent colors */
	int  transparency_count;
	/** TRUE if the image is transparent */
	BOOL transparent;
	//@}

	/** space to hold ICC profile */
	FIICCPROFILE iccProfile;

	/** contains a list of metadata models attached to the bitmap */
	METADATAMAP *metadata;

	/** FALSE if the FIBITMAP only contains the header and no pixel data */
	BOOL has_pixels;

src/Source/FreeImage/BitmapAccess.cpp  view on Meta::CPAN

			memset(bitmap->data, 0, dib_size);

			// write out the FREEIMAGEHEADER

			FREEIMAGEHEADER *fih = (FREEIMAGEHEADER *)bitmap->data;

			fih->type = type;

			memset(&fih->bkgnd_color, 0, sizeof(RGBQUAD));

			fih->transparent = FALSE;
			fih->transparency_count = 0;
			memset(fih->transparent_table, 0xff, 256);

			fih->has_pixels = header_only ? FALSE : TRUE;

			// initialize FIICCPROFILE link

			FIICCPROFILE *iccProfile = FreeImage_GetICCProfile(bitmap);
			iccProfile->size = 0;
			iccProfile->data = 0;
			iccProfile->flags = 0;

src/Source/FreeImage/BitmapAccess.cpp  view on Meta::CPAN

		}
		return TRUE;
	}

	return FALSE;
}

// ----------------------------------------------------------

BOOL DLL_CALLCONV
FreeImage_IsTransparent(FIBITMAP *dib) {
	if(dib) {
		FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
		switch(image_type) {
			case FIT_BITMAP:
				if(FreeImage_GetBPP(dib) == 32) {
					if(FreeImage_GetColorType(dib) == FIC_RGBALPHA) {
						return TRUE;
					}
				} else {
					return ((FREEIMAGEHEADER *)dib->data)->transparent ? TRUE : FALSE;
				}
				break;
			case FIT_RGBA16:
			case FIT_RGBAF:
				return TRUE;
			default:
				break;
		}
	}
	return FALSE;
}

BYTE * DLL_CALLCONV
FreeImage_GetTransparencyTable(FIBITMAP *dib) {
	return dib ? ((FREEIMAGEHEADER *)dib->data)->transparent_table : NULL;
}

void DLL_CALLCONV
FreeImage_SetTransparent(FIBITMAP *dib, BOOL enabled) {
	if (dib) {
		if ((FreeImage_GetBPP(dib) <= 8) || (FreeImage_GetBPP(dib) == 32)) {
			((FREEIMAGEHEADER *)dib->data)->transparent = enabled;
		} else {
			((FREEIMAGEHEADER *)dib->data)->transparent = FALSE;
		}
	}
}

unsigned DLL_CALLCONV
FreeImage_GetTransparencyCount(FIBITMAP *dib) {
	return dib ? ((FREEIMAGEHEADER *)dib->data)->transparency_count : 0;
}

void DLL_CALLCONV
FreeImage_SetTransparencyTable(FIBITMAP *dib, BYTE *table, int count) {
	if (dib) {
		count = MAX(0, MIN(count, 256));
		if (FreeImage_GetBPP(dib) <= 8) {
			((FREEIMAGEHEADER *)dib->data)->transparent = (count > 0) ? TRUE : FALSE;
			((FREEIMAGEHEADER *)dib->data)->transparency_count = count;

			if (table) {
				memcpy(((FREEIMAGEHEADER *)dib->data)->transparent_table, table, count);
			} else {
				memset(((FREEIMAGEHEADER *)dib->data)->transparent_table, 0xff, count);
			}
		} 
	}
}

/** @brief Sets the index of the palette entry to be used as transparent color
 for the image specified. Does nothing on high color images. 
 
 This method sets the index of the palette entry to be used as single transparent
 color for the image specified. This works on palletised images only and does
 nothing for high color images.
 
 Although it is possible for palletised images to have more than one transparent
 color, this method sets the palette entry specified as the single transparent
 color for the image. All other colors will be set to be non-transparent by this
 method.
 
 As with FreeImage_SetTransparencyTable(), this method also sets the image's
 transparency property to TRUE (as it is set and obtained by
 FreeImage_SetTransparent() and FreeImage_IsTransparent() respectively) for
 palletised images.
 
 @param dib Input image, whose transparent color is to be set.
 @param index The index of the palette entry to be set as transparent color.
 */
void DLL_CALLCONV
FreeImage_SetTransparentIndex(FIBITMAP *dib, int index) {
	if (dib) {
		int count = FreeImage_GetColorsUsed(dib);
		if (count) {
			BYTE *new_tt = (BYTE *)malloc(count * sizeof(BYTE));
			memset(new_tt, 0xFF, count);
			if ((index >= 0) && (index < count)) {
				new_tt[index] = 0x00;
			}
			FreeImage_SetTransparencyTable(dib, new_tt, count);
			free(new_tt);
		}
	}
}

/** @brief Returns the palette entry used as transparent color for the image
 specified. Works for palletised images only and returns -1 for high color
 images or if the image has no color set to be transparent. 
 
 Although it is possible for palletised images to have more than one transparent
 color, this function always returns the index of the first palette entry, set
 to be transparent. 
 
 @param dib Input image, whose transparent color is to be returned.
 @return Returns the index of the palette entry used as transparent color for
 the image specified or -1 if there is no transparent color found (e.g. the image
 is a high color image).
 */
int DLL_CALLCONV
FreeImage_GetTransparentIndex(FIBITMAP *dib) {
	int count = FreeImage_GetTransparencyCount(dib);
	BYTE *tt = FreeImage_GetTransparencyTable(dib);
	for (int i = 0; i < count; i++) {
		if (tt[i] == 0) {
			return i;
		}
	}
	return -1;
}

src/Source/FreeImage/Conversion32.cpp  view on Meta::CPAN

		target[FI_RGBA_BLUE]  = source[FI_RGBA_BLUE];
		target[FI_RGBA_ALPHA] = 0xFF;
		target += 4;
		source += 3;
	}
}

// ----------------------------------------------------------

inline void 
FreeImage_ConvertLine1To32MapTransparency(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette, BYTE *table, int transparent_pixels) {
	for (int cols = 0; cols < width_in_pixels; cols++) {
		int index = (source[cols>>3] & (0x80 >> (cols & 0x07))) != 0 ? 1 : 0;

		target[FI_RGBA_BLUE]	= palette[index].rgbBlue;
		target[FI_RGBA_GREEN]	= palette[index].rgbGreen;
		target[FI_RGBA_RED]		= palette[index].rgbRed;
		target[FI_RGBA_ALPHA] = (index < transparent_pixels) ? table[index] : 255;		
		target += 4;
	}	
}

inline void 
FreeImage_ConvertLine4To32MapTransparency(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette, BYTE *table, int transparent_pixels) {
	BOOL low_nibble = FALSE;
	int x = 0;

	for (int cols = 0 ; cols < width_in_pixels ; ++cols) {
		if (low_nibble) {
			target[FI_RGBA_BLUE]	= palette[LOWNIBBLE(source[x])].rgbBlue;
			target[FI_RGBA_GREEN]	= palette[LOWNIBBLE(source[x])].rgbGreen;
			target[FI_RGBA_RED]		= palette[LOWNIBBLE(source[x])].rgbRed;
			target[FI_RGBA_ALPHA]	= (LOWNIBBLE(source[x]) < transparent_pixels) ? table[LOWNIBBLE(source[x])] : 255;

			x++;
		} else {
			target[FI_RGBA_BLUE]	= palette[HINIBBLE(source[x]) >> 4].rgbBlue;
			target[FI_RGBA_GREEN]	= palette[HINIBBLE(source[x]) >> 4].rgbGreen;
			target[FI_RGBA_RED]		= palette[HINIBBLE(source[x]) >> 4].rgbRed;
			target[FI_RGBA_ALPHA]	= (HINIBBLE(source[x] >> 4) < transparent_pixels) ? table[HINIBBLE(source[x]) >> 4] : 255;
		}

		low_nibble = !low_nibble;
				
		target += 4;
	}
}

inline void 
FreeImage_ConvertLine8To32MapTransparency(BYTE *target, BYTE *source, int width_in_pixels, RGBQUAD *palette, BYTE *table, int transparent_pixels) {
	for (int cols = 0; cols < width_in_pixels; cols++) {
		target[FI_RGBA_BLUE]	= palette[source[cols]].rgbBlue;
		target[FI_RGBA_GREEN]	= palette[source[cols]].rgbGreen;
		target[FI_RGBA_RED]		= palette[source[cols]].rgbRed;
		target[FI_RGBA_ALPHA] = (source[cols] < transparent_pixels) ? table[source[cols]] : 255;
		target += 4;		
	}
}

// ----------------------------------------------------------

FIBITMAP * DLL_CALLCONV
FreeImage_ConvertTo32Bits(FIBITMAP *dib) {
	if(!FreeImage_HasPixels(dib)) return NULL;

src/Source/FreeImage/Conversion32.cpp  view on Meta::CPAN

		}

		FIBITMAP *new_dib = FreeImage_Allocate(width, height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
		if(new_dib == NULL) {
			return NULL;
		}

		// copy metadata from src to dst
		FreeImage_CloneMetadata(new_dib, dib);

		BOOL bIsTransparent = FreeImage_IsTransparent(dib);

		switch(bpp) {
			case 1:
			{
				if(bIsTransparent) {
					for (int rows = 0; rows < height; rows++) {
						FreeImage_ConvertLine1To32MapTransparency(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib), FreeImage_GetTransparencyTable(dib), FreeImage_GetTransparencyCount(dib));
					}
				} else {
					for (int rows = 0; rows < height; rows++) {
						FreeImage_ConvertLine1To32(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib));
					}					
				}

				return new_dib;
			}

			case 4:
			{
				if(bIsTransparent) {
					for (int rows = 0; rows < height; rows++) {
						FreeImage_ConvertLine4To32MapTransparency(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib), FreeImage_GetTransparencyTable(dib), FreeImage_GetTransparencyCount(dib));
					}
				} else {
					for (int rows = 0; rows < height; rows++) {
						FreeImage_ConvertLine4To32(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib));
					}					
				}

				return new_dib;
			}
				
			case 8:
			{
				if(bIsTransparent) {
					for (int rows = 0; rows < height; rows++) {
						FreeImage_ConvertLine8To32MapTransparency(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib), FreeImage_GetTransparencyTable(dib), FreeImage_GetTransparencyCount(dib));
					}
				} else {
					for (int rows = 0; rows < height; rows++) {
						FreeImage_ConvertLine8To32(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib));
					}					
				}

				return new_dib;

src/Source/FreeImage/MNGHelper.cpp  view on Meta::CPAN


			} // switch( GetChunckType )
		} // while(!mEnd)

		FreeImage_CloseMemory(hJpegMemory);
		FreeImage_CloseMemory(hPngMemory);
		FreeImage_CloseMemory(hIDATMemory);
		free(mChunk);
		free(PLTE_file_chunk);

		// convert to 32-bit if a transparent layer is available
		if(!header_only && dib_alpha) {
			FIBITMAP *dst = FreeImage_ConvertTo32Bits(dib);
			if((FreeImage_GetBPP(dib_alpha) == 8) && (FreeImage_GetImageType(dib_alpha) == FIT_BITMAP)) {
				FreeImage_SetChannel(dst, dib_alpha, FICC_ALPHA);
			} else {
				FIBITMAP *dst_alpha = FreeImage_ConvertTo8Bits(dib_alpha);
				FreeImage_SetChannel(dst, dst_alpha, FICC_ALPHA);
				FreeImage_Unload(dst_alpha);
			}			
			FreeImage_Unload(dib);

src/Source/FreeImage/PSDParser.cpp  view on Meta::CPAN

//---------------------------------------------------------------------------

psdParser::psdParser() {
	_bThumbnailFilled = false;
	_bDisplayInfoFilled = false;
	_bResolutionInfoFilled = false;
	_bResolutionInfoFilled_v2 = false;
	_bCopyright = false;
	_GlobalAngle = 30;
	_ColourCount = -1;
	_TransparentIndex = -1;
	_fi_flags = 0;
	_fi_format_id = FIF_UNKNOWN;
}

psdParser::~psdParser() {
}

bool psdParser::ReadLayerAndMaskInfoSection(FreeImageIO *io, fi_handle handle)	{
	bool bSuccess = false;
	

src/Source/FreeImage/PSDParser.cpp  view on Meta::CPAN


					// (Photoshop 6.0) Indexed Color Table Count
					// 2 bytes for the number of colors in table that are actually defined
					case 1046:
						n = (int)io->read_proc(&ShortValue, sizeof(ShortValue), 1, handle);
						nBytes += n * sizeof(ShortValue);
						_ColourCount = (short)psdGetValue(ShortValue, sizeof(ShortValue) );
						break;
						
					// (Photoshop 6.0) Transparency Index.
					// 2 bytes for the index of transparent color, if any.
					case 1047:
						n = (int)io->read_proc(&ShortValue, sizeof(ShortValue), 1, handle);
						nBytes += n * sizeof(ShortValue);
						_TransparentIndex = (short)psdGetValue(ShortValue, sizeof(ShortValue) );
						break;
						
					default:
					{
						// skip resource
						unsigned skip_length = MIN(oResource._Size, nTotalBytes - nBytes);
						io->seek_proc(handle, skip_length, SEEK_CUR);
						nBytes += skip_length;
					}
					break;

src/Source/FreeImage/PSDParser.h  view on Meta::CPAN

private:
	psdHeaderInfo			_headerInfo;
	psdColourModeData		_colourModeData;
	psdResolutionInfo		_resolutionInfo;
	psdResolutionInfo_v2	_resolutionInfo_v2;
	psdDisplayInfo			_displayInfo;
	psdThumbnail			_thumbnail;
	psdICCProfile			_iccProfile;

	short _ColourCount;
	short _TransparentIndex;
	int _GlobalAngle;
	bool _bResolutionInfoFilled;
	bool _bResolutionInfoFilled_v2;
	bool _bDisplayInfoFilled;
	bool _bThumbnailFilled;
	bool _bCopyright;

	int _fi_flags;
	int _fi_format_id;
	

src/Source/FreeImage/PluginBMP.cpp  view on Meta::CPAN


				// seek to the actual pixel data
				io->seek_proc(handle, bitmap_bits_offset, SEEK_SET);

				// read in the bitmap bits
				// load pixel data and swap as needed if OS is Big Endian
				LoadPixelData(io, handle, dib, height, pitch, bit_count);

				// check if the bitmap contains transparency, if so enable it in the header

				FreeImage_SetTransparent(dib, (FreeImage_GetColorType(dib) == FIC_RGBALPHA));

				return dib;
			}
			break; // 24-, 32-bit
		}
	} catch(const char *message) {
		if(dib) {
			FreeImage_Unload(dib);
		}
		if(message) {

src/Source/FreeImage/PluginBMP.cpp  view on Meta::CPAN

				if (bitmap_bits_offset > (sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (used_colors * 3))) {
					io->seek_proc(handle, bitmap_bits_offset, SEEK_SET);
				}
				
				// read in the bitmap bits
				// load pixel data and swap as needed if OS is Big Endian
				LoadPixelData(io, handle, dib, height, pitch, bit_count);

				// check if the bitmap contains transparency, if so enable it in the header

				FreeImage_SetTransparent(dib, (FreeImage_GetColorType(dib) == FIC_RGBALPHA));

				return dib;
			}
		}
	} catch(const char *message) {
		if(dib)
			FreeImage_Unload(dib);

		FreeImage_OutputMessageProc(s_format_id, message);
	}

src/Source/FreeImage/PluginBMP.cpp  view on Meta::CPAN

				}

				// Skip over the optional palette 
				// A 24 or 32 bit DIB may contain a palette for faster color reduction

				// load pixel data and swap as needed if OS is Big Endian
				LoadPixelData(io, handle, dib, height, pitch, bit_count);

				// check if the bitmap contains transparency, if so enable it in the header

				FreeImage_SetTransparent(dib, (FreeImage_GetColorType(dib) == FIC_RGBALPHA));

				return dib;
			}
		}
	} catch(const char *message) {	
		if(dib)
			FreeImage_Unload(dib);

		FreeImage_OutputMessageProc(s_format_id, message);
	}

src/Source/FreeImage/PluginDDS.cpp  view on Meta::CPAN

	if (wCol[0] > wCol[1] || !isDXT1) {
		// 4 color block
		for (i = 0; i < 2; i++)	{
			colors[i + 2].a = 0xff;
			colors[i + 2].r = (BYTE)((WORD (colors[0].r) * (2 - i) + WORD (colors[1].r) * (1 + i)) / 3);
			colors[i + 2].g = (BYTE)((WORD (colors[0].g) * (2 - i) + WORD (colors[1].g) * (1 + i)) / 3);
			colors[i + 2].b = (BYTE)((WORD (colors[0].b) * (2 - i) + WORD (colors[1].b) * (1 + i)) / 3);
		}
	}
	else {
		// 3 color block, number 4 is transparent
		colors[2].a = 0xff;
		colors[2].r = (BYTE)((WORD (colors[0].r) + WORD (colors[1].r)) / 2);
		colors[2].g = (BYTE)((WORD (colors[0].g) + WORD (colors[1].g)) / 2);
		colors[2].b = (BYTE)((WORD (colors[0].b) + WORD (colors[1].b)) / 2);

		colors[3].a = 0x00;
		colors[3].g = 0x00;
		colors[3].b = 0x00;
		colors[3].r = 0x00;
	}

src/Source/FreeImage/PluginDDS.cpp  view on Meta::CPAN

		io->seek_proc (handle, delta, SEEK_CUR);
#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB
 		for(int x = 0; x < width; x++) {
			INPLACESWAP(pixels[FI_RGBA_RED],pixels[FI_RGBA_BLUE]);
			pixels += bytespp;
		}
#endif
	}
	
	// enable transparency
	FreeImage_SetTransparent (dib, (desc.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS) ? TRUE : FALSE);

	if (!(desc.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS) && bpp == 32) {
		// no transparency: convert to 24-bit
		FIBITMAP *old = dib;
		dib = FreeImage_ConvertTo24Bits (old);
		FreeImage_Unload (old);
	}
	return dib;
}

src/Source/FreeImage/PluginGIF.cpp  view on Meta::CPAN


	if( page == -1 ) {
		page = 0;
	}
	if( page < 0 || page >= (int)info->image_descriptor_offsets.size() ) {
		return NULL;
	}

	FIBITMAP *dib = NULL;
	try {
		bool have_transparent = false, no_local_palette = false, interlaced = false;
		int disposal_method = GIF_DISPOSAL_LEAVE, delay_time = 0, transparent_color = 0;
		WORD left, top, width, height;
		BYTE packed, b;
		WORD w;

		//playback pages to generate what the user would see for this frame
		if( (flags & GIF_PLAYBACK) == GIF_PLAYBACK ) {
			//Logical Screen Descriptor
			io->seek_proc(handle, 6, SEEK_SET);
			WORD logicalwidth, logicalheight;
			io->read_proc(&logicalwidth, 2, 1, handle);

src/Source/FreeImage/PluginGIF.cpp  view on Meta::CPAN

				}
			}

			//cache some info about each of the pages so we can avoid decoding as many of them as possible
			std::vector<PageInfo> pageinfo;
			int start = page, end = page;
			while( start >= 0 ) {
				//Graphic Control Extension
				io->seek_proc(handle, (long)(info->graphic_control_extension_offsets[start] + 1), SEEK_SET);
				io->read_proc(&packed, 1, 1, handle);
				have_transparent = (packed & GIF_PACKED_GCE_HAVETRANS) ? true : false;
				disposal_method = (packed & GIF_PACKED_GCE_DISPOSAL) >> 2;
				//Image Descriptor
				io->seek_proc(handle, (long)(info->image_descriptor_offsets[start]), SEEK_SET);
				io->read_proc(&left, 2, 1, handle);
				io->read_proc(&top, 2, 1, handle);
				io->read_proc(&width, 2, 1, handle);
				io->read_proc(&height, 2, 1, handle);
#ifdef FREEIMAGE_BIGENDIAN
				SwapShort(&left);
				SwapShort(&top);

src/Source/FreeImage/PluginGIF.cpp  view on Meta::CPAN


				pageinfo.push_back(PageInfo(disposal_method, left, top, width, height));

				if( start != end ) {
					if( left == 0 && top == 0 && width == logicalwidth && height == logicalheight ) {
						if( disposal_method == GIF_DISPOSAL_BACKGROUND ) {
							pageinfo.pop_back();
							start++;
							break;
						} else if( disposal_method != GIF_DISPOSAL_PREVIOUS ) {
							if( !have_transparent ) {
								break;
							}
						}
					}
				}
				start--;
			}
			if( start < 0 ) {
				start = 0;
			}

src/Source/FreeImage/PluginGIF.cpp  view on Meta::CPAN

							}
						}
						continue;
					}
				}

				//decode page
				FIBITMAP *pagedib = Load(io, handle, page, GIF_LOAD256, data);
				if( pagedib != NULL ) {
					RGBQUAD *pal = FreeImage_GetPalette(pagedib);
					have_transparent = false;
					if( FreeImage_IsTransparent(pagedib) ) {
						int count = FreeImage_GetTransparencyCount(pagedib);
						BYTE *table = FreeImage_GetTransparencyTable(pagedib);
						for( int i = 0; i < count; i++ ) {
							if( table[i] == 0 ) {
								have_transparent = true;
								transparent_color = i;
								break;
							}
						}
					}
					//copy page data into logical buffer, with full alpha opaqueness
					for( y = 0; y < info.height; y++ ) {
						const int scanidx = logicalheight - (y + info.top) - 1;
						if ( scanidx < 0 ) {
							break;  // If data is corrupt, don't calculate in invalid scanline
						}
						scanline = (RGBQUAD *)FreeImage_GetScanLine(dib, scanidx) + info.left;
						BYTE *pageline = FreeImage_GetScanLine(pagedib, info.height - y - 1);
						for( x = 0; x < info.width; x++ ) {
							if( !have_transparent || *pageline != transparent_color ) {
								*scanline = pal[*pageline];
								scanline->rgbReserved = 255;
							}
							scanline++;
							pageline++;
						}
					}
					//copy frame time
					if( page == end ) {
						FITAG *tag;

src/Source/FreeImage/PluginGIF.cpp  view on Meta::CPAN


		//Graphic Control Extension
		if( info->graphic_control_extension_offsets[page] != 0 ) {
			io->seek_proc(handle, (long)(info->graphic_control_extension_offsets[page] + 1), SEEK_SET);
			io->read_proc(&packed, 1, 1, handle);
			io->read_proc(&w, 2, 1, handle);
#ifdef FREEIMAGE_BIGENDIAN
			SwapShort(&w);
#endif
			io->read_proc(&b, 1, 1, handle);
			have_transparent = (packed & GIF_PACKED_GCE_HAVETRANS) ? true : false;
			disposal_method = (packed & GIF_PACKED_GCE_DISPOSAL) >> 2;
			delay_time = w * 10; //convert cs to ms
			transparent_color = b;
			if( have_transparent ) {
				int size = 1 << bpp;
				if( transparent_color <= size ) {
					BYTE table[256];
					memset(table, 0xFF, size);
					table[transparent_color] = 0;
					FreeImage_SetTransparencyTable(dib, table, size);
				}
			}
		}
		FreeImage_SetMetadataEx(FIMD_ANIMATION, dib, "FrameTime", ANIMTAG_FRAMETIME, FIDT_LONG, 1, 4, &delay_time);
		b = (BYTE)disposal_method;
		FreeImage_SetMetadataEx(FIMD_ANIMATION, dib, "DisposalMethod", ANIMTAG_DISPOSALMETHOD, FIDT_BYTE, 1, 1, &b);

		delete stringtable;

src/Source/FreeImage/PluginGIF.cpp  view on Meta::CPAN

	try {
		BYTE packed, b;
		WORD w;
		FITAG *tag;

		int bpp = FreeImage_GetBPP(dib);
		if( bpp != 1 && bpp != 4 && bpp != 8 ) {
			throw "Only 1, 4, or 8 bpp images supported";
		}

		bool have_transparent = false, no_local_palette = false, interlaced = false;
		int disposal_method = GIF_DISPOSAL_BACKGROUND, delay_time = 100, transparent_color = 0;
		WORD left = 0, top = 0, width = (WORD)FreeImage_GetWidth(dib), height = (WORD)FreeImage_GetHeight(dib);
		WORD output_height = height;
		if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "FrameLeft", FIDT_SHORT, &tag) ) {
			left = *(WORD *)FreeImage_GetTagValue(tag);
		}
		if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "FrameTop", FIDT_SHORT, &tag) ) {
			top = *(WORD *)FreeImage_GetTagValue(tag);
		}
		if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "NoLocalPalette", FIDT_BYTE, &tag) ) {
			no_local_palette = *(BYTE *)FreeImage_GetTagValue(tag) ? true : false;

src/Source/FreeImage/PluginGIF.cpp  view on Meta::CPAN

						b = 0;
						io->write_proc(&b, 1, 1, handle);
					}
				} while(FreeImage_FindNextMetadata(mdhandle, &tag));

				FreeImage_FindCloseMetadata(mdhandle);
			}
		}

		//Graphic Control Extension
		if( FreeImage_IsTransparent(dib) ) {
			int count = FreeImage_GetTransparencyCount(dib);
			BYTE *table = FreeImage_GetTransparencyTable(dib);
			for( int i = 0; i < count; i++ ) {
				if( table[i] == 0 ) {
					have_transparent = true;
					transparent_color = i;
					break;
				}
			}
		}
		io->write_proc((void *)"\x21\xF9\x04", 3, 1, handle);
		b = (BYTE)((disposal_method << 2) & GIF_PACKED_GCE_DISPOSAL);
		if( have_transparent ) b |= GIF_PACKED_GCE_HAVETRANS;
		io->write_proc(&b, 1, 1, handle);
		//Notes about delay time for GIFs:
		//IE5/IE6 have a minimum and default of 100ms
		//Mozilla/Firefox/Netscape 6+/Opera have a minimum of 20ms and a default of 100ms if <20ms is specified or the GCE is absent
		//Netscape 4 has a minimum of 10ms if 0ms is specified, but will use 0ms if the GCE is absent
		w = (WORD)(delay_time / 10); //convert ms to cs
#ifdef FREEIMAGE_BIGENDIAN
		SwapShort(&w);
#endif
		io->write_proc(&w, 2, 1, handle);
		b = (BYTE)transparent_color;
		io->write_proc(&b, 1, 1, handle);
		b = 0;
		io->write_proc(&b, 1, 1, handle);

		//Image Descriptor
		b = GIF_BLOCK_IMAGE_DESCRIPTOR;
		io->write_proc(&b, 1, 1, handle);
		io->write_proc(&left, 2, 1, handle);
		io->write_proc(&top, 2, 1, handle);
		io->write_proc(&width, 2, 1, handle);

src/Source/FreeImage/PluginICO.cpp  view on Meta::CPAN

		io->write_proc(xor_mask, size_xor, 1, handle);
#if defined(FREEIMAGE_BIGENDIAN) || FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB
	}
#endif
	// AND mask
	BYTE *and_mask = (BYTE*)malloc(size_and);
	if(!and_mask) {
		return FALSE;
	}

	if(FreeImage_IsTransparent(dib)) {

		if(bit_count == 32) {
			// create the AND mask from the alpha channel

			int width_and  = WidthBytes(width);
			BYTE *and_bits = and_mask;

			// clear the mask
			memset(and_mask, 0, size_and);

			for(int y = 0; y < height; y++) {
				RGBQUAD *bits = (RGBQUAD*)FreeImage_GetScanLine(dib, y);

				for(int x = 0; x < width; x++) {
					if(bits[x].rgbReserved != 0xFF) {
						// set any transparent color to full transparency
						and_bits[x >> 3] |= (0x80 >> (x & 0x7)); 
					}
				}

				and_bits += width_and;
			}
		} 
		else if(bit_count <= 8) {
			// create the AND mask from the transparency table

src/Source/FreeImage/PluginICO.cpp  view on Meta::CPAN


			switch(FreeImage_GetBPP(dib)) {
				case 1:
				{
					for(int y = 0; y < height; y++) {
						BYTE *bits = (BYTE*)FreeImage_GetScanLine(dib, y);
						for(int x = 0; x < width; x++) {
							// get pixel at (x, y)
							BYTE index = (bits[x >> 3] & (0x80 >> (x & 0x07))) != 0;
							if(trns[index] != 0xFF) {
								// set any transparent color to full transparency
								and_bits[x >> 3] |= (0x80 >> (x & 0x7)); 
							}
						}
						and_bits += width_and;
					}
				}
				break;

				case 4:
				{
					for(int y = 0; y < height; y++) {
						BYTE *bits = (BYTE*)FreeImage_GetScanLine(dib, y);
						for(int x = 0; x < width; x++) {
							// get pixel at (x, y)
							BYTE shift = (BYTE)((1 - x % 2) << 2);
							BYTE index = (bits[x >> 1] & (0x0F << shift)) >> shift;
							if(trns[index] != 0xFF) {
								// set any transparent color to full transparency
								and_bits[x >> 3] |= (0x80 >> (x & 0x7)); 
							}
						}
						and_bits += width_and;
					}
				}
				break;

				case 8:
				{
					for(int y = 0; y < height; y++) {
						BYTE *bits = (BYTE*)FreeImage_GetScanLine(dib, y);
						for(int x = 0; x < width; x++) {
							// get pixel at (x, y)
							BYTE index = bits[x];
							if(trns[index] != 0xFF) {
								// set any transparent color to full transparency
								and_bits[x >> 3] |= (0x80 >> (x & 0x7)); 
							}
						}
						and_bits += width_and;
					}
				}
				break;

			}
		}

src/Source/FreeImage/PluginIFF.cpp  view on Meta::CPAN

#pragma pack(1)
#endif

typedef struct {
    WORD w, h;                    /* raster width & height in pixels */
    WORD x, y;                    /* position for this image */
    BYTE nPlanes;                 /* # source bitplanes */
    BYTE masking;                 /* masking technique */
    BYTE compression;             /* compression algorithm */
    BYTE pad1;                    /* UNUSED.  For consistency, put 0 here.*/
    WORD transparentColor;        /* transparent "color number" */
    BYTE xAspect, yAspect;        /* aspect ratio, a rational number x/y */
    WORD pageWidth, pageHeight;   /* source "page" size in pixels */
} BMHD;

#ifdef _WIN32
#pragma pack(pop)
#else
#pragma pack()
#endif

#ifndef FREEIMAGE_BIGENDIAN
static void
SwapHeader(BMHD *header) {
	SwapShort(&header->w);
	SwapShort(&header->h);
	SwapShort(&header->x);
	SwapShort(&header->y);
	SwapShort(&header->transparentColor);
	SwapShort(&header->pageWidth);
	SwapShort(&header->pageHeight);
}
#endif

// ----------------------------------------------------------

/* IFF chunk IDs */

typedef DWORD IFF_ID;

src/Source/FreeImage/PluginPNG.cpp  view on Meta::CPAN

*/
static BOOL 
ConfigureDecoder(png_structp png_ptr, png_infop info_ptr, int flags, FREE_IMAGE_TYPE *output_image_type) {
	// get original image info
	const int color_type = png_get_color_type(png_ptr, info_ptr);
	const int bit_depth = png_get_bit_depth(png_ptr, info_ptr);
	const int pixel_depth = bit_depth * png_get_channels(png_ptr, info_ptr);

	FREE_IMAGE_TYPE image_type = FIT_BITMAP;	// assume standard image type

	// check for transparency table or single transparent color
	BOOL bIsTransparent = png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) == PNG_INFO_tRNS ? TRUE : FALSE;

	// check allowed combinations of colour type and bit depth
	// then get converted FreeImage type

	switch(color_type) {
		case PNG_COLOR_TYPE_GRAY:		// color type '0', bitdepth = 1, 2, 4, 8, 16
			switch(bit_depth) {
				case 1:
				case 2:
				case 4:
				case 8:
					// expand grayscale images to the full 8-bit from 2-bit/pixel
					if (pixel_depth == 2) {
						png_set_expand_gray_1_2_4_to_8(png_ptr);
					}

					// if a tRNS chunk is provided, we must also expand the grayscale data to 8-bits,
					// this allows us to make use of the transparency table with existing FreeImage methods
					if (bIsTransparent && (pixel_depth < 8)) {
						png_set_expand_gray_1_2_4_to_8(png_ptr);
					}
					break;

				case 16:
					image_type = (pixel_depth == 16) ? FIT_UINT16 : FIT_UNKNOWN;

					// 16-bit grayscale images can contain a transparent value (shade)
					// if found, expand the transparent value to a full alpha channel
					if (bIsTransparent && (image_type != FIT_UNKNOWN)) {
						// expand tRNS to a full alpha channel
						png_set_tRNS_to_alpha(png_ptr);
						
						// expand new 16-bit gray + 16-bit alpha to full 64-bit RGBA
						png_set_gray_to_rgb(png_ptr);

						image_type = FIT_RGBA16;
					}
					break;

src/Source/FreeImage/PluginPNG.cpp  view on Meta::CPAN

					break;
				case 16:
					image_type = (pixel_depth == 48) ? FIT_RGB16 : FIT_UNKNOWN;
					break;
				default:
					image_type = FIT_UNKNOWN;
					break;
			}
			// sometimes, 24- or 48-bit images may contain transparency information
			// check for this use case and convert to an alpha-compatible format
			if (bIsTransparent && (image_type != FIT_UNKNOWN)) {
				// if the image is 24-bit RGB, mark it as 32-bit; if it is 48-bit, mark it as 64-bit
				image_type = (pixel_depth == 24) ? FIT_BITMAP : (pixel_depth == 48) ? FIT_RGBA16 : FIT_UNKNOWN;
				// expand tRNS chunk to alpha channel
				png_set_tRNS_to_alpha(png_ptr);
			}
			break;

		case PNG_COLOR_TYPE_PALETTE:	// color type '3', bitdepth = 1, 2, 4, 8
			switch(bit_depth) {
				case 1:
				case 2:
				case 4:
				case 8:
					// expand palette images to the full 8 bits from 2 bits/pixel
					if (pixel_depth == 2) {
						png_set_packing(png_ptr);
					}

					// if a tRNS chunk is provided, we must also expand the palletized data to 8-bits,
					// this allows us to make use of the transparency table with existing FreeImage methods
					if (bIsTransparent && (pixel_depth < 8)) {
						png_set_packing(png_ptr);
					}
					break;

				default:
					image_type = FIT_UNKNOWN;
					break;
			}
			break;

src/Source/FreeImage/PluginPNG.cpp  view on Meta::CPAN


			if(!dib) {
				throw FI_MSG_ERROR_DIB_MEMORY;
			}

			// store the transparency table

			if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
				// array of alpha (transparency) entries for palette
				png_bytep trans_alpha = NULL;
				// number of transparent entries
				int num_trans = 0;						
				// graylevel or color sample values of the single transparent color for non-paletted images
				png_color_16p trans_color = NULL;

				png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color);

				if((color_type == PNG_COLOR_TYPE_GRAY) && trans_color) {
					// single transparent color
					if (trans_color->gray < 256) { 
						BYTE table[256]; 
						memset(table, 0xFF, 256); 
						table[trans_color->gray] = 0; 
						FreeImage_SetTransparencyTable(dib, table, 256); 
					}
					// check for a full transparency table, too
					else if ((trans_alpha) && (pixel_depth <= 8)) {
						FreeImage_SetTransparencyTable(dib, (BYTE *)trans_alpha, num_trans);
					}

				} else if((color_type == PNG_COLOR_TYPE_PALETTE) && trans_alpha) {
					// transparency table
					FreeImage_SetTransparencyTable(dib, (BYTE *)trans_alpha, num_trans);
				}
			}

			// store the background color (only supported for FIT_BITMAP types)

			if ((image_type == FIT_BITMAP) && png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD)) {
				// Get the background color to draw transparent and alpha images over.
				// Note that even if the PNG file supplies a background, you are not required to
				// use it - you should use the (solid) application background if it has one.

				png_color_16p image_background = NULL;
				RGBQUAD rgbBkColor;

				if (png_get_bKGD(png_ptr, info_ptr, &image_background)) {
					rgbBkColor.rgbRed      = (BYTE)image_background->red;
					rgbBkColor.rgbGreen    = (BYTE)image_background->green;
					rgbBkColor.rgbBlue     = (BYTE)image_background->blue;

src/Source/FreeImage/PluginPNG.cpp  view on Meta::CPAN

				row_pointers[height - 1 - k] = FreeImage_GetScanLine(dib, k);
			}

			png_set_benign_errors(png_ptr, 1);
			png_read_image(png_ptr, row_pointers);

			// check if the bitmap contains transparency, if so enable it in the header

			if (FreeImage_GetBPP(dib) == 32) {
				if (FreeImage_GetColorType(dib) == FIC_RGBALPHA) {
					FreeImage_SetTransparent(dib, TRUE);
				} else {
					FreeImage_SetTransparent(dib, FALSE);
				}
			}
				
			// cleanup

			if (row_pointers) {
				free(row_pointers);
				row_pointers = NULL;
			}

src/Source/FreeImage/PluginPNG.cpp  view on Meta::CPAN


			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;
			}

			// check for transparent images
			BOOL bIsTransparent = 
				(image_type == FIT_BITMAP) && FreeImage_IsTransparent(dib) && (FreeImage_GetTransparencyCount(dib) > 0) ? TRUE : FALSE;

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

				case FIC_MINISBLACK:
					if(!bIsTransparent) {
						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;
					}
					// If a monochrome image is transparent, save it with a palette
					// (fall through)

				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

src/Source/FreeImage/PluginPNG.cpp  view on Meta::CPAN

			// write metadata

			WriteMetadata(png_ptr, info_ptr, dib);

			// Optional gamma chunk is strongly suggested if you have any guess
			// as to the correct gamma of the image.
			// png_set_gAMA(png_ptr, info_ptr, gamma);

			// set the transparency table

			if (bIsTransparent) {
				png_set_tRNS(png_ptr, info_ptr, FreeImage_GetTransparencyTable(dib), FreeImage_GetTransparencyCount(dib), NULL);
			}

			// set the background color

			if(FreeImage_HasBackgroundColor(dib)) {
				png_color_16 image_background;
				RGBQUAD rgbBkColor;

				FreeImage_GetBackgroundColor(dib, &rgbBkColor);

src/Source/FreeImage/PluginPNG.cpp  view on Meta::CPAN

#endif

			int number_passes = 1;
			if (bInterlaced) {
				number_passes = png_set_interlace_handling(png_ptr);
			}

			if ((pixel_depth == 32) && (!has_alpha_channel)) {
				BYTE *buffer = (BYTE *)malloc(width * 3);

				// transparent conversion to 24-bit
				// the number of passes is either 1 for non-interlaced images, or 7 for interlaced images
				for (int pass = 0; pass < number_passes; pass++) {
					for (png_uint_32 k = 0; k < height; k++) {
						FreeImage_ConvertLine32To24(buffer, FreeImage_GetScanLine(dib, height - k - 1), width);
						png_write_row(png_ptr, buffer);
					}
				}
				free(buffer);
			} else {
				// the number of passes is either 1 for non-interlaced images, or 7 for interlaced images

src/Source/FreeImage/PluginTARGA.cpp  view on Meta::CPAN

	header.is_width = (WORD)FreeImage_GetWidth(dib);
	header.is_height = (WORD)FreeImage_GetHeight(dib);
	header.is_pixel_depth = (BYTE)bpp;
	header.is_image_descriptor = (bpp == 32 ? 8 : 0);

	if (palette) {
		header.color_map_type = 1;
		header.image_type = (TARGA_SAVE_RLE & flags) ? TGA_RLECMAP : TGA_CMAP;
		header.cm_length = (WORD)(1 << bpp);

		if (FreeImage_IsTransparent(dib)) {
			header.cm_size = 32;
		} else {
			header.cm_size = 24;
		}

	} else {
		header.color_map_type = 0;
		header.image_type = (TARGA_SAVE_RLE & flags) ? TGA_RLERGB : TGA_RGB;
		header.cm_length = 0;
		header.cm_size = 0;

src/Source/FreeImage/PluginTARGA.cpp  view on Meta::CPAN


	io->write_proc(&header, sizeof(header), 1, handle);

#ifdef FREEIMAGE_BIGENDIAN
	SwapHeader(&header);
#endif

	// write the palette

	if (palette) {
		if (FreeImage_IsTransparent(dib)) {
			FILE_BGRA *bgra_pal = (FILE_BGRA*)malloc(header.cm_length * sizeof(FILE_BGRA));

			// get the transparency table
			BYTE *trns = FreeImage_GetTransparencyTable(dib);

			for (unsigned i = 0; i < header.cm_length; i++) {
				bgra_pal[i].b = palette[i].rgbBlue;
				bgra_pal[i].g = palette[i].rgbGreen;
				bgra_pal[i].r = palette[i].rgbRed;
				bgra_pal[i].a = trns[i];

src/Source/FreeImage/PluginTIFF.cpp  view on Meta::CPAN

	}

	int bpp = bitspersample * samplesperpixel;

	if(fit == FIT_BITMAP) {
		// standard bitmap type 

		if(bpp == 16) {
			
			if((samplesperpixel == 2) && (bitspersample == 8)) {
				// 8-bit indexed + 8-bit alpha channel -> convert to 8-bit transparent
				dib = FreeImage_AllocateHeader(header_only, width, height, 8);
			} else {
				// 16-bit RGB -> expect it to be 565
				dib = FreeImage_AllocateHeader(header_only, width, height, bpp, FI16_565_RED_MASK, FI16_565_GREEN_MASK, FI16_565_BLUE_MASK);
			}
			
		}
		else {

			dib = FreeImage_AllocateHeader(header_only, width, height, MIN(bpp, 32), FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);

src/Source/FreeImage/PluginTIFF.cpp  view on Meta::CPAN

							bits += 3;
						}
						row += width;
					}
				}

				_TIFFfree(raster);
			}
			
			// ### Not correct when header only
			FreeImage_SetTransparent(dib, has_alpha);

		} else if(loadMethod == LoadAs8BitTrns) {
			// ---------------------------------------------------------------------------------
			// 8-bit + 8-bit alpha layer loading
			// ---------------------------------------------------------------------------------

			// create a new 8-bit DIB
			dib = CreateImageType(header_only, image_type, width, height, bitspersample, MIN<uint16>(2, samplesperpixel));
			if (dib == NULL) {
				throw FI_MSG_ERROR_MEMORY;

src/Source/FreeImage/PluginTIFF.cpp  view on Meta::CPAN

						}
						bits -= dst_pitch;
					}
				}

				free(buf);

			}
			
			FreeImage_SetTransparencyTable(dib, &trns[0], 256);
			FreeImage_SetTransparent(dib, TRUE);

		} else if(loadMethod == LoadAsCMYK) {
			// ---------------------------------------------------------------------------------
			// CMYK loading
			// ---------------------------------------------------------------------------------

			// At this place, samplesperpixel could be > 4, esp. when a CMYK(A) format
			// is recognized. Where all other formats are handled straight-forward, this
			// format has to be handled special 

src/Source/FreeImage/PluginTIFF.cpp  view on Meta::CPAN

		uint16 samplesperpixel;
		uint16 photometric;

		if(image_type == FIT_BITMAP) {
			// standard image: 1-, 4-, 8-, 16-, 24-, 32-bit

			samplesperpixel = ((bitsperpixel == 24) ? 3 : ((bitsperpixel == 32) ? 4 : 1));
			bitspersample = bitsperpixel / samplesperpixel;
			photometric	= GetPhotometric(dib);

			if((bitsperpixel == 8) && FreeImage_IsTransparent(dib)) {
				// 8-bit transparent picture : convert later to 8-bit + 8-bit alpha
				samplesperpixel = 2;
				bitspersample = 8;
			}
			else if(bitsperpixel == 32) {
				// 32-bit images : check for CMYK or alpha transparency

				if((((iccProfile->flags & FIICC_COLOR_IS_CMYK) == FIICC_COLOR_IS_CMYK) || ((flags & TIFF_CMYK) == TIFF_CMYK))) {
					// CMYK support
					photometric = PHOTOMETRIC_SEPARATED;
					TIFFSetField(out, TIFFTAG_INKSET, INKSET_CMYK);

src/Source/FreeImage/PluginTIFF.cpp  view on Meta::CPAN

		const uint32 pitch = FreeImage_GetPitch(dib);

		if(image_type == FIT_BITMAP) {
			// standard bitmap type
		
			switch(bitsperpixel) {
				case 1 :
				case 4 :
				case 8 :
				{
					if((bitsperpixel == 8) && FreeImage_IsTransparent(dib)) {
						// 8-bit transparent picture : convert to 8-bit + 8-bit alpha

						// get the transparency table
						BYTE *trns = FreeImage_GetTransparencyTable(dib);

						BYTE *buffer = (BYTE *)malloc(2 * width * sizeof(BYTE));
						if(buffer == NULL) {
							throw FI_MSG_ERROR_MEMORY;
						}

						for (int y = height - 1; y >= 0; y--) {

src/Source/FreeImageToolkit/Background.cpp  view on Meta::CPAN

				if (m == 0) {
					break;
				}
			}
			palette += sizeof(RGBQUAD);
		}		
	}
	return result;
}

/** @brief Blends an alpha-transparent foreground color over an opaque background
 color.
 
 This function blends the alpha-transparent foreground color fgcolor over the
 background color bgcolor. The background color is considered fully opaque,
 whatever it's alpha value contains, whereas the foreground color is considered
 to be a real RGBA color with an alpha value, which is used for the blend
 operation. The resulting color is returned through the blended parameter.
 @param bgcolor The background color for the blend operation.
 @param fgcolor The foreground color for the blend operation. This color's alpha
 value, stored in the rgbReserved member, is the alpha value used for the blend
 operation.
 @param blended This out parameter takes the blended color and so, returns it to
 the caller. This color's alpha value will be 0xFF (255) so, the blended color

src/Source/FreeImageToolkit/Background.cpp  view on Meta::CPAN

	BYTE *src_bits = FreeImage_GetScanLine(dib, 0);
	BYTE *dst_bits = src_bits;	
	
	BOOL supports_alpha = ((bpp >= 24) || ((bpp == 8) && (color_type != FIC_PALETTE)));
	
	// Check for RGBA case if bitmap supports alpha 
	// blending (8-bit greyscale, 24- or 32-bit images)
	if (supports_alpha && (options & FI_COLOR_IS_RGBA_COLOR)) {
		
		if (color->rgbReserved == 0) {
			// the fill color is fully transparent; we are done
			return TRUE;
		}
		
		// Only if the fill color is NOT fully opaque, draw it with
		// the (much) slower FreeImage_DrawLine function and return.
		// Since we do not have the FreeImage_DrawLine function in this
		// release, just assume to have an unicolor background and fill
		// all with an 'alpha-blended' color.
		if (color->rgbReserved < 255) {
							

src/Source/FreeImageToolkit/Background.cpp  view on Meta::CPAN

 by an RGBQUAD structure for all images of type FIT_BITMAP (including all palletized
 images), the smallest possible size of this memory is the size of the RGBQUAD structure,
 which uses 4 bytes.

 So, color must point to a double, if the image to be filled is of type FIT_DOUBLE and
 point to a RGBF structure if the image is of type FIT_RGBF and so on.

 However, the fill color is always specified through a RGBQUAD structure for all images
 of type FIT_BITMAP. So, for 32- and 24-bit images, the red, green and blue members of
 the RGBQUAD structure are directly used for the image's red, green and blue channel
 respectively. Although alpha transparent RGBQUAD colors are supported, the alpha channel
 of a 32-bit image never gets modified by this function. A fill color with an alpha value
 smaller than 255 gets blended with the image's actual background color, which is determined
 from the image's bottom-left pixel. So, currently using alpha enabled colors, assumes the
 image to be unicolor before the fill operation. However, the RGBQUAD's rgbReserved member is
 only taken into account, if option FI_COLOR_IS_RGBA_COLOR has been specified.

 For 16-bit images, the red-, green- and blue components of the specified color are
 transparently translated into either the 16-bit 555 or 565 representation. This depends
 on the image's actual red- green- and blue masks.

 Special attention must be payed for palletized images. Generally, the RGB color specified
 is looked up in the image's palette. The found palette index is then used to fill the image.
 There are some option flags, that affect this lookup process:

 no option specified       (0x00)   Uses the color, that is nearest to the specified color.
                                    This is the default behavior and should always find a
                                    color in the palette. However, the visual result may
                                    far from what was expected and mainly depends on the

src/Source/FreeImageToolkit/Background.cpp  view on Meta::CPAN

 So, calling this function with all parameters left, top, right and bottom set to zero, is
 effectively the same as calling function FreeImage_Clone; setting all parameters left, top,
 right and bottom to value equal to or smaller than zero, my easily be substituted by a call
 to function FreeImage_Copy. Both these cases produce a new image, which is guaranteed not to
 be larger than the input image. Thus, since the specified color is not needed in these cases,
 the pointer color may be NULL.

 Both parameters color and options work according to function FreeImage_FillBackground. So,
 please refer to the documentation of FreeImage_FillBackground to learn more about parameters
 color and options. For palletized images, the palette of the input image src is
 transparently copied to the newly created enlarged or shrunken image, so any color
 look-ups are performed on this palette.

 Here are some examples, that illustrate, how to use the parameters left, top, right and
 bottom:

 // create a white color
 RGBQUAD c;
 c.rgbRed = 0xFF;
 c.rgbGreen = 0xFF;
 c.rgbBlue = 0xFF;

src/Source/FreeImageToolkit/Colors.cpp  view on Meta::CPAN

 <i>dstcolors</i> are also mapped to these specified in <i>srccolors</i>. For
 high color images, the actual image data will be modified whereas, for
 palletized images only the palette will be changed.<br>

 The function returns the number of pixels changed or zero, if no pixels were
 changed. 

 Both arrays <i>srccolors</i> and <i>dstcolors</i> are assumed not to hold less
 than <i>count</i> colors.<br>

 For 16-bit images, all colors specified are transparently converted to their 
 proper 16-bit representation (either in RGB555 or RGB565 format, which is
 determined by the image's red- green- and blue-mask).<br>

 <b>Note, that this behaviour is different from what FreeImage_ApplyPaletteIndexMapping()
 does, which modifies the actual image data on palletized images.</b>

 @param dib Input/output image to be processed.
 @param srccolors Array of colors to be used as the mapping source.
 @param dstcolors Array of colors to be used as the mapping destination.
 @param count The number of colors to be mapped. This is the size of both

src/Source/FreeImageToolkit/Display.cpp  view on Meta::CPAN

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))

src/Source/FreeImageToolkit/Display.cpp  view on Meta::CPAN

	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

src/Source/FreeImageToolkit/Display.cpp  view on Meta::CPAN


		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) {
				// get the foreground color
				fgc.rgbBlue  = fg_bits[FI_RGBA_BLUE];
				fgc.rgbGreen = fg_bits[FI_RGBA_GREEN];
				fgc.rgbRed   = fg_bits[FI_RGBA_RED];

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

		color_type = GetExtendedColorType(src, &bIsGreyscale);
	} else {
		color_type = FIC_RGB;
	}

	// determine the required bit depth of the destination image
	unsigned dst_bpp;
	unsigned dst_bpp_s1 = 0;
	if (color_type == FIC_PALETTE && !bIsGreyscale) {
		// non greyscale FIC_PALETTE images require a high-color destination
		// image (24- or 32-bits depending on the image's transparent state)
		dst_bpp = FreeImage_IsTransparent(src) ? 32 : 24;
	} else if (src_bpp <= 8) {
		// greyscale images require an 8-bit destination image
		// (or a 32-bit image if the image is transparent);
		// however, if flag FI_RESCALE_TRUE_COLOR is set, we will return
		// a true color (24 bpp) image
		if (FreeImage_IsTransparent(src)) {
			dst_bpp = 32;
			// additionally, for transparent images we always need a
			// palette including transparency information (an RGBA palette)
			// so, set color_type accordingly
			color_type = FIC_PALETTE;
		} else {
			dst_bpp = ((flags & FI_RESCALE_TRUE_COLOR) == FI_RESCALE_TRUE_COLOR) ? 24 : 8;
			// in any case, we use a fast 8-bit temporary image for the
			// first filter operation (stage 1, either horizontal or
			// vertical) and implicitly convert to 24 bpp (if requested
			// by flag FI_RESCALE_TRUE_COLOR) during the second filter
			// operation

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

		}

		return (out != src) ? out : FreeImage_Clone(src);
	}

	RGBQUAD pal_buffer[256];
	RGBQUAD *src_pal = NULL;

	// provide the source image's palette to the rescaler for
	// FIC_PALETTE type images (this includes palletized greyscale
	// images with an unordered palette as well as transparent images)
	if (color_type == FIC_PALETTE) {
		if (dst_bpp == 32) {
			// a 32-bit destination image signals transparency, so
			// create an RGBA palette from the source palette
			src_pal = GetRGBAPalette(src, pal_buffer);
		} else {
			src_pal = FreeImage_GetPalette(src);
		}
	}

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

	// step through rows
	switch(FreeImage_GetImageType(src)) {
		case FIT_BITMAP:
		{
			switch(FreeImage_GetBPP(src)) {
				case 1:
				{
					switch(FreeImage_GetBPP(dst)) {
						case 8:
						{
							// transparently convert the 1-bit non-transparent greyscale image to 8 bpp
							src_offset_x >>= 3;
							if (src_pal) {
								// we have got a palette
								for (unsigned y = 0; y < height; y++) {
									// scale each row
									const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x;
									BYTE * const dst_bits = FreeImage_GetScanLine(dst, y);

									for (unsigned x = 0; x < dst_width; x++) {
										// loop through row

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

										// clamp and place result in destination pixel
										dst_bits[x] = (BYTE)CLAMP<int>((int)(value + 0.5), 0, 0xFF);
									}
								}
							}
						}
						break;

						case 24:
						{
							// transparently convert the non-transparent 1-bit image to 24 bpp
							src_offset_x >>= 3;
							if (src_pal) {
								// we have got a palette
								for (unsigned y = 0; y < height; y++) {
									// scale each row
									const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x;
									BYTE *dst_bits = FreeImage_GetScanLine(dst, y);

									for (unsigned x = 0; x < dst_width; x++) {
										// loop through row

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

										dst_bits[FI_RGBA_BLUE]	= bval;
										dst_bits += 3;
									}
								}
							}
						}
						break;

						case 32:
						{
							// transparently convert the transparent 1-bit image to 32 bpp; 
							// we always have got a palette here
							src_offset_x >>= 3;

							for (unsigned y = 0; y < height; y++) {
								// scale each row
								const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x;
								BYTE *dst_bits = FreeImage_GetScanLine(dst, y);

								for (unsigned x = 0; x < dst_width; x++) {
									// loop through row

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

						break;
					}
				}
				break;

				case 4:
				{
					switch(FreeImage_GetBPP(dst)) {
						case 8:
						{
							// transparently convert the non-transparent 4-bit greyscale image to 8 bpp; 
							// we always have got a palette for 4-bit images
							src_offset_x >>= 1;

							for (unsigned y = 0; y < height; y++) {
								// scale each row
								const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x;
								BYTE * const dst_bits = FreeImage_GetScanLine(dst, y);

								for (unsigned x = 0; x < dst_width; x++) {
									// loop through row

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN


									// clamp and place result in destination pixel
									dst_bits[x] = (BYTE)CLAMP<int>((int)(value + 0.5), 0, 0xFF);
								}
							}
						}
						break;

						case 24:
						{
							// transparently convert the non-transparent 4-bit image to 24 bpp; 
							// we always have got a palette for 4-bit images
							src_offset_x >>= 1;

							for (unsigned y = 0; y < height; y++) {
								// scale each row
								const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x;
								BYTE *dst_bits = FreeImage_GetScanLine(dst, y);

								for (unsigned x = 0; x < dst_width; x++) {
									// loop through row

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

									dst_bits[FI_RGBA_GREEN]	= (BYTE)CLAMP<int>((int)(g + 0.5), 0, 0xFF);
									dst_bits[FI_RGBA_BLUE]	= (BYTE)CLAMP<int>((int)(b + 0.5), 0, 0xFF);
									dst_bits += 3;
								}
							}
						}
						break;

						case 32:
						{
							// transparently convert the transparent 4-bit image to 32 bpp; 
							// we always have got a palette for 4-bit images
							src_offset_x >>= 1;

							for (unsigned y = 0; y < height; y++) {
								// scale each row
								const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x;
								BYTE *dst_bits = FreeImage_GetScanLine(dst, y);

								for (unsigned x = 0; x < dst_width; x++) {
									// loop through row

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

						break;
					}
				}
				break;

				case 8:
				{
					switch(FreeImage_GetBPP(dst)) {
						case 8:
						{
							// scale the 8-bit non-transparent greyscale image
							// into an 8 bpp destination image
							if (src_pal) {
								// we have got a palette
								for (unsigned y = 0; y < height; y++) {
									// scale each row
									const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x;
									BYTE * const dst_bits = FreeImage_GetScanLine(dst, y);

									for (unsigned x = 0; x < dst_width; x++) {
										// loop through row

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

										// clamp and place result in destination pixel
										dst_bits[x] = (BYTE)CLAMP<int>((int)(value + 0.5), 0, 0xFF);
									}
								}
							}
						}
						break;

						case 24:
						{
							// transparently convert the non-transparent 8-bit image to 24 bpp
							if (src_pal) {
								// we have got a palette
								for (unsigned y = 0; y < height; y++) {
									// scale each row
									const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x;
									BYTE *dst_bits = FreeImage_GetScanLine(dst, y);

									for (unsigned x = 0; x < dst_width; x++) {
										// loop through row
										const unsigned iLeft = weightsTable.getLeftBoundary(x);				// retrieve left boundary

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

										dst_bits[FI_RGBA_BLUE]	= bval;
										dst_bits += 3;
									}
								}
							}
						}
						break;

						case 32:
						{
							// transparently convert the transparent 8-bit image to 32 bpp; 
							// we always have got a palette here
							for (unsigned y = 0; y < height; y++) {
								// scale each row
								const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x;
								BYTE *dst_bits = FreeImage_GetScanLine(dst, y);

								for (unsigned x = 0; x < dst_width; x++) {
									// loop through row
									const unsigned iLeft = weightsTable.getLeftBoundary(x);				// retrieve left boundary
									const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft;	// retrieve right boundary

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

								}
							}
						}
						break;
					}
				}
				break;

				case 16:
				{
					// transparently convert the 16-bit non-transparent image to 24 bpp
					if (IS_FORMAT_RGB565(src)) {
						// image has 565 format
						for (unsigned y = 0; y < height; y++) {
							// scale each row
							const WORD * const src_bits = (WORD *)FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x / sizeof(WORD);
							BYTE *dst_bits = FreeImage_GetScanLine(dst, y);

							for (unsigned x = 0; x < dst_width; x++) {
								// loop through row
								const unsigned iLeft = weightsTable.getLeftBoundary(x);				// retrieve left boundary

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

								dst_bits[FI_RGBA_BLUE]	= (BYTE)CLAMP<int>((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF);
								dst_bits += 3;
							}
						}
					}
				}
				break;

				case 24:
				{
					// scale the 24-bit non-transparent image into a 24 bpp destination image
					for (unsigned y = 0; y < height; y++) {
						// scale each row
						const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x * 3;
						BYTE *dst_bits = FreeImage_GetScanLine(dst, y);

						for (unsigned x = 0; x < dst_width; x++) {
							// loop through row
							const unsigned iLeft = weightsTable.getLeftBoundary(x);				// retrieve left boundary
							const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft;	// retrieve right boundary
							const BYTE * pixel = src_bits + iLeft * 3;

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

							dst_bits[FI_RGBA_GREEN]	= (BYTE)CLAMP<int>((int)(g + 0.5), 0, 0xFF);
							dst_bits[FI_RGBA_BLUE]	= (BYTE)CLAMP<int>((int)(b + 0.5), 0, 0xFF);
							dst_bits += 3;
						}
					}
				}
				break;

				case 32:
				{
					// scale the 32-bit transparent image into a 32 bpp destination image
					for (unsigned y = 0; y < height; y++) {
						// scale each row
						const BYTE * const src_bits = FreeImage_GetScanLine(src, y + src_offset_y) + src_offset_x * 4;
						BYTE *dst_bits = FreeImage_GetScanLine(dst, y);

						for (unsigned x = 0; x < dst_width; x++) {
							// loop through row
							const unsigned iLeft = weightsTable.getLeftBoundary(x);				// retrieve left boundary
							const unsigned iLimit = weightsTable.getRightBoundary(x) - iLeft;	// retrieve right boundary
							const BYTE *pixel = src_bits + iLeft * 4;

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN


			switch(FreeImage_GetBPP(src)) {
				case 1:
				{
					const unsigned src_pitch = FreeImage_GetPitch(src);
					const BYTE * const src_base = FreeImage_GetBits(src) + src_offset_y * src_pitch + (src_offset_x >> 3);

					switch(FreeImage_GetBPP(dst)) {
						case 8:
						{
							// transparently convert the 1-bit non-transparent greyscale image to 8 bpp
							if (src_pal) {
								// we have got a palette
								for (unsigned x = 0; x < width; x++) {
									// work on column x in dst
									BYTE *dst_bits = dst_base + x;
									const unsigned index = x >> 3;
									const unsigned mask = 0x80 >> (x & 0x07);

									// scale each column
									for (unsigned y = 0; y < dst_height; y++) {

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

										*dst_bits = (BYTE)CLAMP<int>((int)(value + 0.5), 0, 0xFF);
										dst_bits += dst_pitch;
									}
								}
							}
						}
						break;

						case 24:
						{
							// transparently convert the non-transparent 1-bit image to 24 bpp
							if (src_pal) {
								// we have got a palette
								for (unsigned x = 0; x < width; x++) {
									// work on column x in dst
									BYTE *dst_bits = dst_base + x * 3;
									const unsigned index = x >> 3;
									const unsigned mask = 0x80 >> (x & 0x07);

									// scale each column
									for (unsigned y = 0; y < dst_height; y++) {

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

										dst_bits[FI_RGBA_BLUE]	= bval;
										dst_bits += dst_pitch;
									}
								}
							}
						}
						break;

						case 32:
						{
							// transparently convert the transparent 1-bit image to 32 bpp; 
							// we always have got a palette here
							for (unsigned x = 0; x < width; x++) {
								// work on column x in dst
								BYTE *dst_bits = dst_base + x * 4;
								const unsigned index = x >> 3;
								const unsigned mask = 0x80 >> (x & 0x07);

								// scale each column
								for (unsigned y = 0; y < dst_height; y++) {
									// loop through column

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

				break;

				case 4:
				{
					const unsigned src_pitch = FreeImage_GetPitch(src);
					const BYTE *const src_base = FreeImage_GetBits(src) + src_offset_y * src_pitch + (src_offset_x >> 1);

					switch(FreeImage_GetBPP(dst)) {
						case 8:
						{
							// transparently convert the non-transparent 4-bit greyscale image to 8 bpp; 
							// we always have got a palette for 4-bit images
							for (unsigned x = 0; x < width; x++) {
								// work on column x in dst
								BYTE *dst_bits = dst_base + x;
								const unsigned index = x >> 1;

								// scale each column
								for (unsigned y = 0; y < dst_height; y++) {
									// loop through column
									const unsigned iLeft = weightsTable.getLeftBoundary(y);				// retrieve left boundary

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

									// clamp and place result in destination pixel
									*dst_bits = (BYTE)CLAMP<int>((int)(value + 0.5), 0, 0xFF);
									dst_bits += dst_pitch;
								}
							}
						}
						break;

						case 24:
						{
							// transparently convert the non-transparent 4-bit image to 24 bpp; 
							// we always have got a palette for 4-bit images
							for (unsigned x = 0; x < width; x++) {
								// work on column x in dst
								BYTE *dst_bits = dst_base + x * 3;
								const unsigned index = x >> 1;

								// scale each column
								for (unsigned y = 0; y < dst_height; y++) {
									// loop through column
									const unsigned iLeft = weightsTable.getLeftBoundary(y);				// retrieve left boundary

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

									dst_bits[FI_RGBA_GREEN]	= (BYTE)CLAMP<int>((int)(g + 0.5), 0, 0xFF);
									dst_bits[FI_RGBA_BLUE]	= (BYTE)CLAMP<int>((int)(b + 0.5), 0, 0xFF);
									dst_bits += dst_pitch;
								}
							}
						}
						break;

						case 32:
						{
							// transparently convert the transparent 4-bit image to 32 bpp; 
							// we always have got a palette for 4-bit images
							for (unsigned x = 0; x < width; x++) {
								// work on column x in dst
								BYTE *dst_bits = dst_base + x * 4;
								const unsigned index = x >> 1;

								// scale each column
								for (unsigned y = 0; y < dst_height; y++) {
									// loop through column
									const unsigned iLeft = weightsTable.getLeftBoundary(y);				// retrieve left boundary

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

				break;

				case 8:
				{
					const unsigned src_pitch = FreeImage_GetPitch(src);
					const BYTE *const src_base = FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x;

					switch(FreeImage_GetBPP(dst)) {
						case 8:
						{
							// scale the 8-bit non-transparent greyscale image into an 8 bpp destination image
							if (src_pal) {
								// we have got a palette
								for (unsigned x = 0; x < width; x++) {
									// work on column x in dst
									BYTE *dst_bits = dst_base + x;

									// scale each column
									for (unsigned y = 0; y < dst_height; y++) {
										// loop through column
										const unsigned iLeft = weightsTable.getLeftBoundary(y);				// retrieve left boundary

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

										*dst_bits = (BYTE)CLAMP<int>((int)(value + 0.5), 0, 0xFF);
										dst_bits += dst_pitch;
									}
								}
							}
						}
						break;

						case 24:
						{
							// transparently convert the non-transparent 8-bit image to 24 bpp
							if (src_pal) {
								// we have got a palette
								for (unsigned x = 0; x < width; x++) {
									// work on column x in dst
									BYTE *dst_bits = dst_base + x * 3;

									// scale each column
									for (unsigned y = 0; y < dst_height; y++) {
										// loop through column
										const unsigned iLeft = weightsTable.getLeftBoundary(y);				// retrieve left boundary

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

										dst_bits[FI_RGBA_BLUE]	= bval;
										dst_bits += dst_pitch;
									}
								}
							}
						}
						break;

						case 32:
						{
							// transparently convert the transparent 8-bit image to 32 bpp; 
							// we always have got a palette here
							for (unsigned x = 0; x < width; x++) {
								// work on column x in dst
								BYTE *dst_bits = dst_base + x * 4;

								// scale each column
								for (unsigned y = 0; y < dst_height; y++) {
									// loop through column
									const unsigned iLeft = weightsTable.getLeftBoundary(y);				// retrieve left boundary
									const unsigned iLimit = weightsTable.getRightBoundary(y) - iLeft;	// retrieve right boundary

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

								}
							}
						}
						break;
					}
				}
				break;

				case 16:
				{
					// transparently convert the 16-bit non-transparent image to 24 bpp
					const unsigned src_pitch = FreeImage_GetPitch(src) / sizeof(WORD);
					const WORD *const src_base = (WORD *)FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x;

					if (IS_FORMAT_RGB565(src)) {
						// image has 565 format
						for (unsigned x = 0; x < width; x++) {
							// work on column x in dst
							BYTE *dst_bits = dst_base + x * 3;

							// scale each column

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

								dst_bits[FI_RGBA_BLUE]	= (BYTE)CLAMP<int>((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF);
								dst_bits += dst_pitch;
							}
						}
					}
				}
				break;

				case 24:
				{
					// scale the 24-bit transparent image into a 24 bpp destination image
					const unsigned src_pitch = FreeImage_GetPitch(src);
					const BYTE *const src_base = FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x * 3;

					for (unsigned x = 0; x < width; x++) {
						// work on column x in dst
						const unsigned index = x * 3;
						BYTE *dst_bits = dst_base + index;

						// scale each column
						for (unsigned y = 0; y < dst_height; y++) {

src/Source/FreeImageToolkit/Resize.cpp  view on Meta::CPAN

							dst_bits[FI_RGBA_GREEN]	= (BYTE)CLAMP<int>((int) (g + 0.5), 0, 0xFF);
							dst_bits[FI_RGBA_BLUE]	= (BYTE)CLAMP<int>((int) (b + 0.5), 0, 0xFF);
							dst_bits += dst_pitch;
						}
					}
				}
				break;

				case 32:
				{
					// scale the 32-bit transparent image into a 32 bpp destination image
					const unsigned src_pitch = FreeImage_GetPitch(src);
					const BYTE *const src_base = FreeImage_GetBits(src) + src_offset_y * src_pitch + src_offset_x * 4;

					for (unsigned x = 0; x < width; x++) {
						// work on column x in dst
						const unsigned index = x * 4;
						BYTE *dst_bits = dst_base + index;

						// scale each column
						for (unsigned y = 0; y < dst_height; y++) {

src/Source/LibJPEG/README  view on Meta::CPAN

the assets of these former principals, agents, and beneficiaries of the
foreclosed institutions and corporations.
IJG asserts what is: that each man, woman, and child has unalienable value
and rights granted and deposited in them by the Creator and not any one of
the people is subordinate to any artificial principality, corporate fiction
or the special interest of another without their appropriate knowing,
willing and intentional consent made by contract or accommodation agreement.
IJG expresses that which already was.
The people have already determined and demanded that public administration
entities, national governments, and their supporting judicial systems must
be fully transparent, accountable, and liable.
IJG has secured the value for all concerned free people of the planet.

A partial list of foreclosed institutions and corporations ("Hall of Shame")
is currently prepared and will be published later.


TO DO
=====

Version 9 is the second release of a new generation JPEG standard

src/Source/LibJPEG/ansi2knr.c  view on Meta::CPAN

/*
 * Usage:
	ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]
 * --filename provides the file name for the #line directive in the output,
 * overriding input_file (if present).
 * If no input_file is supplied, input is read from stdin.
 * If no output_file is supplied, output goes to stdout.
 * There are no error messages.
 *
 * ansi2knr recognizes function definitions by seeing a non-keyword
 * identifier at the left margin, followed by a left parenthesis, with a
 * right parenthesis as the last character on the line, and with a left
 * brace as the first token on the following line (ignoring possible
 * intervening comments and/or preprocessor directives), except that a line
 * consisting of only
 *	identifier1(identifier2)
 * will not be considered a function definition unless identifier2 is
 * the word "void", and a line consisting of
 *	identifier1(identifier2, <<arbitrary>>)
 * will not be considered a function definition.
 * ansi2knr will recognize a multi-line header provided that no intervening
 * line ends with a left or right brace or a semicolon.  These algorithms

src/Source/LibJPEG/ansi2knr.c  view on Meta::CPAN

	   }
	while ( isidchar(*p) )
	  p++;
	endfn = p;
	p = skipspace(p, 1);
	if ( *p++ != '(' )
	  return 0;		/* not a function */
	p = skipspace(p, 1);
	if ( *p == ')' )
	  return 0;		/* no parameters */
	/* Check that the apparent function name isn't a keyword. */
	/* We only need to check for keywords that could be followed */
	/* by a left parenthesis (which, unfortunately, is most of them). */
	   {	static char *words[] =
		   {	"asm", "auto", "case", "char", "const", "double",
			"extern", "float", "for", "if", "int", "long",
			"register", "return", "short", "signed", "sizeof",
			"static", "switch", "typedef", "unsigned",
			"void", "volatile", "while", 0
		   };
		char **key = words;
		char *kp;
		unsigned len = endfn - buf;

src/Source/LibJPEG/ansi2knr.c  view on Meta::CPAN

		   p++;
	       len = p - id;
	       p = skipspace(p, 1);
	       if (*p == ',' ||
		   (*p == ')' && (len != 4 || strncmp(id, "void", 4)))
		   )
		   return 0;	/* not a function */
	   }
	/*
	 * If the last significant character was a ), we need to count
	 * parentheses, because it might be part of a formal parameter
	 * that is a procedure.
	 */
	if (contin > 0) {
	    int level = 0;

	    for (p = skipspace(buf, 1); *p; p = skipspace(p + 1, 1))
		level += (*p == '(' ? 1 : *p == ')' ? -1 : 0);
	    if (level > 0)
		contin = -1;
	}

src/Source/LibJPEG/ansi2knr.c  view on Meta::CPAN

	if ( bp == breaks+2 )
	   {	p = skipspace(breaks[0], 1);
		if ( !strncmp(p, "void", 4) )
		   {	p = skipspace(p+4, 1);
			if ( p == breaks[2] - 1 )
			   {	bp = breaks;	/* yup, pretend arglist is empty */
				writeblanks(breaks[0], p + 1);
			   }
		   }
	   }
	/* Put out the function name and left parenthesis. */
	p = buf;
	while ( p != endfn ) putc(*p, out), p++;
	/* Put out the declaration. */
	if ( header )
	  {	fputs(");", out);
		for ( p = breaks[0]; *p; p++ )
		  if ( *p == '\r' || *p == '\n' )
		    putc(*p, out);
	  }
	else

src/Source/LibJPEG/coderules.txt  view on Meta::CPAN

	#ifdef HAVE_PROTOTYPES
	#define JMETHOD(type,methodname,arglist)  type (*methodname) arglist
	#else
	#define JMETHOD(type,methodname,arglist)  type (*methodname) ()
	#endif
which is used like this:
	struct function_pointers {
	  JMETHOD(void, init_entropy_encoder, (int somearg, jparms *jp));
	  JMETHOD(void, term_entropy_encoder, (void));
	};
Note the set of parentheses surrounding the parameter list.

A similar solution is used for forward and external function declarations
(see the EXTERN and JPP macros).

If the code is to work on non-ANSI compilers, we cannot rely on a prototype
declaration to coerce actual parameters into the right types.  Therefore, use
explicit casts on actual parameters whenever the actual parameter type is not
identical to the formal parameter.  Beware of implicit conversions to "int".

It seems there are some non-ANSI compilers in which the sizeof() operator

src/Source/LibJPEG/jdinput.c  view on Meta::CPAN

      } else {			/* 2nd or later SOS marker */
	if (! inputctl->pub.has_multiple_scans)
	  ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
	if (cinfo->comps_in_scan == 0) /* unexpected pseudo SOS marker */
	  break;
	start_input_pass(cinfo);
      }
      return val;
    case JPEG_REACHED_EOI:	/* Found EOI */
      inputctl->pub.eoi_reached = TRUE;
      if (inputctl->inheaders) { /* Tables-only datastream, apparently */
	if (cinfo->marker->saw_SOF)
	  ERREXIT(cinfo, JERR_SOF_NO_SOS);
      } else {
	/* Prevent infinite loop in coef ctlr's decompress_data routine
	 * if user set output_scan_number larger than number of scans.
	 */
	if (cinfo->output_scan_number > cinfo->input_scan_number)
	  cinfo->output_scan_number = cinfo->input_scan_number;
      }
      return val;

src/Source/LibJPEG/jmorecfg.h  view on Meta::CPAN

/* a function used only in its module: */
#define LOCAL(type)		static type
/* a function referenced thru EXTERNs: */
#define GLOBAL(type)		type
/* a reference to a GLOBAL function: */
#define EXTERN(type)		extern type


/* This macro is used to declare a "method", that is, a function pointer.
 * We want to supply prototype parameters if the compiler can cope.
 * Note that the arglist parameter must be parenthesized!
 * Again, you can customize this if you need special linkage keywords.
 */

#ifdef HAVE_PROTOTYPES
#define JMETHOD(type,methodname,arglist)  type (*methodname) arglist
#else
#define JMETHOD(type,methodname,arglist)  type (*methodname) ()
#endif


src/Source/LibJPEG/jpeglib.h  view on Meta::CPAN



/* Routine signature for application-supplied marker processing methods.
 * Need not pass marker code since it is stored in cinfo->unread_marker.
 */
typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));


/* Declarations for routines called by application.
 * The JPP macro hides prototype parameters from compilers that can't cope.
 * Note JPP requires double parentheses.
 */

#ifdef HAVE_PROTOTYPES
#define JPP(arglist)	arglist
#else
#define JPP(arglist)	()
#endif


/* Short forms of external names for systems with brain-damaged linkers.

src/Source/LibJPEG/libjpeg.txt  view on Meta::CPAN

slow communications link, a decoder can generate a low-quality image very
quickly from the first scan, then gradually improve the displayed quality as
more scans are received.  The final image after all scans are complete is
identical to that of a regular (sequential) JPEG file of the same quality
setting.  Progressive JPEG files are often slightly smaller than equivalent
sequential JPEG files, but the possibility of incremental display is the main
reason for using progressive JPEG.

The IJG encoder library generates progressive JPEG files when given a
suitable "scan script" defining how to divide the data into scans.
Creation of progressive JPEG files is otherwise transparent to the encoder.
Progressive JPEG files can also be read transparently by the decoder library.
If the decoding application simply uses the library as defined above, it
will receive a final decoded image without any indication that the file was
progressive.  Of course, this approach does not allow incremental display.
To perform incremental display, an application needs to use the decoder
library's "buffered-image" mode, in which it receives a decoded image
multiple times.

Each displayed scan requires about as much work to decode as a full JPEG
image of the same size, so the decoder must be fairly fast in relation to the
data transmission rate in order to make incremental display useful.  However,

src/Source/LibJPEG/libjpeg.txt  view on Meta::CPAN

manager, since jpeg_finish_compress() does not support suspension.  We
should also note that the compressor currently forces Huffman optimization
mode when creating a progressive JPEG file, because the default Huffman
tables are unsuitable for progressive files.

Progressive decompression:

When buffered-image mode is not used, the decoder library will read all of
a multi-scan file during jpeg_start_decompress(), so that it can provide a
final decoded image.  (Here "multi-scan" means either progressive or
multi-scan sequential.)  This makes multi-scan files transparent to the
decoding application.  However, existing applications that used suspending
input with version 5 of the IJG library will need to be modified to check
for a suspension return from jpeg_start_decompress().

To perform incremental display, an application must use the library's
buffered-image mode.  This is described in the next section.


Buffered-image mode
-------------------

src/Source/LibJXR/common/include/wmspecstrings_strict.h  view on Meta::CPAN

*                        data members are pointers to a block of data.
*                        The annotations describe properties about the
*                        size of the block of data. This can be used for
*
*                __struct
*                        The annotation should only be placed at the
*                        beginning of the definition of a structure or
*                        class. These annotations are used when a struct
*                        or class is used as a "header" that is
*                        allocated inline with a block of data and there
*                        is no apparent field that represents the tail
*                        end of the structure.
*
*   Units
*
*                _ecount
*                        All size and initialization values are in terms
*                        of elements of the appropriate type
*
*                _bcount
*                        All size and initialization values are in terms

src/Source/LibOpenJPEG/tgt.c  view on Meta::CPAN

/* 
==========================================================
   Tag-tree coder interface
==========================================================
*/

opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
        OPJ_INT32 nplh[32];
        OPJ_INT32 nplv[32];
        opj_tgt_node_t *node = 00;
        opj_tgt_node_t *l_parent_node = 00;
        opj_tgt_node_t *l_parent_node0 = 00;
        opj_tgt_tree_t *tree = 00;
        OPJ_UINT32 i;
        OPJ_INT32  j,k;
        OPJ_UINT32 numlvls;
        OPJ_UINT32 n;

        tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t));
        if(!tree) {
                fprintf(stderr, "ERROR in tgt_create while allocating tree\n");
                return 00;

src/Source/LibOpenJPEG/tgt.c  view on Meta::CPAN

        tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t));
        if(!tree->nodes) {
                fprintf(stderr, "ERROR in tgt_create while allocating node of the tree\n");
                opj_free(tree);
                return 00;
        }
        memset(tree->nodes,0,tree->numnodes * sizeof(opj_tgt_node_t));
        tree->nodes_size = tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t);

        node = tree->nodes;
        l_parent_node = &tree->nodes[tree->numleafsh * tree->numleafsv];
        l_parent_node0 = l_parent_node;

        for (i = 0; i < numlvls - 1; ++i) {
                for (j = 0; j < nplv[i]; ++j) {
                        k = nplh[i];
                        while (--k >= 0) {
                                node->parent = l_parent_node;
                                ++node;
                                if (--k >= 0) {
                                        node->parent = l_parent_node;
                                        ++node;
                                }
                                ++l_parent_node;
                        }
                        if ((j & 1) || j == nplv[i] - 1) {
                                l_parent_node0 = l_parent_node;
                        } else {
                                l_parent_node = l_parent_node0;
                                l_parent_node0 += nplh[i];
                        }
                }
        }
        node->parent = 0;
        opj_tgt_reset(tree);
        return tree;
}

/**
 * Reinitialises a tag-tree from an existing one.
 *
 * @param       p_tree                          the tree to reinitialize.
 * @param       p_num_leafs_h           the width of the array of leafs of the tree
 * @param       p_num_leafs_v           the height of the array of leafs of the tree
 * @return      a new tag-tree if successful, NULL otherwise
*/
opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, OPJ_UINT32 p_num_leafs_v)
{
        OPJ_INT32 l_nplh[32];
        OPJ_INT32 l_nplv[32];
        opj_tgt_node_t *l_node = 00;
        opj_tgt_node_t *l_parent_node = 00;
        opj_tgt_node_t *l_parent_node0 = 00;
        OPJ_UINT32 i;
        OPJ_INT32 j,k;
        OPJ_UINT32 l_num_levels;
        OPJ_UINT32 n;
        OPJ_UINT32 l_node_size;

        if (! p_tree){
                return 00;
        }

src/Source/LibOpenJPEG/tgt.c  view on Meta::CPAN

                        if (! new_nodes) {
                                fprintf(stderr, "ERROR Not enough memory to reinitialize the tag tree\n");
                                opj_tgt_destroy(p_tree);
                                return 00;
                        }
                        p_tree->nodes = new_nodes;
                        memset(((char *) p_tree->nodes) + p_tree->nodes_size, 0 , l_node_size - p_tree->nodes_size);
                        p_tree->nodes_size = l_node_size;
                }
                l_node = p_tree->nodes;
                l_parent_node = &p_tree->nodes[p_tree->numleafsh * p_tree->numleafsv];
                l_parent_node0 = l_parent_node;

                for (i = 0; i < l_num_levels - 1; ++i) {
                        for (j = 0; j < l_nplv[i]; ++j) {
                                k = l_nplh[i];
                                while (--k >= 0) {
                                        l_node->parent = l_parent_node;
                                        ++l_node;
                                        if (--k >= 0) {
                                                l_node->parent = l_parent_node;
                                                ++l_node;
                                        }
                                        ++l_parent_node;
                                        }
                                if ((j & 1) || j == l_nplv[i] - 1)
                                {
                                        l_parent_node0 = l_parent_node;
                                }
                                else
                                {
                                        l_parent_node = l_parent_node0;
                                        l_parent_node0 += l_nplh[i];
                                }
                        }
                }
                l_node->parent = 0;
        }
        opj_tgt_reset(p_tree);

        return p_tree;
}

void opj_tgt_destroy(opj_tgt_tree_t *p_tree)
{
        if (! p_tree) {
                return;

src/Source/LibOpenJPEG/tgt.c  view on Meta::CPAN

                l_current_node->known = 0;
                ++l_current_node;
        }
}

void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value) {
        opj_tgt_node_t *node;
        node = &tree->nodes[leafno];
        while (node && node->value > value) {
                node->value = value;
                node = node->parent;
        }
}

void opj_tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold) {
        opj_tgt_node_t *stk[31];
        opj_tgt_node_t **stkptr;
        opj_tgt_node_t *node;
        OPJ_INT32 low;

        stkptr = stk;
        node = &tree->nodes[leafno];
        while (node->parent) {
                *stkptr++ = node;
                node = node->parent;
        }
        
        low = 0;
        for (;;) {
                if (low > node->low) {
                        node->low = low;
                } else {
                        low = node->low;
                }
                

src/Source/LibOpenJPEG/tgt.c  view on Meta::CPAN

}

OPJ_UINT32 opj_tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold) {
        opj_tgt_node_t *stk[31];
        opj_tgt_node_t **stkptr;
        opj_tgt_node_t *node;
        OPJ_INT32 low;

        stkptr = stk;
        node = &tree->nodes[leafno];
        while (node->parent) {
                *stkptr++ = node;
                node = node->parent;
        }
        
        low = 0;
        for (;;) {
                if (low > node->low) {
                        node->low = low;
                } else {
                        low = node->low;
                }
                while (low < threshold && low < node->value) {

src/Source/LibOpenJPEG/tgt.h  view on Meta::CPAN

are used by some function in T2.C.
*/

/** @defgroup TGT TGT - Implementation of a tag-tree coder */
/*@{*/

/**
Tag node
*/
typedef struct opj_tgt_node {
    struct opj_tgt_node *parent;
    OPJ_INT32 value;
    OPJ_INT32 low;
    OPJ_UINT32 known;
} opj_tgt_node_t;

/**
Tag tree
*/
typedef struct opj_tgt_tree
{

src/Source/LibPNG/CHANGES  view on Meta::CPAN

  Added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P)
  Minor corrections in libpng.txt
  Added simple sRGB support (Glenn R-P)
  Easier conditional compiling, e.g.,
    define PNG_READ/WRITE_NOT_FULLY_SUPPORTED;
    all configurable options can be selected from command-line instead
    of having to edit pngconf.h (Glenn R-P)
  Fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P)
  Added more conditions for png_do_background, to avoid changing
    black pixels to background when a background is supplied and
    no pixels are transparent
  Repaired PNG_NO_STDIO behavior
  Tested NODIV support and made it default behavior (Greg Roelofs)
  Added "-m" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler)
  Regularized version numbering scheme and bumped shared-library major
    version number to 2 to avoid problems with libpng 0.89 apps
    (Greg Roelofs)

Version 0.98 [January, 1998]
  Cleaned up some typos in libpng.txt and in code documentation
  Fixed memory leaks in pCAL chunk processing (Glenn R-P and John Bowler)

src/Source/LibPNG/CHANGES  view on Meta::CPAN

  Fixed some typos and made other minor rearrangement of libpng.txt (Andreas)
  Changed recommendation about file_gamma for PC images to .50 from .51 in
    example.c and libpng.txt, and changed file_gamma for sRGB images to .45
  Added a number of functions to access information from the png structure
    png_get_image_height(), etc. (Glenn R-P, suggestion by Brad Pettit)
  Added TARGET_MACOS similar to zlib-1.0.8
  Define PNG_ALWAYS_EXTERN when __MWERKS__ && WIN32 are defined
  Added type casting to all png_malloc() function calls

Version 0.99a [January 31, 1998]
  Added type casts and parentheses to all returns that return a value.(Tim W.)

Version 0.99b [February 4, 1998]
  Added type cast png_uint_32 on malloc function calls where needed.
  Changed type of num_hist from png_uint_32 to int (same as num_palette).
  Added checks for rowbytes overflow, in case png_size_t is less than 32 bits.
  Renamed makefile.elf to makefile.lnx.

Version 0.99c [February 7, 1998]
  More type casting.  Removed erroneous overflow test in pngmem.c.
  Added png_buffered_memcpy() and png_buffered_memset(), apply them to rowbytes.

src/Source/LibPNG/CHANGES  view on Meta::CPAN

  Version 99c "buffered" operations didn't work as intended.  Replaced them
    with png_memcpy_check() and png_memset_check().
  Added many "if (png_ptr == NULL) return" to quell compiler warnings about
    unused png_ptr, mostly in pngget.c and pngset.c.
  Check for overlength tRNS chunk present when indexed-color PLTE is read.
  Cleaned up spelling errors in libpng.3/libpng.txt
  Corrected a problem with png_get_tRNS() which returned undefined trans array

Version 0.99e [February 28, 1998]
  Corrected png_get_tRNS() again.
  Add parentheses for easier reading of pngget.c, fixed "||" should be "&&".
  Touched up example.c to make more of it compileable, although the entire
    file still can't be compiled (Willem van Schaik)
  Fixed a bug in png_do_shift() (Bryan Tsai)
  Added a space in png.h prototype for png_write_chunk_start()
  Replaced pngtest.png with one created with zlib 1.1.1
  Changed pngtest to report PASS even when file size is different (Jean-loup G.)
  Corrected some logic errors in png_do_invert_alpha() (Chris Patterson)

Version 0.99f [March 5, 1998]
  Corrected a bug in pngpread() introduced in version 99c (Kevin Bracey)

src/Source/LibPNG/CHANGES  view on Meta::CPAN

  Split makefile.win32vc into two versions, makefile.vcawin32 (uses MMX
    assembler code) and makefile.vcwin32 (doesn't).
  Added a CPU timing report to pngtest.c (enabled by defining PNGTEST_TIMING)
  Added a copy of pngnow.png to the distribution.

Version 1.0.4a [September 25, 1999]
  Increase max_pixel_depth in pngrutil.c if a user transform needs it.
  Changed several division operations to right-shifts in pngvcrd.c

Version 1.0.4b [September 30, 1999]
  Added parentheses in line 3732 of pngvcrd.c
  Added a comment in makefile.linux warning about buggy -O3 in pgcc 2.95.1

Version 1.0.4c [October 1, 1999]
  Added a "png_check_version" function in png.c and pngtest.c that will generate
    a helpful compiler error if an old png.h is found in the search path.
  Changed type of png_user_transform_depth|channels from int to png_byte.

Version 1.0.4d [October 6, 1999]
  Changed 0.45 to 0.45455 in png_set_sRGB()
  Removed unused PLTE entries from pngnow.png

src/Source/LibPNG/CHANGES  view on Meta::CPAN

    member to distinguish among tEXt/zTXt/iTXt types.  Added
    PNG_ITXT_COMPRESSION_NONE (1) and PNG_ITXT_COMPRESSION_zTXt(2) macros.
    The "Note" above, about backward incompatibility of libpng-1.0.5e, no
    longer applies.
  Fixed png_read|write_iTXt() to read|write parameters in the right order,
    and to write the iTXt chunk after IDAT if it appears in the end_ptr.
  Added pnggccrd.c, version of pngvcrd.c Intel assembler for gcc (Greg Roelofs)
  Reversed the order of trying to write floating-point and fixed-point gAMA.

Version 1.0.5k [December 27, 1999]
  Added many parentheses, e.g., "if (a && b & c)" becomes "if (a && (b & c))"
  Added png_handle_as_unknown() function (Glenn)
  Added png_free_chunk_list() function and chunk_list and num_chunk_list members
    of png_ptr.
  Eliminated erroneous warnings about multiple sPLT chunks and sPLT-after-PLTE.
  Fixed a libpng-1.0.5h bug in pngrutil.c that was issuing erroneous warnings
    about ignoring incorrect gAMA with sRGB (gAMA was in fact not ignored)
  Added png_free_tRNS(); png_set_tRNS() now malloc's its own trans array (ESR).
  Define png_get_int_32 when oFFs chunk is supported as well as when pCAL is.
  Changed type of proflen from png_int_32 to png_uint_32 in png_get_iCCP().

src/Source/LibPNG/CHANGES  view on Meta::CPAN

  Removed spaces in makefile.linux and makefile.gcmmx, introduced in 1.0.5s

Version 1.0.5u [March 5, 2000]
  Simplified the code that detects old png.h in png.c and pngtest.c
  Renamed png_spalette (_p, _pp) to png_sPLT_t (_tp, _tpp)
  Increased precision of rgb_to_gray calculations from 8 to 15 bits and
    added png_set_rgb_to_gray_fixed() function.
  Added makefile.bc32 (32-bit Borland C++, C mode)

Version 1.0.5v [March 11, 2000]
  Added some parentheses to the png_jmpbuf macro definition.
  Updated references to the zlib home page, which has moved to freesoftware.com.
  Corrected bugs in documentation regarding png_read_row() and png_write_row().
  Updated documentation of png_rgb_to_gray calculations in libpng.3/libpng.txt.
  Renamed makefile.borland,turboc3 back to makefile.bor,tc3 as in version 1.0.3,
    revised borland makefiles; added makefile.ibmvac3 and makefile.gcc (Cosmin)

Version 1.0.6 [March 20, 2000]
  Minor revisions of makefile.bor, libpng.txt, and gregbook/rpng2-win.c
  Added makefile.sggcc (SGI IRIX with gcc)

src/Source/LibPNG/CHANGES  view on Meta::CPAN

    the limit for PNG unsigned 32-bit integers when encoded.
  Revised calls to png_create_read_struct() and png_create_write_struct()
    for simpler debugging.
  Revised png_zalloc() so zlib handles errors (uses PNG_FLAG_MALLOC_NULL_MEM_OK)

Version 1.2.2beta2 [February 23, 2002]
  Check chunk_length and idat_size for invalid (over PNG_MAX_UINT) lengths.
  Check for invalid image dimensions in png_get_IHDR.
  Added missing "fi;" in the install target of the SGI makefiles.
  Added install-static to all makefiles that make shared libraries.
  Always do gamma compensation when image is partially transparent.

Version 1.2.2beta3 [March 7, 2002]
  Compute background.gray and background_1.gray even when color_type is RGB
    in case image gets reduced to gray later.
  Modified shared-library makefiles to install pkgconfig/libpngNN.pc.
  Export (with PNGAPI) png_zalloc, png_zfree, and png_handle_as_unknown
  Removed unused png_write_destroy_info prototype from png.h
  Eliminated incorrect use of width_mmx from pnggccrd.c in pixel_bytes == 8 case
  Added install-shared target to all makefiles that make shared libraries.
  Stopped a double free of palette, hist, and trans when not using free_me.

src/Source/LibPNG/CHANGES  view on Meta::CPAN

  Fixed potential overrun in pngerror.c by using strncpy instead of memcpy.
  Added "#!/bin/sh" at the top of configure, for recognition of the
    'x' flag under Cygwin (Cosmin).
  Optimized vacuous tests that silence compiler warnings, in png.c (Cosmin).
  Added support for PNG_USER_CONFIG, in pngconf.h (Cosmin).
  Fixed the special memory handler for Borland C under DOS, in pngmem.c
    (Cosmin).
  Removed some spurious assignments in pngrutil.c (Cosmin).
  Replaced 65536 with 65536L, and 0xffff with 0xffffL, to silence warnings
    on 16-bit platforms (Cosmin).
  Enclosed shift op expressions in parentheses, to silence warnings (Cosmin).
  Used proper type png_fixed_point, to avoid problems on 16-bit platforms,
    in png_handle_sRGB() (Cosmin).
  Added compression_type to png_struct, and optimized the window size
    inside the deflate stream (Cosmin).
  Fixed definition of isnonalpha(), in pngerror.c and pngrutil.c (Cosmin).
  Fixed handling of unknown chunks that come after IDAT (Cosmin).
  Allowed png_error() and png_warning() to work even if png_ptr == NULL
    (Cosmin).
  Replaced row_info->rowbytes with row_bytes in png_write_find_filter()
    (Cosmin).

src/Source/LibPNG/CHANGES  view on Meta::CPAN

    png_read_end or png_write_end after png_read_png or png_write_png.
  Updated references to png-mng-implement mailing list.
  Fixed an incorrect typecast in pngrutil.c
  Added PNG_NO_READ_SUPPORTED conditional for making a write-only library.
  Added PNG_NO_WRITE_INTERLACING_SUPPORTED conditional.
  Optimized alpha-inversion loops in pngwtran.c
  Moved test for nonzero gamma outside of png_build_gamma_table() in pngrtran.c
  Make sure num_trans is <= 256 before copying data in png_set_tRNS().
  Make sure num_palette is <= 256 before copying data in png_set_PLTE().
  Interchanged order of write_swap_alpha and write_invert_alpha transforms.
  Added parentheses in the definition of PNG_LIBPNG_BUILD_TYPE (Cosmin).
  Optimized zlib window flag (CINFO) in contrib/pngsuite/*.png (Cosmin).
  Updated scripts/makefile.bc32 for Borland C++ 5.6 (Cosmin).
  Exported png_get_uint_32, png_save_uint_32, png_get_uint_16, png_save_uint_16,
    png_get_int_32, png_save_int_32, png_get_uint_31 (Cosmin).
  Added type cast (png_byte) in png_write_sCAL() (Cosmin).
  Fixed scripts/makefile.cygwin (Christian Biesinger, Cosmin).
  Default iTXt support was inadvertently enabled.

Version 1.2.9beta2 [February 21, 2006]
  Check for png_rgb_to_gray and png_gray_to_rgb read transformations before

src/Source/LibPNG/CHANGES  view on Meta::CPAN

    file (fixes build on Cygwin).
  Enabled 'attribute' warnings that are relevant to library APIs and callbacks.
  Changed rules for generation of the various symbol files and added a new
    rule for a DEF file (which is also added to the distribution).
  Updated the symbol file generation to stop it adding spurious spaces
    to EOL (coming from preprocessor macro expansion).  Added a facility
    to join tokens in the output and rewrite *.dfn to use this.
  Eliminated scripts/*.def in favor of libpng.def; updated projects/visualc71
    and removed scripts/makefile.cygwin.
  Made PNG_BUILD_DLL safe: it can be set whenever a DLL is being built.
  Removed the include of sys/types.h - apparently unnecessary now on the
    platforms on which it happened (all but Mac OS and RISC OS).
  Moved the Mac OS test into pngpriv.h (the only place it is used.)

Version 1.5.0beta15 [March 17, 2010]
  Added symbols.chk target to Makefile.am to validate the symbols in png.h
    against the new DEF file scripts/symbols.def.
  Changed the default DEF file back to pngwin.def.
  Removed makefile.mingw.
  Eliminated PNG_NO_EXTERN and PNG_ALL_EXTERN

src/Source/LibPNG/CHANGES  view on Meta::CPAN

    benefit of the user transform callback.
  Added png_process_data_pause and png_process_data_skip for the benefit of
    progressive readers that need to stop data processing or want to optimize
    skipping of unread data (e.g., if the reader marks a chunk to be skipped.)

Version 1.5.1beta09 [January 24, 2011]
  Enhanced pngvalid, corrected an error in gray_to_rgb, corrected doc error.
    pngvalid contains tests of transforms, which tests are currently disabled
    because they are incompletely tested.  gray_to_rgb was failing to expand
    the bit depth for smaller bit depth images; this seems to be a long
    standing error and resulted, apparently, in invalid output
    (CVE-2011-0408, CERT VU#643140).  The documentation did not accurately
    describe what libpng really does when converting RGB to gray.

Version 1.5.1beta10 [January 27, 2010]
  Fixed incorrect examples of callback prototypes in the manual, that were
    introduced in libpng-1.0.0.
  In addition the order of the png_get_uint macros with respect to the
    relevant function definitions has been reversed.  This helps the
    preprocessing of the symbol files be more robust.  Furthermore, the
    symbol file preprocessing now uses -DPNG_NO_USE_READ_MACROS even when

src/Source/LibPNG/CHANGES  view on Meta::CPAN


Version 1.5.1rc02 [January 31, 2011]
  Added a request in the manual that applications do not use "png_" or
    "PNG_" to begin any of their own symbols.
  Changed PNG_UNUSED to "(void)param;" and updated the commentary in pngpriv.h

Version 1.5.1 [February 3, 2011]
  No changes.

Version 1.5.2beta01 [February 13, 2011]
  More -Wshadow fixes for older gcc compilers.  Older gcc versions apparently
    check formal parameters names in function declarations (as well as
    definitions) to see if they match a name in the global namespace.
  Revised PNG_EXPORTA macro to not use an empty parameter, to accommodate the
    old VisualC++ preprocessor.
  Turned on interlace handling in png_read_png().
  Fixed gcc pendantic warnings.
  Handle longjmp in Cygwin.
  Fixed png_get_current_row_number() in the interlaced case.
  Cleaned up ALPHA flags and transformations.
  Implemented expansion to 16 bits.

src/Source/LibPNG/CHANGES  view on Meta::CPAN

    the option the tests written in configure itself fail compilation because
    they cause compiler warnings.
  Rewrote autogen.sh to run autoreconf instead of running tools one-by-one.
  Conditionalize the install rules for MINGW and CYGWIN in CMakeLists.txt and
    set CMAKE_LIBRARY_OUTPUT_DIRECTORY to "lib" on all platforms (C. Yapp).
  Freeze libtool files in the 'scripts' directory. This version of autogen.sh
    attempts to dissuade people from running it when it is not, or should not,
    be necessary.  In fact, autogen.sh does not work when run in a libpng
    directory extracted from a tar distribution anymore. You must run it in
    a GIT clone instead.
  Added two images to contrib/pngsuite (1-bit and 2-bit transparent grayscale),
    and renamed three whose names were inconsistent with those in
    pngsuite/README.txt.

Version 1.6.0beta08 [February 1, 2012]
  Fixed Image::colormap misalignment in pngstest.c
  Check libtool/libtoolize version number (2.4.2) in configure.ac
  Divide test-pngstest.sh into separate pngstest runs for basic and
    transparent images.
  Moved automake options to AM_INIT_AUTOMAKE in configure.ac
  Added color-tests, silent-rules (Not yet implemented in Makefile.am) and
    version checking to configure.ac
  Improved pngstest speed by not doing redundant tests and add const to
    the background parameter of png_image_finish_read. The --background
    option is now done automagically only when required, so that commandline
    option no longer exists.
  Cleaned up pngpriv.h to consistently declare all functions and data.
    Also eliminated PNG_CONST_DATA, which is apparently not needed but we
    can't be sure until it is gone.
  Added symbol prefixing that allows all the libpng external symbols
    to be prefixed (suggested by Reuben Hawkins).
  Updated "ftbb*.png" list in the owatcom and vstudio projects.
  Fixed 'prefix' builds on clean systems. The generation of pngprefix.h
    should not require itself.
  Updated INSTALL to explain that autogen.sh must be run in a GIT clone,
    not in a libpng directory extracted from a tar distribution.

Version 1.6.0beta09 [February 1, 2012]

src/Source/LibPNG/CHANGES  view on Meta::CPAN

    pnglibconf.h.prebuilt and pnglibconf.h.

Version 1.6.0beta14 [February 27, 2012]
  Added information about the new limits in the manual.
  Updated Makefile.in

Version 1.6.0beta15 [March 2, 2012]
  Removed unused "current_text" members of png_struct and the png_free()
    of png_ptr->current_text from pngread.c
  Rewrote pngstest.c for substantial speed improvement.
  Fixed transparent pixel and 16-bit rgb tests in pngstest and removed a
    spurious check in pngwrite.c
  Added PNG_IMAGE_FLAG_FAST for the benefit of applications that store
    intermediate files, or intermediate in-memory data, while processing
    image data with the simplified API.  The option makes the files larger
    but faster to write and read.  pngstest now uses this by default; this
    can be disabled with the --slow option.
  Improved pngstest fine tuning of error numbers, new test file generator.
    The generator generates images that test the full range of sample values,
    allow the error numbers in pngstest to be tuned and checked.  makepng
    also allows generation of images with extra chunks, although this is

src/Source/LibPNG/CHANGES  view on Meta::CPAN

  Issue a png_benign_error() instead of png_warning() about bad palette index.
  In pngtest, treat benign errors as errors if "-strict" is present.
  Fixed an off-by-one error in the palette index checking function.
  Fixed a compiler warning under Cygwin (Windows-7, 32-bit system)
  Revised example.c to put text strings in a temporary character array
    instead of directly assigning string constants to png_textp members.
    This avoids compiler warnings when -Wwrite-strings is enabled.
  Added output flushing to aid debugging under Visual Studio. Unfortunately
    this is necessary because the VS2010 output window otherwise simply loses
    the error messages on error (they weren't flushed to the window before
    the process exited, apparently!)
  Added configuration support for benign errors and changed the read
    default. Also changed some warnings in the iCCP and sRGB handling
    from to benign errors. Configuration now makes read benign
    errors warnings and write benign errors to errors by default (thus
    changing the behavior on read).  The simplified API always forces
    read benign errors to warnings (regardless of the system default, unless
    this is disabled in which case the simplified API can't be built.)

Version 1.6.0beta19 [March 18, 2012]
  Work around for duplicate row start calls; added warning messages.

src/Source/LibPNG/CHANGES  view on Meta::CPAN

    work everywhere.
  Enabled parallel tests - back ported from libpng-1.7.
  scripts/pnglibconf.dfa formatting improvements back ported from libpng17.
  Fixed a race condition in the creation of the build 'scripts' directory
    while building with a parallel make.
  Use approved/supported Android method to check for NEON, use Linux/POSIX
    1003.1 API to check /proc/self/auxv avoiding buffer allocation and other
    library calls (ported from libpng15).

Version 1.6.1beta02 [February 19, 2013]
  Use parentheses more consistently in "#if defined(MACRO)" tests.
  Folded long lines.
  Reenabled code to allow zero length PLTE chunks for MNG.

Version 1.6.1beta03 [February 22, 2013]
  Fixed ALIGNED_MEMORY support.
  Allow run-time ARM NEON checking to be disabled. A new configure option:
    --enable-arm-neon=always will stop the run-time checks. New checks
    within arm/arm_init.c will cause the code not to be compiled unless
    __ARM_NEON__ is set. This should make it fail safe (if someone asks
    for it on then the build will fail if it can't be done.)

src/Source/LibPNG/CHANGES  view on Meta::CPAN

    seem to generate warnings when an unsigned value is implicitly
    converted to double. This is probably a GCC bug but this change
    avoids the issue by explicitly converting to (int) where safe.
  Free all allocated memory in pngimage. The file buffer cache was left
    allocated at the end of the program, harmless but it causes memory
    leak reports from clang.
  Fixed array size calculations to avoid warnings. At various points
    in the code the number of elements in an array is calculated using
    sizeof.  This generates a compile time constant of type (size_t) which
    is then typically assigned to an (unsigned int) or (int). Some versions
    of GCC on 64-bit systems warn about the apparent narrowing, even though
    the same compiler does apparently generate the correct, in-range,
    numeric constant.  This adds appropriate, safe, casts to make the
    warnings go away.

Version 1.6.15beta06 [November 6, 2014]
  Reverted use png_get_libpng_ver(NULL) instead of PNG_LIBPNG_VER_STRING
    in the manual, example.c, pngtest.c, and applications in the contrib
    directory.  It was incorrect advice.

Version 1.6.15beta07 [November 7, 2014]
  Removed #ifdef PNG_16BIT_SUPPORTED/#endif around png_product2(); it is

src/Source/LibPNG/INSTALL  view on Meta::CPAN

and "bin" subdirectories.

V. Directory structure

You can rename the directories that you downloaded (they
might be called "libpng-x.y.z" or "libpngNN" and "zlib-1.2.8"
or "zlib128") so that you have directories called "zlib" and "libpng".

Your directory structure should look like this:

   ..       (the parent directory)
      libpng  (this directory)
          INSTALL (this file)
          README
          *.h, *.c  => libpng source files
          CMakeLists.txt    =>  "cmake" script
          configuration files:
             configure.ac, configure, Makefile.am, Makefile.in,
             autogen.sh, config.guess, ltmain.sh, missing, libpng.pc.in,
             libpng-config.in, aclocal.m4, config.h.in, config.sub,
             depcomp, install-sh, mkinstalldirs, test-pngtest.sh

src/Source/LibPNG/INSTALL  view on Meta::CPAN

an "unsigned char far * far *".

XI. Prepending a prefix to exported symbols

Starting with libpng-1.6.0, you can configure libpng (when using the
"configure" script) to prefix all exported symbols by means of the
configuration option "--with-libpng-prefix=FOO_", where FOO_ can be any
string beginning with a letter and containing only uppercase
and lowercase letters, digits, and the underscore (i.e., a C language
identifier).  This creates a set of macros in pnglibconf.h, so this is
transparent to applications; their function calls get transformed by
the macros to use the modified names.

XII. Configuring for compiler xxx:

All includes for libpng are in pngconf.h.  If you need to add, change
or delete an include, this is the place to do it.
The includes that are not needed outside libpng are placed in pngpriv.h,
which is only used by the routines inside libpng itself.
The files in libpng proper only include pngpriv.h and png.h, which
in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h.



( run in 1.426 second using v1.01-cache-2.11-cpan-fd5d4e115d8 )