This commit is contained in:
2012-09-02 15:24:38 +02:00
commit 5b667b5781
250 changed files with 70477 additions and 0 deletions

20
DSTexCompress.sln Normal file
View File

@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DSTexCompress", "DSTexCompress\DSTexCompress.vcproj", "{126B132C-BACE-403D-A643-CF31C47672C8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{126B132C-BACE-403D-A643-CF31C47672C8}.Debug|Win32.ActiveCfg = Debug|Win32
{126B132C-BACE-403D-A643-CF31C47672C8}.Debug|Win32.Build.0 = Debug|Win32
{126B132C-BACE-403D-A643-CF31C47672C8}.Release|Win32.ActiveCfg = Release|Win32
{126B132C-BACE-403D-A643-CF31C47672C8}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

BIN
DSTexCompress.suo Normal file

Binary file not shown.

View File

@@ -0,0 +1,225 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="DSTexCompress"
ProjectGUID="{126B132C-BACE-403D-A643-CF31C47672C8}"
RootNamespace="DSTexCompress"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="FreeImage\Dist"
PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="FreeImagePlus.lib"
AdditionalLibraryDirectories="FreeImage\Dist"
GenerateDebugInformation="true"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="FreeImage\Dist"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="FreeImage.lib FreeImagePlus.lib"
AdditionalLibraryDirectories="FreeImage\Dist"
GenerateDebugInformation="true"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header"
>
<File
RelativePath=".\src\Color.h"
>
</File>
<File
RelativePath=".\src\Compressor.h"
>
</File>
<File
RelativePath=".\src\Cut.h"
>
</File>
<File
RelativePath=".\src\Histogram.h"
>
</File>
<File
RelativePath=".\src\Palette.h"
>
</File>
<File
RelativePath=".\src\types.h"
>
</File>
<File
RelativePath=".\src\wingetopt.h"
>
</File>
</Filter>
<Filter
Name="Source"
>
<File
RelativePath=".\src\Compressor.cpp"
>
</File>
<File
RelativePath=".\src\Histogram.cpp"
>
</File>
<File
RelativePath=".\src\main.cpp"
>
</File>
<File
RelativePath=".\src\Palette.cpp"
>
</File>
<File
RelativePath=".\src\wingetopt.c"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

BIN
DSTexCompress/FreeImage.dll Normal file

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

View File

@@ -0,0 +1,214 @@
// ==========================================================
// Batch loader
//
// Design and implementation by
// - Floris van den Berg
// - Herv<72> Drolon
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at own risk!
// ==========================================================
//
// This example shows how to easily batch load a directory
// full of images. Because not all formats can be identified
// by their header (some images don't have a header or one
// at the end of the file) we make use of the
// FreeImage_GetFIFFromFilename function. This function
// receives a file name, for example 'myfile.bmp', and returns
// a FREE_IMAGE_TYPE enum which identifies that bitmap.
//
// Functions used in this sample :
// FreeImage_GetFileType, FreeImage_GetFIFFromFilename, FreeImage_FIFSupportsReading,
// FreeImage_Load, FreeImage_GetBPP, FreeImage_FIFSupportsWriting, FreeImage_GetFormatFromFIF
// FreeImage_FIFSupportsExportBPP, FreeImage_Save, FreeImage_Unload,
// FreeImage_SetOutputMessage, FreeImage_GetVersion, FreeImage_GetCopyrightMessage
//
// ==========================================================
#include <assert.h>
#include <stdio.h>
#include <io.h>
#include <string.h>
#include <stdlib.h>
#include "FreeImage.h"
// ----------------------------------------------------------
/** Generic image loader
@param lpszPathName Pointer to the full file name
@param flag Optional load flag constant
@return Returns the loaded dib if successful, returns NULL otherwise
*/
FIBITMAP* GenericLoader(const char* lpszPathName, int flag) {
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
// check the file signature and deduce its format
// (the second argument is currently not used by FreeImage)
fif = FreeImage_GetFileType(lpszPathName, 0);
if(fif == FIF_UNKNOWN) {
// no signature ?
// try to guess the file format from the file extension
fif = FreeImage_GetFIFFromFilename(lpszPathName);
}
// check that the plugin has reading capabilities ...
if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
// ok, let's load the file
FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, flag);
// unless a bad file format, we are done !
return dib;
}
return NULL;
}
/** Generic image writer
@param dib Pointer to the dib to be saved
@param lpszPathName Pointer to the full file name
@param flag Optional save flag constant
@return Returns true if successful, returns false otherwise
*/
bool GenericWriter(FIBITMAP* dib, const char* lpszPathName, int flag) {
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
BOOL bSuccess = FALSE;
if(dib) {
// try to guess the file format from the file extension
fif = FreeImage_GetFIFFromFilename(lpszPathName);
if(fif != FIF_UNKNOWN ) {
// check that the plugin has sufficient writing and export capabilities ...
WORD bpp = FreeImage_GetBPP(dib);
if(FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)) {
// ok, we can save the file
bSuccess = FreeImage_Save(fif, dib, lpszPathName, flag);
// unless an abnormal bug, we are done !
}
}
}
return (bSuccess == TRUE) ? true : false;
}
// ----------------------------------------------------------
/**
FreeImage error handler
@param fif Format / Plugin responsible for the error
@param message Error message
*/
void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) {
printf("\n*** ");
if(fif != FIF_UNKNOWN) {
printf("%s Format\n", FreeImage_GetFormatFromFIF(fif));
}
printf(message);
printf(" ***\n");
}
// ----------------------------------------------------------
#ifndef MAX_PATH
#define MAX_PATH 260
#endif
int
main(int argc, char *argv[]) {
const char *input_dir = "d:\\images\\";
FIBITMAP *dib = NULL;
int id = 1;
// call this ONLY when linking with FreeImage as a static library
#ifdef FREEIMAGE_LIB
FreeImage_Initialise();
#endif // FREEIMAGE_LIB
// initialize your own FreeImage error handler
FreeImage_SetOutputMessage(FreeImageErrorHandler);
// print version & copyright infos
printf(FreeImage_GetVersion());
printf("\n");
printf(FreeImage_GetCopyrightMessage());
printf("\n");
// open the log file
FILE *log_file = fopen("log_file.txt", "w");
// batch convert all supported bitmaps
_finddata_t finddata;
long handle;
char image_path[MAX_PATH];
// scan all files
strcpy(image_path, input_dir);
strcat(image_path, "*.*");
if ((handle = _findfirst(image_path, &finddata)) != -1) {
do {
// make a path to a directory
char *directory = new char[MAX_PATH];
strcpy(directory, input_dir);
strcat(directory, finddata.name);
// make a unique filename
char *unique = new char[128];
itoa(id, unique, 10);
strcat(unique, ".png");
// open and load the file using the default load option
dib = GenericLoader(directory, 0);
if (dib != NULL) {
// save the file as PNG
bool bSuccess = GenericWriter(dib, unique, PNG_DEFAULT);
// free the dib
FreeImage_Unload(dib);
if(bSuccess) {
fwrite(unique, strlen(unique), 1, log_file);
} else {
strcpy(unique, "FAILED");
fwrite(unique, strlen(unique), 1, log_file);
}
fwrite(" >> ", 4, 1, log_file);
fwrite(directory, strlen(directory), 1, log_file);
fwrite("\n", 1, 1, log_file);
id++;
}
delete [] unique;
delete [] directory;
} while (_findnext(handle, &finddata) == 0);
_findclose(handle);
}
fclose(log_file);
// call this ONLY when linking with FreeImage as a static library
#ifdef FREEIMAGE_LIB
FreeImage_DeInitialise();
#endif // FREEIMAGE_LIB
return 0;
}

View File

@@ -0,0 +1,112 @@
// ==========================================================
// Multipage functions demonstration
//
// Design and implementation by
// - Herv<72> Drolon
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at own risk!
// ==========================================================
// This sample shows how to clone a multipage TIFF
//
// Functions used in this sample :
// FreeImage_OpenMultiBitmap, FreeImage_GetPageCount, FreeImage_LockPage,
// FreeImage_AppendPage, FreeImage_UnlockPage, FreeImage_CloseMultiBitmap;
// FreeImage_SetOutputMessage
//
// ==========================================================
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include "FreeImage.h"
// ----------------------------------------------------------
/**
FreeImage error handler
*/
void MyMessageFunc(FREE_IMAGE_FORMAT fif, const char *message) {
cout << "\n*** " << message << " ***\n";
cout.flush();
}
// ----------------------------------------------------------
bool CloneMultiPage(FREE_IMAGE_FORMAT fif, char *input, char *output, int output_flag) {
BOOL bMemoryCache = TRUE;
// Open src file (read-only, use memory cache)
FIMULTIBITMAP *src = FreeImage_OpenMultiBitmap(fif, input, FALSE, TRUE, bMemoryCache);
if(src) {
// Open dst file (creation, use memory cache)
FIMULTIBITMAP *dst = FreeImage_OpenMultiBitmap(fif, output, TRUE, FALSE, bMemoryCache);
// Get src page count
int count = FreeImage_GetPageCount(src);
// Clone src to dst
for(int page = 0; page < count; page++) {
// Load the bitmap at position 'page'
FIBITMAP *dib = FreeImage_LockPage(src, page);
if(dib) {
// add a new bitmap to dst
FreeImage_AppendPage(dst, dib);
// Unload the bitmap (do not apply any change to src)
FreeImage_UnlockPage(src, dib, FALSE);
}
}
// Close src
FreeImage_CloseMultiBitmap(src, 0);
// Save and close dst
FreeImage_CloseMultiBitmap(dst, output_flag);
return true;
}
return false;
}
int
main(int argc, char *argv[]) {
char *input_filename = "images\\input.tif";
char *output_filename = "images\\clone.tif";
// call this ONLY when linking with FreeImage as a static library
#ifdef FREEIMAGE_LIB
FreeImage_Initialise();
#endif // FREEIMAGE_LIB
// initialize our own FreeImage error handler
FreeImage_SetOutputMessage(MyMessageFunc);
// Copy 'input.tif' to 'clone.tif'
CloneMultiPage(FIF_TIFF, input_filename, output_filename, 0);
// call this ONLY when linking with FreeImage as a static library
#ifdef FREEIMAGE_LIB
FreeImage_DeInitialise();
#endif // FREEIMAGE_LIB
return 0;
}

View File

@@ -0,0 +1,181 @@
// ==========================================================
// Alpha channel manipulation example
//
// Design and implementation by
// - Herv<72> Drolon
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at own risk!
// ==========================================================
// This example shows how to create a transparent image from any input image
// using the greyscale version of the input image as the alpha channel mask.
// The alpha channel is set using the FreeImage_SetChannel function.
//
//
// ==========================================================
#include <stdio.h>
#include "FreeImage.h"
// ----------------------------------------------------------
/** Generic image loader
@param lpszPathName Pointer to the full file name
@param flag Optional load flag constant
@return Returns the loaded dib if successful, returns NULL otherwise
*/
FIBITMAP* GenericLoader(const char* lpszPathName, int flag) {
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
// check the file signature and deduce its format
// (the second argument is currently not used by FreeImage)
fif = FreeImage_GetFileType(lpszPathName, 0);
if(fif == FIF_UNKNOWN) {
// no signature ?
// try to guess the file format from the file extension
fif = FreeImage_GetFIFFromFilename(lpszPathName);
}
// check that the plugin has reading capabilities ...
if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
// ok, let's load the file
FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, flag);
// unless a bad file format, we are done !
return dib;
}
return NULL;
}
/** Generic image writer
@param dib Pointer to the dib to be saved
@param lpszPathName Pointer to the full file name
@param flag Optional save flag constant
@return Returns true if successful, returns false otherwise
*/
bool GenericWriter(FIBITMAP* dib, const char* lpszPathName, int flag) {
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
BOOL bSuccess = FALSE;
if(dib) {
// try to guess the file format from the file extension
fif = FreeImage_GetFIFFromFilename(lpszPathName);
if(fif != FIF_UNKNOWN ) {
// check that the plugin has sufficient writing and export capabilities ...
WORD bpp = FreeImage_GetBPP(dib);
if(FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)) {
// ok, we can save the file
bSuccess = FreeImage_Save(fif, dib, lpszPathName, flag);
// unless an abnormal bug, we are done !
}
}
}
return (bSuccess == TRUE) ? true : false;
}
// ----------------------------------------------------------
/**
FreeImage error handler
@param fif Format / Plugin responsible for the error
@param message Error message
*/
void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) {
printf("\n*** ");
if(fif != FIF_UNKNOWN) {
printf("%s Format\n", FreeImage_GetFormatFromFIF(fif));
}
printf(message);
printf(" ***\n");
}
// ----------------------------------------------------------
/**
Creates a 32-bit transparent image using the black channel of the source image
@param src Source image
@return Returns a 32-bit transparent image
*/
FIBITMAP* CreateAlphaFromLightness(FIBITMAP *src) {
// create a 32-bit image from the source
FIBITMAP *dst = FreeImage_ConvertTo32Bits(src);
// create a 8-bit mask
FreeImage_Invert(src);
FIBITMAP *mask = FreeImage_ConvertTo8Bits(src);
FreeImage_Invert(src);
// insert the mask as an alpha channel
FreeImage_SetChannel(dst, mask, FICC_ALPHA);
// free the mask and return
FreeImage_Unload(mask);
return dst;
}
int
main(int argc, char *argv[]) {
// call this ONLY when linking with FreeImage as a static library
#ifdef FREEIMAGE_LIB
FreeImage_Initialise();
#endif // FREEIMAGE_LIB
// initialize your own FreeImage error handler
FreeImage_SetOutputMessage(FreeImageErrorHandler);
// print version & copyright infos
printf("FreeImage version : %s", FreeImage_GetVersion());
printf("\n");
printf(FreeImage_GetCopyrightMessage());
printf("\n");
if(argc != 3) {
printf("Usage : CreateAlpha <input file name> <output file name>\n");
return 0;
}
// Load the source image
FIBITMAP *src = GenericLoader(argv[1], 0);
if(src) {
// Create a transparent image from the lightness image of src
FIBITMAP *dst = CreateAlphaFromLightness(src);
if(dst) {
// Save the destination image
bool bSuccess = GenericWriter(dst, argv[2], 0);
if(!bSuccess) {
printf("\nUnable to save %s file", argv[2]);
printf("\nThis format does not support 32-bit images");
}
// Free dst
FreeImage_Unload(dst);
}
// Free src
FreeImage_Unload(src);
}
// call this ONLY when linking with FreeImage as a static library
#ifdef FREEIMAGE_LIB
FreeImage_DeInitialise();
#endif // FREEIMAGE_LIB
return 0;
}

View File

@@ -0,0 +1,149 @@
// ==========================================================
// Plugin functions demonstration
//
// Design and implementation by
// - Herv<72> Drolon
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at own risk!
// ==========================================================
// This example shows how to use Plugin functions to explore FreeImage capabilities.
// Whenever an external plugin is added to the library, it is automatically loaded
// with FreeImage and can be asked for its capabilities via the plugin functions.
//
// Functions used in this sample :
// FreeImage_FIFSupportsExportBPP, FreeImage_FIFSupportsICCProfiles, FreeImage_FIFSupportsReading,
// FreeImage_FIFSupportsWriting, FreeImage_GetFIFCount, FreeImage_GetFIFDescription,
// FreeImage_GetFIFExtensionList, FreeImage_GetFormatFromFIF,
// FreeImage_GetVersion, FreeImage_GetCopyrightMessage, FreeImage_SetOutputMessage
//
// ==========================================================
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <string.h>
#include "FreeImage.h"
// ----------------------------------------------------------
/**
FreeImage error handler
*/
void MyMessageFunc(FREE_IMAGE_FORMAT fif, const char *message) {
cout << "\n*** " << message << " ***\n";
}
// ----------------------------------------------------------
/**
Print plugins import capabilities
*/
void PrintImportFormats(iostream& ios) {
int count = FreeImage_GetFIFCount();
if(count)
ios << "FORMAT;DESCRIPTION;EXTENSIONS;ICC PROFILES\n";
for(int i = 0; i < count; i++) {
FREE_IMAGE_FORMAT fif = (FREE_IMAGE_FORMAT)i;
if(FreeImage_FIFSupportsReading(fif)) {
const char * format = FreeImage_GetFormatFromFIF(fif);
const char * description = FreeImage_GetFIFDescription(fif);
const char * ext = FreeImage_GetFIFExtensionList(fif);
const char * icc = "*";
if(FreeImage_FIFSupportsICCProfiles(fif)) {
ios << format << ";" << description << ";" << ext << ";" << icc << "\n";
} else {
ios << format << ";" << description << ";" << ext << "; \n";
}
}
}
}
/**
Print plugins export capabilities
*/
void PrintExportFormats(iostream& ios) {
int count = FreeImage_GetFIFCount();
if(count)
ios << "FORMAT;DESCRIPTION;EXTENSIONS;BITDEPTH;ICC PROFILES\n";
for(int i = 0; i < count; i++) {
FREE_IMAGE_FORMAT fif = (FREE_IMAGE_FORMAT)i;
if(FreeImage_FIFSupportsWriting(fif)) {
const char * format = FreeImage_GetFormatFromFIF(fif);
const char * description = FreeImage_GetFIFDescription(fif);
const char * ext = FreeImage_GetFIFExtensionList(fif);
const char * icc = "*";
ios << format << ";" << description << ";" << ext << ";";
if(FreeImage_FIFSupportsExportBPP(fif, 1))
ios << "1 ";
if(FreeImage_FIFSupportsExportBPP(fif, 4))
ios << "4 ";
if(FreeImage_FIFSupportsExportBPP(fif, 8))
ios << "8 ";
if(FreeImage_FIFSupportsExportBPP(fif, 16))
ios << "16 ";
if(FreeImage_FIFSupportsExportBPP(fif, 24))
ios << "24 ";
if(FreeImage_FIFSupportsExportBPP(fif, 32))
ios << "32 ";
if(FreeImage_FIFSupportsICCProfiles(fif)) {
ios << ";" << icc;
} else {
ios << "; ";
}
ios << "\n";
}
}
}
int
main(int argc, char *argv[]) {
// call this ONLY when linking with FreeImage as a static library
#ifdef FREEIMAGE_LIB
FreeImage_Initialise();
#endif // FREEIMAGE_LIB
// initialize FreeImage error handler
FreeImage_SetOutputMessage(MyMessageFunc);
// print version & copyright infos
cout << "FreeImage " << FreeImage_GetVersion() << "\n";
cout << FreeImage_GetCopyrightMessage() << "\n\n";
// Print input formats (including external plugins) known by the library
fstream importFile("fif_import.csv", ios::out);
PrintImportFormats(importFile);
importFile.close();
// Print output formats (including plugins) known by the library
// for each export format, supported bitdepths are given
fstream exportFile("fif_export.csv", ios::out);
PrintExportFormats(exportFile);
exportFile.close();
// call this ONLY when linking with FreeImage as a static library
#ifdef FREEIMAGE_LIB
FreeImage_DeInitialise();
#endif // FREEIMAGE_LIB
return 0;
}

View File

@@ -0,0 +1,146 @@
/*--------------------------------------------------------------------------*\
|| fiio_mem.cpp by Ryan Rubley <ryan@lostreality.org> ||
|| ||
|| (v1.02) 4-28-2004 ||
|| FreeImageIO to memory ||
|| ||
\*--------------------------------------------------------------------------*/
#include <string.h>
#include <stdlib.h>
#include "fiio_mem.h"
#ifdef __cplusplus
extern "C" {
#endif
FIBITMAP *
FreeImage_LoadFromMem(FREE_IMAGE_FORMAT fif, fiio_mem_handle *handle, int flags) {
FreeImageIO io;
SetMemIO(&io);
if (handle && handle->data) {
handle->curpos = 0;
return FreeImage_LoadFromHandle(fif, &io, (fi_handle)handle, flags);
}
return NULL;
}
BOOL
FreeImage_SaveToMem(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, fiio_mem_handle *handle, int flags) {
FreeImageIO io;
SetMemIO(&io);
if (handle) {
handle->filelen = 0;
handle->curpos = 0;
return FreeImage_SaveToHandle(fif, dib, &io, (fi_handle)handle, flags);
}
return FALSE;
}
// ----------------------------------------------------------
void
SetMemIO(FreeImageIO *io) {
io->read_proc = fiio_mem_ReadProc;
io->seek_proc = fiio_mem_SeekProc;
io->tell_proc = fiio_mem_TellProc;
io->write_proc = fiio_mem_WriteProc;
}
// ----------------------------------------------------------
#define FIIOMEM(member) (((fiio_mem_handle *)handle)->member)
unsigned
fiio_mem_ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) {
unsigned x;
for( x=0; x<count; x++ ) {
//if there isnt size bytes left to read, set pos to eof and return a short count
if( FIIOMEM(filelen)-FIIOMEM(curpos) < (long)size ) {
FIIOMEM(curpos) = FIIOMEM(filelen);
break;
}
//copy size bytes count times
memcpy( buffer, (char *)FIIOMEM(data) + FIIOMEM(curpos), size );
FIIOMEM(curpos) += size;
buffer = (char *)buffer + size;
}
return x;
}
unsigned
fiio_mem_WriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) {
void *newdata;
long newdatalen;
//double the data block size if we need to
while( FIIOMEM(curpos)+(long)(size*count) >= FIIOMEM(datalen) ) {
//if we are at or above 1G, we cant double without going negative
if( FIIOMEM(datalen) & 0x40000000 ) {
//max 2G
if( FIIOMEM(datalen) == 0x7FFFFFFF ) {
return 0;
}
newdatalen = 0x7FFFFFFF;
} else if( FIIOMEM(datalen) == 0 ) {
//default to 4K if nothing yet
newdatalen = 4096;
} else {
//double size
newdatalen = FIIOMEM(datalen) << 1;
}
newdata = realloc( FIIOMEM(data), newdatalen );
if( !newdata ) {
return 0;
}
FIIOMEM(data) = newdata;
FIIOMEM(datalen) = newdatalen;
}
memcpy( (char *)FIIOMEM(data) + FIIOMEM(curpos), buffer, size*count );
FIIOMEM(curpos) += size*count;
if( FIIOMEM(curpos) > FIIOMEM(filelen) ) {
FIIOMEM(filelen) = FIIOMEM(curpos);
}
return count;
}
int
fiio_mem_SeekProc(fi_handle handle, long offset, int origin) {
switch(origin) { //0 to filelen-1 are 'inside' the file
default:
case SEEK_SET: //can fseek() to 0-7FFFFFFF always
if( offset >= 0 ) {
FIIOMEM(curpos) = offset;
return 0;
}
break;
case SEEK_CUR:
if( FIIOMEM(curpos)+offset >= 0 ) {
FIIOMEM(curpos) += offset;
return 0;
}
break;
case SEEK_END:
if( FIIOMEM(filelen)+offset >= 0 ) {
FIIOMEM(curpos) = FIIOMEM(filelen)+offset;
return 0;
}
break;
}
return -1;
}
long
fiio_mem_TellProc(fi_handle handle) {
return FIIOMEM(curpos);
}
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,74 @@
/*--------------------------------------------------------------------------*\
|| fiio_mem.h by Ryan Rubley <ryan@lostreality.org> ||
|| ||
|| (v1.02) 4-28-2004 ||
|| FreeImageIO to memory ||
|| ||
\*--------------------------------------------------------------------------*/
#ifndef _FIIO_MEM_H_
#define _FIIO_MEM_H_
#include "freeimage.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct fiio_mem_handle_s {
long filelen,datalen,curpos;
void *data;
} fiio_mem_handle;
/* it is up to the user to create a fiio_mem_handle and init datalen and data
* filelen will be pre-set to 0 by SaveToMem
* curpos will be pre-set to 0 by SaveToMem and LoadFromMem
* IMPORTANT: data should be set to NULL and datalen to 0,
* unless the user wants to manually malloc a larger buffer
*/
FIBITMAP *FreeImage_LoadFromMem(FREE_IMAGE_FORMAT fif, fiio_mem_handle *handle, int flags);
BOOL FreeImage_SaveToMem(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, fiio_mem_handle *handle, int flags);
void SetMemIO(FreeImageIO *io);
unsigned fiio_mem_ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle);
unsigned fiio_mem_WriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle);
int fiio_mem_SeekProc(fi_handle handle, long offset, int origin);
long fiio_mem_TellProc(fi_handle handle);
/*** Example Usage ***
//variables
FIBITMAP *bitmap, *bitmap2;
fiio_mem_handle fmh;
//important initialization
fmh.data = NULL;
fmh.datalen = 0;
//load a regular file
bitmap = FreeImage_Load(FIF_PNG, "sample.png");
//save the file to memory
FreeImage_SaveToMem(FIF_PNG, bitmap, &fmh, 0);
//at this point, fmh.data contains the entire PNG data in memory
//fmh.datalen is the amount of space malloc'd for the image in memory,
//but only fmh.filelen amount of that space is actually used.
//its easy load an image from memory as well
bitmap2 = FreeImage_LoadFromMem(FIF_PNG, &fmh, 0);
//you could also have image data in memory via some other method, and just set
//fmh.data to point to it, and set both fmh.datalen and fmh.filelen to the
//size of that data, then FreeImage_LoadFromMem could load the image from that
//memory
//make sure to free the data since SaveToMem will cause it to be malloc'd
free(fmh.data);
*/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,145 @@
// ==========================================================
// Load From Handle Example
//
// Design and implementation by
// - Herv<72> Drolon
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at own risk!
// ==========================================================
// This example shows how to load a bitmap from a
// user allocated FILE pointer.
//
// Functions used in this sample :
// FreeImage_GetFormatFromFIF, FreeImage_GetFileTypeFromHandle, FreeImage_LoadFromHandle,
// FreeImage_GetFIFFromFilename, FreeImage_Save, FreeImage_Unload
// FreeImage_GetVersion, FreeImage_GetCopyrightMessage, FreeImage_SetOutputMessage
//
// ==========================================================
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "FreeImage.h"
// ----------------------------------------------------------
/**
FreeImage error handler
@param fif Format / Plugin responsible for the error
@param message Error message
*/
void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) {
printf("\n*** ");
if(fif != FIF_UNKNOWN) {
printf("%s Format\n", FreeImage_GetFormatFromFIF(fif));
}
printf(message);
printf(" ***\n");
}
// ----------------------------------------------------------
unsigned DLL_CALLCONV
myReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) {
return fread(buffer, size, count, (FILE *)handle);
}
unsigned DLL_CALLCONV
myWriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) {
return fwrite(buffer, size, count, (FILE *)handle);
}
int DLL_CALLCONV
mySeekProc(fi_handle handle, long offset, int origin) {
return fseek((FILE *)handle, offset, origin);
}
long DLL_CALLCONV
myTellProc(fi_handle handle) {
return ftell((FILE *)handle);
}
// ----------------------------------------------------------
int
main(int argc, char *argv[]) {
// call this ONLY when linking with FreeImage as a static library
#ifdef FREEIMAGE_LIB
FreeImage_Initialise();
#endif // FREEIMAGE_LIB
// initialize your own FreeImage error handler
FreeImage_SetOutputMessage(FreeImageErrorHandler);
// print version & copyright infos
printf(FreeImage_GetVersion());
printf("\n");
printf(FreeImage_GetCopyrightMessage());
printf("\n");
if(argc != 2) {
printf("Usage : LoadFromHandle <input file name>\n");
return 0;
}
// initialize your own IO functions
FreeImageIO io;
io.read_proc = myReadProc;
io.write_proc = myWriteProc;
io.seek_proc = mySeekProc;
io.tell_proc = myTellProc;
FILE *file = fopen(argv[1], "rb");
if (file != NULL) {
// find the buffer format
FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromHandle(&io, (fi_handle)file, 0);
if(fif != FIF_UNKNOWN) {
// load from the file handle
FIBITMAP *dib = FreeImage_LoadFromHandle(fif, &io, (fi_handle)file, 0);
// save the bitmap as a PNG ...
const char *output_filename = "test.png";
// first, check the output format from the file name or file extension
FREE_IMAGE_FORMAT out_fif = FreeImage_GetFIFFromFilename(output_filename);
if(out_fif != FIF_UNKNOWN) {
// then save the file
FreeImage_Save(out_fif, dib, output_filename, 0);
}
// free the loaded FIBITMAP
FreeImage_Unload(dib);
}
fclose(file);
}
// call this ONLY when linking with FreeImage as a static library
#ifdef FREEIMAGE_LIB
FreeImage_DeInitialise();
#endif // FREEIMAGE_LIB
return 0;
}

View File

@@ -0,0 +1,101 @@
// ==========================================================
// Classified FreeImageIO handler
//
// Design and implementation by
// - schickb (schickb@hotmail.com)
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================
class MemIO : public FreeImageIO {
public :
MemIO( BYTE *data ) : _start(data), _cp(data) {
read_proc = _ReadProc;
write_proc = _WriteProc;
tell_proc = _TellProc;
seek_proc = _SeekProc;
}
void Reset() {
_cp = _start;
}
static unsigned _ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle);
static unsigned _WriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle);
static int _SeekProc(fi_handle handle, long offset, int origin);
static long _TellProc(fi_handle handle);
private:
BYTE * const _start;
BYTE *_cp;
};
unsigned
MemIO::_ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) {
MemIO *memIO = (MemIO*)handle;
BYTE *tmp = (BYTE *)buffer;
for (unsigned c = 0; c < count; c++) {
memcpy(tmp, memIO->_cp, size);
memIO->_cp = memIO->_cp + size;
tmp += size;
}
return count;
}
unsigned
MemIO::_WriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) {
ASSERT( false );
return size;
}
int
MemIO::_SeekProc(fi_handle handle, long offset, int origin) {
ASSERT(origin != SEEK_END);
MemIO *memIO = (MemIO*)handle;
if (origin == SEEK_SET)
memIO->_cp = memIO->_start + offset;
else
memIO->_cp = memIO->_cp + offset;
return 0;
}
long
MemIO::_TellProc(fi_handle handle) {
MemIO *memIO = (MemIO*)handle;
return memIO->_cp - memIO->_start;
}
// ----------------------------------------------------------
// PSEUDOCODE... HELPS TO UNDERSTAND HOW THE MEMIO CLASS WORKS
// ----------------------------------------------------------
int
main(int argc, char *argv[]) {
BYTE *data = loadimagesomehow();
MemIO memIO(data);
FIBITMAP *fbmp = FreeImage_LoadFromHandle( fif, &memIO, (fi_handle)&memIO );
}

View File

@@ -0,0 +1,113 @@
// ==========================================================
// Load From Memory Example
//
// Design and implementation by Floris van den Berg
//
// This file is part of FreeImage 3
//
// Use at own risk!
// ==========================================================
//
// This example shows how to load a bitmap from memory
// rather than from a file. To do this we make use of the
// FreeImage_LoadFromHandle functions where we override
// the i/o functions to simulate FILE* access in memory.
//
// For seeking purposes the fi_handle passed to the i/o
// functions contain the start of the data block where the
// bitmap is stored.
//
// ==========================================================
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "FreeImage.h"
// ----------------------------------------------------------
fi_handle g_load_address;
// ----------------------------------------------------------
inline unsigned _stdcall
_ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) {
BYTE *tmp = (BYTE *)buffer;
for (unsigned c = 0; c < count; c++) {
memcpy(tmp, g_load_address, size);
g_load_address = (BYTE *)g_load_address + size;
tmp += size;
}
return count;
}
inline unsigned _stdcall
_WriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) {
// there's not much use for saving the bitmap into memory now, is there?
return size;
}
inline int _stdcall
_SeekProc(fi_handle handle, long offset, int origin) {
assert(origin != SEEK_END);
if (origin == SEEK_SET) {
g_load_address = (BYTE *)handle + offset;
} else {
g_load_address = (BYTE *)g_load_address + offset;
}
return 0;
}
inline long _stdcall
_TellProc(fi_handle handle) {
assert((int)handle > (int)g_load_address);
return ((int)g_load_address - (int)handle);
}
// ----------------------------------------------------------
int
main(int argc, char *argv[]) {
FreeImageIO io;
io.read_proc = _ReadProc;
io.write_proc = _WriteProc;
io.tell_proc = _TellProc;
io.seek_proc = _SeekProc;
// allocate some memory for the bitmap
BYTE *test = new BYTE[159744];
if (test != NULL) {
// load the bitmap into memory. ofcourse you can do this any way you want
FILE *file = fopen("e:\\projects\\images\\money-256.tif", "rb");
fread(test, 159744, 1, file);
fclose(file);
// we store the load address of the bitmap for internal reasons
g_load_address = test;
// convert the bitmap
FIBITMAP *dib = FreeImage_LoadFromHandle(FIF_TIFF, &io, (fi_handle)test);
// don't forget to free the dib !
FreeImage_Unload(dib);
delete [] test;
}
return 0;
}

View File

@@ -0,0 +1,317 @@
// ==========================================================
// Simple metadata reader
//
// Design and implementation by
// - Herv<72> Drolon
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at own risk!
// ==========================================================
//
// This example shows how to easily parse all metadata
// contained in a JPEG, TIFF or PNG image.
// Comments, Exif and IPTC/NAA metadata tags are written to a HTML file
// for later reading, and Adobe XMP XML packets are written
// in a file whose extension is '.xmp'. This file can be later
// processed using a XML parser.
//
// Metadata functions showed in this sample :
// FreeImage_GetMetadataCount, FreeImage_FindFirstMetadata, FreeImage_FindNextMetadata,
// FreeImage_FindCloseMetadata, FreeImage_TagToString, FreeImage_GetMetadata
//
// ==========================================================
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;
#include "FreeImage.h"
// ----------------------------------------------------------
/** Generic image loader
@param lpszPathName Pointer to the full file name
@param flag Optional load flag constant
@return Returns the loaded dib if successful, returns NULL otherwise
*/
FIBITMAP* GenericLoader(const char* lpszPathName, int flag) {
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
// check the file signature and deduce its format
// (the second argument is currently not used by FreeImage)
fif = FreeImage_GetFileType(lpszPathName, 0);
if(fif == FIF_UNKNOWN) {
// no signature ?
// try to guess the file format from the file extension
fif = FreeImage_GetFIFFromFilename(lpszPathName);
}
// check that the plugin has reading capabilities ...
if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
// ok, let's load the file
FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, flag);
// unless a bad file format, we are done !
return dib;
}
return NULL;
}
/** Generic image writer
@param dib Pointer to the dib to be saved
@param lpszPathName Pointer to the full file name
@param flag Optional save flag constant
@return Returns true if successful, returns false otherwise
*/
bool GenericWriter(FIBITMAP* dib, const char* lpszPathName, int flag) {
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
BOOL bSuccess = FALSE;
if(dib) {
// try to guess the file format from the file extension
fif = FreeImage_GetFIFFromFilename(lpszPathName);
if(fif != FIF_UNKNOWN ) {
// check that the plugin has sufficient writing and export capabilities ...
WORD bpp = FreeImage_GetBPP(dib);
if(FreeImage_FIFSupportsWriting(fif) && FreeImage_FIFSupportsExportBPP(fif, bpp)) {
// ok, we can save the file
bSuccess = FreeImage_Save(fif, dib, lpszPathName, flag);
// unless an abnormal bug, we are done !
}
}
}
return (bSuccess == TRUE) ? true : false;
}
// ----------------------------------------------------------
/**
FreeImage error handler
@param fif Format / Plugin responsible for the error
@param message Error message
*/
void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) {
cout << "\n*** ";
if(fif != FIF_UNKNOWN) {
cout << FreeImage_GetFormatFromFIF(fif) << " Format\n";
}
cout << message;
cout << " ***\n";
}
// ----------------------------------------------------------
/**
Print a basic HTML header
*/
void PrintHTMLHeader(iostream& ios) {
ios << "<HTML>\n<BODY>\n<CENTER>\n";
ios << "<FONT FACE = \"Arial\">\n";
}
/**
Print a HTML footer
*/
void PrintHTMLFooter(iostream& ios) {
ios << "</CENTER>\n</FONT>\n</BODY>\n</HTML>\n";
}
/**
Print a table header
*/
void PrintTableHeader(iostream& ios, const char *title) {
ios << "<TABLE BORDER=\"1\">\n";
ios << "<TR><TD ALIGN=CENTER COLSPAN=\"3\" BGCOLOR=\"#CCCCCC\"><B><font face=\"Arial\">" << title << "</font></B></TD></TR>\n";
}
/**
Print a table section
*/
void PrintTableSection(iostream& ios, const char *title) {
ios << "<TR><TD ALIGN=CENTER COLSPAN=\"3\" BGCOLOR=\"#FFFFCC\"><B><font face=\"Arial\">" << title << "</font></B></TD></TR>\n";
ios << "<TR><TD><B>Tag name</B></TD><TD><B>Tag value</B></TD><TD><B>Description</B></TD></TR>";
}
/**
Print a table footer
*/
void PrintTableFooter(iostream& ios) {
ios << "</TABLE>\n";
}
/**
Print the metadata tags to a HTML file
*/
void PrintMetadata(iostream& ios, const char *sectionTitle, FIBITMAP *dib, FREE_IMAGE_MDMODEL model) {
FITAG *tag = NULL;
FIMETADATA *mdhandle = NULL;
mdhandle = FreeImage_FindFirstMetadata(model, dib, &tag);
if(mdhandle) {
// Print a table section
PrintTableSection(ios, sectionTitle);
do {
// convert the tag value to a string
const char *value = FreeImage_TagToString(model, tag);
// print the tag
// note that most tags do not have a description,
// especially when the metadata specifications are not available
if(FreeImage_GetTagDescription(tag)) {
ios << "<TR><TD>" << FreeImage_GetTagKey(tag) << "</TD><TD>" << value << "</TD><TD>" << FreeImage_GetTagDescription(tag) << "</TD></TR>\n";
} else {
ios << "<TR><TD>" << FreeImage_GetTagKey(tag) << "</TD><TD>" << value << "</TD><TD>" << "&nbsp;" << "</TD></TR>\n";
}
} while(FreeImage_FindNextMetadata(mdhandle, &tag));
}
FreeImage_FindCloseMetadata(mdhandle);
}
int
main(int argc, char *argv[]) {
unsigned count;
// call this ONLY when linking with FreeImage as a static library
#ifdef FREEIMAGE_LIB
FreeImage_Initialise();
#endif // FREEIMAGE_LIB
// initialize your own FreeImage error handler
FreeImage_SetOutputMessage(FreeImageErrorHandler);
// print version & copyright infos
cout << "FreeImage " << FreeImage_GetVersion() << "\n";
cout << FreeImage_GetCopyrightMessage() << "\n\n";
if(argc != 2) {
cout << "Usage : ShowMetadata <input file name>\n";
return 0;
}
// Load the bitmap
FIBITMAP *dib = GenericLoader(argv[1], 0);
if(!dib)
return 0;
// Create a HTML file
std::string html_file(strtok(argv[1], ".") + std::string(".html"));
fstream metadataFile(html_file.c_str(), ios::out);
// Print the header
PrintHTMLHeader(metadataFile);
PrintTableHeader(metadataFile, argv[1]);
// Parse and print metadata
if(count = FreeImage_GetMetadataCount(FIMD_COMMENTS, dib)) {
cout << "\nFIMD_COMMENTS (" << count << " data)\n-----------------------------------------\n";
PrintMetadata(metadataFile, "Comments", dib, FIMD_COMMENTS);
}
if(count = FreeImage_GetMetadataCount(FIMD_EXIF_MAIN, dib)) {
cout << "\nFIMD_EXIF_MAIN (" << count << " data)\n-----------------------------------------\n";
PrintMetadata(metadataFile, "Exif - main info", dib, FIMD_EXIF_MAIN);
}
if(count = FreeImage_GetMetadataCount(FIMD_EXIF_EXIF, dib)) {
cout << "\nFIMD_EXIF_EXIF (" << count << " data)\n-----------------------------------------\n";
PrintMetadata(metadataFile, "Exif - advanced info", dib, FIMD_EXIF_EXIF);
}
if(count = FreeImage_GetMetadataCount(FIMD_EXIF_GPS, dib)) {
cout << "\nFIMD_EXIF_GPS (" << count << " data)\n-----------------------------------------\n";
PrintMetadata(metadataFile, "Exif GPS", dib, FIMD_EXIF_GPS);
}
if(count = FreeImage_GetMetadataCount(FIMD_EXIF_INTEROP, dib)) {
cout << "\nFIMD_EXIF_INTEROP (" << count << " data)\n-----------------------------------------\n";
PrintMetadata(metadataFile, "Exif interoperability", dib, FIMD_EXIF_INTEROP);
}
if(count = FreeImage_GetMetadataCount(FIMD_EXIF_MAKERNOTE, dib)) {
cout << "\nFIMD_EXIF_MAKERNOTE (" << count << " data)\n-----------------------------------------\n";
// Get the camera model
FITAG *tagMake = NULL;
FreeImage_GetMetadata(FIMD_EXIF_MAIN, dib, "Make", &tagMake);
std::string buffer((char*)FreeImage_GetTagValue(tagMake));
buffer += " Makernote";
PrintMetadata(metadataFile, buffer.c_str(), dib, FIMD_EXIF_MAKERNOTE);
}
if(count = FreeImage_GetMetadataCount(FIMD_IPTC, dib)) {
cout << "\nFIMD_IPTC (" << count << " data)\n-----------------------------------------\n";
PrintMetadata(metadataFile, "IPTC/NAA", dib, FIMD_IPTC);
}
if(count = FreeImage_GetMetadataCount(FIMD_GEOTIFF, dib)) {
cout << "\nFIMD_GEOTIFF (" << count << " data)\n-----------------------------------------\n";
PrintMetadata(metadataFile, "GEOTIFF", dib, FIMD_GEOTIFF);
}
// Print the footer
PrintTableFooter(metadataFile);
PrintHTMLFooter(metadataFile);
// close the HTML file
metadataFile.close();
// print XMP data
if(count = FreeImage_GetMetadataCount(FIMD_XMP, dib)) {
cout << "\nFIMD_XMP (" << count << " packet)\n-----------------------------------------\n";
std::string xmp_file(strtok(argv[1], ".") + std::string(".xmp"));
metadataFile.open(xmp_file.c_str(), ios::out);
FITAG *tag = NULL;
FreeImage_GetMetadata(FIMD_XMP, dib, "XMLPacket", &tag);
if(tag) {
metadataFile << (char*)FreeImage_GetTagValue(tag);
}
metadataFile.close();
}
// Unload the bitmap
FreeImage_Unload(dib);
// call this ONLY when linking with FreeImage as a static library
#ifdef FREEIMAGE_LIB
FreeImage_DeInitialise();
#endif // FREEIMAGE_LIB
return 0;
}

View File

@@ -0,0 +1,24 @@
CC = gcc
CPP = g++
COMPILERFLAGS = -O3
INCLUDE = -I../../Dist
VGALIBRARIES = -lfreeimage -lvga
VGAINCLUDE = -I/usr/include/asm
GTKLIBRARIES = -lfreeimage `pkg-config --libs gtk+-2.0`
GTKINCLUDE = `pkg-config --cflags gtk+-2.0`
CFLAGS = $(COMPILERFLAGS) $(INCLUDE)
all: default
default: linux-svgalib linux-gtk
linux-svgalib: linux-svgalib.c
$(CC) $(CFLAGS) $< -o $@ $(VGALIBRARIES) $(VGAINCLUDE)
strip $@
linux-gtk: linux-gtk.c
$(CC) $(CFLAGS) $< -o $@ $(GTKLIBRARIES) $(GTKINCLUDE)
strip $@
clean:
rm -f core linux-svgalib linux-gtk

View File

@@ -0,0 +1,100 @@
#include <gtk/gtk.h>
#include <FreeImage.h>
#include <string.h>
void destroy(GtkWidget * widget, gpointer data) {
gtk_main_quit();
}
int main(int argc, char *argv[])
{
GtkWidget *window, *imagebox;
GdkVisual *visual;
GdkImage *image;
FIBITMAP *dib;
int y;
// initialize the FreeImage library
FreeImage_Initialise(TRUE);
dib = FreeImage_Load(FIF_PNG, "freeimage.png", PNG_DEFAULT);
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_signal_connect(GTK_OBJECT(window), "destroy",
GTK_SIGNAL_FUNC(destroy), NULL);
visual = gdk_visual_get_system();
image = gdk_image_new(GDK_IMAGE_NORMAL,visual,
FreeImage_GetWidth(dib),FreeImage_GetHeight(dib));
g_print("picture: %d bpp\n"
"system: %d bpp byteorder: %d\n"
" redbits: %d greenbits: %d bluebits: %d\n"
"image: %d bpp %d bytes/pixel\n",
FreeImage_GetBPP(dib),
visual->depth,visual->byte_order,
visual->red_prec,visual->green_prec,visual->blue_prec,
image->depth,image->bpp );
if (FreeImage_GetBPP(dib) != (image->bpp << 3)) {
FIBITMAP *ptr;
switch (image->bpp) {
case 1:
ptr = FreeImage_ConvertTo8Bits(dib);
break;
case 2:
if (image->depth == 15) {
ptr = FreeImage_ConvertTo16Bits555(dib);
} else {
ptr = FreeImage_ConvertTo16Bits565(dib);
}
break;
case 3:
ptr = FreeImage_ConvertTo24Bits(dib);
break;
default:
case 4:
ptr = FreeImage_ConvertTo32Bits(dib);
break;
}
FreeImage_Unload(dib);
dib = ptr;
}
//makes it upside down :(
// memcpy(image->mem, FreeImage_GetBits(dib), image->bpl * image->height);
BYTE *ptr = FreeImage_GetBits(dib);
for (y = 0; y < image->height; y++) {
memcpy(image->mem + (y * image->bpl),
ptr + ((image->height - y - 1) * image->bpl),
image->bpl);
}
FreeImage_Unload(dib);
imagebox = gtk_image_new_from_image(image, NULL);
gtk_container_add(GTK_CONTAINER(window), imagebox);
gtk_widget_show(imagebox);
gtk_widget_show(window);
gtk_main();
// release the FreeImage library
FreeImage_DeInitialise();
return 0;
}

View File

@@ -0,0 +1,96 @@
#include <vga.h>
#include "FreeImage.h"
int main(void)
{
FIBITMAP *dib,*ptr;
vga_modeinfo *inf;
int length,height,bpp,y;
// initialize the FreeImage library
FreeImage_Initialise();
dib = FreeImage_Load(FIF_PNG, "freeimage.png", PNG_DEFAULT);
vga_init();
vga_setmode(vga_getdefaultmode());
inf = vga_getmodeinfo(vga_getcurrentmode());
switch(inf->colors) {
default:
printf("Must be at least 256 color mode!\n");
return;
case 1 << 8:
bpp = 8;
break;
case 1 << 15:
bpp = 15;
break;
case 1 << 16:
bpp = 16;
break;
case 1 << 24:
if( inf->bytesperpixel == 3 ) {
bpp = 24;
} else {
bpp = 32;
}
break;
}
if(FreeImage_GetBPP(dib) != bpp) {
switch(bpp) {
case 8:
ptr = FreeImage_ConvertTo8Bits(dib);
break;
case 15:
ptr = FreeImage_ConvertTo16Bits555(dib);
break;
case 16:
ptr = FreeImage_ConvertTo16Bits565(dib);
break;
case 24:
ptr = FreeImage_ConvertTo24Bits(dib);
break;
default:
case 32:
ptr = FreeImage_ConvertTo32Bits(dib);
break;
}
FreeImage_Unload(dib);
dib = ptr;
}
length = FreeImage_GetWidth(dib);
if( inf->width < length ) {
length = inf->width;
}
height = FreeImage_GetHeight(dib);
if( inf->height < height ) {
height = inf->height;
}
for(y = 0; y < height; y++) {
vga_drawscansegment(FreeImage_GetScanLine(dib, y), 0, y, length);
}
FreeImage_Unload(dib);
vga_getch();
vga_setmode(TEXT);
// release the FreeImage library
FreeImage_DeInitialise();
return 0;
}

View File

@@ -0,0 +1,145 @@
//**********************************************
//Singleton Texture Manager class
//Written by Ben English
//benjamin.english@oit.edu
//
//For use with OpenGL and the FreeImage library
//**********************************************
#include "TextureManager.h"
TextureManager* TextureManager::m_inst(0);
TextureManager* TextureManager::Inst()
{
if(!m_inst)
m_inst = new TextureManager();
return m_inst;
}
TextureManager::TextureManager()
{
// call this ONLY when linking with FreeImage as a static library
#ifdef FREEIMAGE_LIB
FreeImage_Initialise();
#endif
}
//these should never be called
//TextureManager::TextureManager(const TextureManager& tm){}
//TextureManager& TextureManager::operator=(const TextureManager& tm){}
TextureManager::~TextureManager()
{
// call this ONLY when linking with FreeImage as a static library
#ifdef FREEIMAGE_LIB
FreeImage_DeInitialise();
#endif
UnloadAllTextures();
m_inst = 0;
}
bool TextureManager::LoadTexture(const char* filename, const unsigned int texID, GLenum image_format, GLint internal_format, GLint level, GLint border)
{
//image format
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
//pointer to the image, once loaded
FIBITMAP *dib(0);
//pointer to the image data
BYTE* bits(0);
//image width and height
unsigned int width(0), height(0);
//OpenGL's image ID to map to
GLuint gl_texID;
//check the file signature and deduce its format
fif = FreeImage_GetFileType(filename, 0);
//if still unknown, try to guess the file format from the file extension
if(fif == FIF_UNKNOWN)
fif = FreeImage_GetFIFFromFilename(filename);
//if still unkown, return failure
if(fif == FIF_UNKNOWN)
return false;
//check that the plugin has reading capabilities and load the file
if(FreeImage_FIFSupportsReading(fif))
dib = FreeImage_Load(fif, filename);
//if the image failed to load, return failure
if(!dib)
return false;
//retrieve the image data
bits = FreeImage_GetBits(dib);
//get the image width and height
width = FreeImage_GetWidth(dib);
height = FreeImage_GetHeight(dib);
//if this somehow one of these failed (they shouldn't), return failure
if((bits == 0) || (width == 0) || (height == 0))
return false;
//if this texture ID is in use, unload the current texture
if(m_texID.find(texID) != m_texID.end())
glDeleteTextures(1, &(m_texID[texID]));
//generate an OpenGL texture ID for this texture
glGenTextures(1, &gl_texID);
//store the texture ID mapping
m_texID[texID] = gl_texID;
//bind to the new texture ID
glBindTexture(GL_TEXTURE_2D, gl_texID);
//store the texture data for OpenGL use
glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height,
border, image_format, GL_UNSIGNED_BYTE, bits);
//Free FreeImage's copy of the data
FreeImage_Unload(dib);
//return success
return true;
}
bool TextureManager::UnloadTexture(const unsigned int texID)
{
bool result(true);
//if this texture ID mapped, unload it's texture, and remove it from the map
if(m_texID.find(texID) != m_texID.end())
{
glDeleteTextures(1, &(m_texID[texID]));
m_texID.erase(texID);
}
//otherwise, unload failed
else
{
result = false;
}
return result;
}
bool TextureManager::BindTexture(const unsigned int texID)
{
bool result(true);
//if this texture ID mapped, bind it's texture as current
if(m_texID.find(texID) != m_texID.end())
glBindTexture(GL_TEXTURE_2D, m_texID[texID]);
//otherwise, binding failed
else
result = false;
return result;
}
void TextureManager::UnloadAllTextures()
{
//start at the begginning of the texture map
std::map<unsigned int, GLuint>::iterator i = m_texID.begin();
//Unload the textures untill the end of the texture map is found
while(i != m_texID.end())
UnloadTexture(i->first);
//clear the texture map
m_texID.clear();
}

View File

@@ -0,0 +1,51 @@
//**********************************************
//Singleton Texture Manager class
//Written by Ben English
//benjamin.english@oit.edu
//
//For use with OpenGL and the FreeImage library
//**********************************************
#ifndef TextureManager_H
#define TextureManager_H
#include <windows.h>
#include <gl/gl.h>
#include "FreeImage.h"
#include <map>
class TextureManager
{
public:
static TextureManager* Inst();
virtual ~TextureManager();
//load a texture an make it the current texture
//if texID is already in use, it will be unloaded and replaced with this texture
bool LoadTexture(const char* filename, //where to load the file from
const unsigned int texID, //arbitrary id you will reference the texture by
//does not have to be generated with glGenTextures
GLenum image_format = GL_RGB, //format the image is in
GLint internal_format = GL_RGB, //format to store the image in
GLint level = 0, //mipmapping level
GLint border = 0); //border size
//free the memory for a texture
bool UnloadTexture(const unsigned int texID);
//set the current texture
bool BindTexture(const unsigned int texID);
//free all texture memory
void UnloadAllTextures();
protected:
TextureManager();
TextureManager(const TextureManager& tm);
TextureManager& operator=(const TextureManager& tm);
static TextureManager* m_inst;
std::map<unsigned int, GLuint> m_texID;
};
#endif

View File

@@ -0,0 +1,31 @@
Hello everyone, this is my 2D texture manager class for OpenGL using the FreeImage Library.
Requirements:
--------------------
OpenGL
STL map class
FreeImage (included)
Usage
--------------------
To load a texture, simply call the LoadTexture function:
TextureManager::Inst()->LoadTexture("img\\bg.jpg", BACKGROUND_IMAGE_ID);
This also binds the loaded texture as the current texture, so after calling it you may make any calls to glTexParameter you may need to specify the properties of the texture.
When you are rendering, just call the TextureManager's BindImage function instead of glBindImage:
TextureManager::Inst()->BindImage(BACKGROUND_IMAGE_ID);
and then do your rendering as normal.
--------------------
Feel free to distribute this as you like, but mind the FreeImage licence included in license-fi.txt, and please don't take credit for my code. If you modify it, be sure to mention me (Ben English) somewhere.
Please send any comments or suggestions to me at benjamin.english@oit.edu
Thanks to Herve Drolon for the FreeImage library, I've found it to be very useful!

View File

@@ -0,0 +1,253 @@
// ==========================================================
// Loader/Saver Plugin Cradle
//
// Design and implementation by
// - Floris van den Berg (flvdberg@wxs.nl)
// - Herv<72> Drolon (drolon@infonie.fr)
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================
#include <windows.h>
#include <stdlib.h>
#include "FreeImage.h"
#include "Utilities.h"
// ==========================================================
BOOL APIENTRY
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH :
case DLL_PROCESS_DETACH :
case DLL_THREAD_ATTACH :
case DLL_THREAD_DETACH :
break;
}
return TRUE;
}
// ==========================================================
// Plugin Interface
// ==========================================================
static int s_format_id;
// ==========================================================
// Plugin Implementation
// ==========================================================
/**
Returns the format string for the plugin. Each plugin,
both internal in the DLL and external in a .fip file, must have
a unique format string to be addressable.
*/
static const char * DLL_CALLCONV
Format() {
return "CRADLE";
}
/**
Returns a description string for the plugin. Though a
description is not necessary per-se,
it is advised to return an unique string in order to tell the
user what type of bitmaps this plugin will read and/or write.
*/
static const char * DLL_CALLCONV
Description() {
return "Here comes the description for your image loader/saver";
}
/**
Returns a comma separated list of file extensions indicating
what files this plugin can open. no spaces or whatsoever are allowed.
The list, being used by FreeImage_GetFIFFromFilename, is usually
used as a last resort in finding the type of the bitmap we
are dealing with. Best is to check the first few bytes on
the low-level bits level first and compare them with a known
signature . If this fails, FreeImage_GetFIFFromFilename can be
used.
*/
static const char * DLL_CALLCONV
Extension() {
return "ext1,ext2";
}
/**
RegExpr is only needed for the Qt wrapper
It allows the Qt mechanism for loading bitmaps to identify the bitmap
*/
static const char * DLL_CALLCONV
RegExpr() {
return NULL;
}
/**
Returns a MIME content type string for that format (MIME stands
for Multipurpose Internet Mail Extension).
*/
static const char * DLL_CALLCONV
MimeType() {
return "image/myformat";
}
/**
FreeImage's internal way of seeing if a bitmap is of the desired type.
When the type of a bitmap is to be retrieved, FreeImage runs Validate
for each registered plugin until one returns true. If a plugin doesn't
have a validate function, a return value of false is assumed.
You can always force to use a particular plugin by directly specifying
it on the command line, but this can result in a dead DLL if the plugin
was not made for the bitmap.
*/
static BOOL DLL_CALLCONV
Validate(FreeImageIO &io, fi_handle handle) {
return FALSE;
}
/**
SupportsExportDepth is the first in a possible range of new plugin functions
to ask specific information to that plugin. This function returns TRUE if it
can save a bitmap in the required bitdepth. If it can't the bitmap has to be
converted by the user or another plugin has to be chosen.
*/
static BOOL DLL_CALLCONV
SupportsExportDepth(int depth) {
return FALSE;
}
/**
Returns TRUE if the plugin belonging to the given FREE_IMAGE_FORMAT can save a
bitmap in the desired data type, returns FALSE otherwise. Currently, TIFF is the only plugin
able to save all non-standard images. The PNG plugin is able to save unsigned 16-bit
images.
*/
static BOOL DLL_CALLCONV
SupportsExportType(FREE_IMAGE_TYPE type) {
return (type == FIT_BITMAP) ? TRUE : FALSE;
}
/**
SupportsICCProfiles informs FreeImage that a plugin supports ICC profiles.
This function returns TRUE if the plugin can load and save a profile.
ICC profile information is accessed via freeimage->get_icc_profile_proc(dib)
*/
static BOOL DLL_CALLCONV
SupportsICCProfiles() {
return FALSE;
}
// ----------------------------------------------------------
/**
Loads a bitmap into memory. On entry it is assumed that
the bitmap to be loaded is of the correct type. If the bitmap
is of an incorrect type, the plugin might not gracefully fail but
crash or enter an endless loop. It is also assumed that all
the bitmap data is available at one time. If the bitmap is not complete,
for example because it is being downloaded while loaded, the plugin
might also not gracefully fail.
The Load function has the following parameters:
The first parameter (FreeImageIO *io) is a structure providing
function pointers in order to make use of FreeImage's IO redirection. Using
FreeImage's file i/o functions instead of standard ones it is garantueed
that all bitmap types, both current and future ones, can be loaded from
memory, file cabinets, the internet and more. The second parameter (fi_handle handle)
is a companion of FreeImageIO and can be best compared with the standard FILE* type,
in a generalized form.
The third parameter (int page) indicates wether we will be loading a certain page
in the bitmap or if we will load the default one. This parameter is only used if
the plugin supports multi-paged bitmaps, e.g. cabinet bitmaps that contain a series
of images or pages. If the plugin does support multi-paging, the page parameter
can contain either a number higher or equal to 0 to load a certain page, or -1 to
load the default page. If the plugin does not support multi-paging,
the page parameter is always -1.
The fourth parameter (int flags) manipulates the load function to load a bitmap
in a certain way. Every plugin has a different flag parameter with different meanings.
The last parameter (void *data) can contain a special data block used when
the file is read multi-paged. Because not every plugin supports multi-paging
not every plugin will use the data parameter and it will be set to NULL.However,
when the plugin does support multi-paging the parameter contains a pointer to a
block of data allocated by the Open function.
*/
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
return NULL;
}
static BOOL DLL_CALLCONV
Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
return FALSE;
}
// ==========================================================
// Init
// ==========================================================
/**
Initialises the plugin. The first parameter (Plugin *plugin)
contains a pointer to a pre-allocated Plugin structure
wherein pointers to the available plugin functions
has to be stored. The second parameter (int format_id) is an identification
number that the plugin may use to show plugin specific warning messages
or other information to the user. The plugin number
is generated by FreeImage and can differ everytime the plugin is
initialised.
If you want to create your own plugin you have to take some
rules into account. Plugin functions have to be compiled
__stdcall using the multithreaded c runtime libraries. Throwing
exceptions in plugin functions is allowed, as long as those exceptions
are being caught inside the same plugin. It is forbidden for a plugin
function to directly call FreeImage functions or to allocate memory
and pass it to the main DLL. Exception to this rule is the special file data
block that may be allocated the Open function. Allocating a FIBITMAP inside a
plugin can be using the function allocate_proc in the FreeImage structure,
which will allocate the memory using the DLL's c runtime library.
*/
void DLL_CALLCONV
Init(Plugin *plugin, int format_id) {
s_format_id = format_id;
plugin->format_proc = Format;
plugin->description_proc = Description;
plugin->extension_proc = Extension;
plugin->regexpr_proc = RegExpr;
plugin->open_proc = NULL;
plugin->close_proc = NULL;
plugin->pagecount_proc = NULL;
plugin->pagecapability_proc = NULL;
plugin->load_proc = Load;
plugin->save_proc = Save;
plugin->validate_proc = Validate;
plugin->mime_proc = MimeType;
plugin->supports_export_bpp_proc = SupportsExportDepth;
plugin->supports_export_type_proc = SupportsExportType;
plugin->supports_icc_profiles_proc = SupportsICCProfiles;
}

View File

@@ -0,0 +1,45 @@
// ==========================================================
// JBIG Plugin
//
// Design and implementation by
// - Floris van den Berg (flvdberg@wxs.nl)
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================
#ifndef PLUGINCRADLE_H
#define PLUGINCRADLE_H
#ifdef PLUGINCRADLE_EXPORTS
#define PLUGIN_API __declspec(dllexport)
#else
#define PLUGIN_API __declspec(dllimport)
#endif
// ----------------------------------------------------------
struct Plugin;
// ----------------------------------------------------------
#define DLL_CALLCONV __stdcall
// ----------------------------------------------------------
extern "C" {
PLUGIN_API void DLL_CALLCONV Init(Plugin *plugin, int format_id);
}
#endif

View File

@@ -0,0 +1,236 @@
=====================================================================
Using the FreeImage library with the MinGW Compiler Suite
=====================================================================
This file describes how to use the precompiled FreeImage library
FreeImage.dll with the MinGW port of the GNU Compiler Collection
(GCC), how to build this library from source using MinGW and how
to use this MinGW-built library with Microsoft Visual Studio.
Contents:
I. Prerequisites
1. Using the precompiled FreeImage library with MinGW
2. Building the FreeImage library with MinGW
3. Using the MinGW FreeImage library with Microsoft Visual Studio
4. Useful links
---------------------------------------------------------------------
I. Prerequisites
=====================================================================
The procedures described in this document have been developed and
tested using the following free tools:
1. MinGW GCC Version 4.4.0 (Core and C++ including required libs)
2. MinGW GNU Binutils Version 2.19.1
3. MinGW GNU Make Version 3.81-20080326-3
4. MinGW Runtime Version 3.15.2
5. MinGW API for MS-Windows Version 3.13
6. GnuWin32 Package CoreUtils Version 5.3.0 (only for building)
7. GnuWin32 Package Sed Version 4.2 (only for creating the GCC
import library)*
* Sed is only needed to create a GCC-native import library from
the MSVC import library FreeImage.lib. However, since MinGW now
supports linking against MSVC lib files, this process seems to
be obsolete. See section 1.
Basically, no version dependent capabilities are used so, this
should also work with older versions of the tools mentioned above.
Similarly, the GnuWin32 packages (which I just prefer over MSYS)
could likely be replaced by a properly installed MSYS environment.
Furthermore, the following preconditions should be met:
1. The folders 'bin' under both the MinGW and the GnuWin32
installation directory should have been added to the PATH
environment variable. Likely it is best adding these
directories permanently to PATH through the System
Properties dialog on the Control Panel.
2. The MinGW Make package only provides a 'mingw32-make.exe'
executable. There is no alias 'make.exe'. However, make is
preconfigured to use 'make' as the default $(MAKE) command.
This seems to be a bug in the MinGW GNU Make distribution.
Thus, a copy of 'mingw32-make.exe' named 'make.exe' should
be placed into MinGW's 'bin' directory.
---------------------------------------------------------------------
1. Using the precompiled FreeImage library with MinGW
=====================================================================
When using functions from C/C++, that reside in a DLL, the linker
needs a so called import library, which specifies, how to
dynamically link these external functions during runtime. However,
different linkers use different types or formats of these import
libraries.
Since the precompiled FreeImage library was build with Microsoft
Visual Studio, in the past, some extra work was required to use it
from MinGW. An import library, that was compatible with GNU ld,
must have been created first.
However, for several MinGW versions, the GNU linker ld also
supports linking against Microsoft Visual C++ import libraries
directly. So, this effectively makes any circulating HOWTO's on
how to create a GCC-compatible import library from a MSVC lib file
more or less obsolete. Additionally, MinGW does not require the
GCC/Linux usual lib prefix for libraries, so linking with MinGW
against the precompiled FreeImage DLL is as easy as with MSVC:
1.) Open a DOS shell (run application cmd.exe)
2.) Ensure, that the 'bin' folder of MinGW is added to the PATH
environment variable (see Prerequisites).
3.) Link directly against the supplied lib file:
C:\>gcc -oFreeImageTest.exe FreeImageTest.c -lFreeImage
Nonetheless, for the sake of completeness, the following steps
describe how to create a native GCC import library:
1.) Open a DOS shell (run application cmd.exe)
2.) Ensure, that the 'bin' folders of both MinGW and GnuWin32 are
added to the PATH environment variable (see Prerequisites).
3.) Create a .def file 'libfreeimage.def', that contains all symbols
exported by the FreeImage library:
C:\>pexports FreeImage.dll | sed "s/^_//" > libfreeimage.def
4.) Create the GCC compatible import library 'libfreeimage.a':
C:\>dlltool --add-underscore -d libfreeimage.def -l libfreeimage.a
5.) Use this library to link against with GCC:
C:\>gcc -oFreeImageTest.exe FreeImageTest.c -lfreeimage
---------------------------------------------------------------------
2. Building the FreeImage library with MinGW
=====================================================================
You *do not* need to have any other third party library (like
libjpeg, libpng, libtiff, libmng and zlib and others) installed on
your system in order to compile and use the library. FreeImage uses
its own versions of these libraries. This way, you can be sure that
FreeImage will always use the latest and properly tested versions
of of these third party libraries.
In order to build the FreeImage library under Windows with MinGW
(GCC), ensure that all the prerequisites mentioned above are met.
The MinGW makefile aims to build a Windows DLL, that differs as
least as possible from the precompiled library that comes with the
FreeImage distribution. Thus, the build process also includes the
DLL version resource as well as the __stdcall attribute for all the
exported functions, including the MSVC-like function decorations
_FuncName@nn.
When building the FreeImage DLL, of course, an import library is
generated, too. However, this input library is not in GCC's native
format, but in MSVC lib format, which makes it usable from both
MinGW and Microsoft Visual Studio with no further processing.
The MinGW makefile can also be used to build a static library.
However, due to the different function export attributes needed
for both the dynamic and the shared library (DLL), this requires
a separate invocation of make, which in turn needs to rebuild every
source file after switching from dynamic to static and vice versa.
So, a 'make clean' is required each time, the library type is
changed.
The type of library to build is specified by a variable named
FREEIMAGE_LIBRARY_TYPE, which may either be set directly in the
Makefile.mingw near line 18 or may be specified as an environment
variable. This variable may either take SHARED or STATIC to build
a dynamic link library (DLL) or a static library respectively.
Since this value is used to dynamically form the actual make target
internally, only uppercase values are valid. Defaults to SHARED.
The MinGW makefile also supports the 'install' target. However,
this only copies the FreeImage dynamic link library (DLL) from the
Dist folder into the %SystemRoot%\system32 folder. So, invoking this
target only makes sense, if the DLL has been built before.
Since there is neither a common system wide 'include' nor a 'lib'
directory available under Windows, the FreeImage header file
FreeImage.h as well as both the static library and the DLL import
library FreeImage.lib just remain in the 'Dist' folder.
The following procedure creates the FreeImage dynamic link library
(DLL) from the sources, installs it and also creates a static
FreeImage library:
1.) Open a DOS shell (run application cmd.exe)
2.) Ensure, that the 'bin' folders of both MinGW and GnuWin32 are
added to the PATH environment variable (see Prerequisites).
3.) Create the FreeImage dynamic link library (DLL):
C:\>make
4.) Install the FreeImage dynamic link library (DLL):
C:\>make install
5.) Clean all files produced by the recent build process:
C:\>make clean
6.) Create a static FreeImage library:
C:\>set FREEIMAGE_LIBRARY_TYPE=STATIC
C:\>make
You should be able to link progams with the -lFreeImage option
after the shared library is compiled and installed. You can also
link statically against FreeImage.a from MinGW.
---------------------------------------------------------------------
3. Using the MinGW FreeImage library with Microsoft Visual Studio
=====================================================================
Since the MinGW makefile creates an import library in MSVC's lib
format, the produced shared library (DLL) can be used from both
MinGW and Microsoft Visual Studio with no further adaption. Just
link to the import library FreeImage.lib from either MinGW or
Microsoft Visual Studio.
---------------------------------------------------------------------
4. Useful links
=====================================================================
- The MinGW homepage:
http://www.mingw.org/
- The GnuWin32 homepage:
http://gnuwin32.sourceforge.net/
- The GCC homepage and online documentation:
http://gcc.gnu.org/
http://gcc.gnu.org/onlinedocs/
- The GNU Binutils homepage and online documentation:
http://www.gnu.org/software/binutils/
http://sourceware.org/binutils/docs-2.19/
- The GNU Make homepage and online documentation:
http://www.gnu.org/software/make/
http://www.gnu.org/software/make/manual/make.html

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,92 @@
What's New for FreeImage Delphi Wrapper
* : fixed
- : removed
! : changed
+ : added
July 29, 2010
+ [Lorenzo Monti] added Free Pascal / Lazarus 32 bit support
July 14, 2010
+ [Lorenzo Monti] updated wrapper for FreeImage 3.13.1
* [Lorenzo Monti] fixed declaration of FreeImageIO functions (FI_ReadProc, FI_WriteProc, FI_SeekProc, FI_TellProc)
! [Lorenzo Monti] renamed structure PluginStruct to Plugin, according to FreeImage.h
* [Lorenzo Monti] fixed declaration of JPEG_CMYK constant
* [Lorenzo Monti] fixed declaration of type FreeImage_OutputMessageFunction
* [Lorenzo Monti] fixed declaration of FreeImage_OutputMessageProc
+ [Lorenzo Monti] added wrapper for FreeImage_OutputMessageProc for older Delphi compilers (<6) not supporting varargs
* [Lorenzo Monti] fixed declaration of FreeImage_LookupX11Color and FreeImage_LookupSVGColor
! [Lorenzo Monti] changed declaration of FreeImage_GetPixelIndex, FreeImage_GetPixelColor, FreeImage_SetPixelIndex, FreeImage_SetPixelColor
! [Lorenzo Monti] changed declaration of FreeImage_GetInfo
! [Lorenzo Monti] changed declaration of FreeImage_GetICCProfile, FreeImage_CreateICCProfile, FreeImage_DestroyICCProfile
* [Lorenzo Monti] fixed declaration of FreeImage_SetComplexChannel
+ [Lorenzo Monti] added Delphi 2010 support
+ [Lorenzo Monti] added Version.inc to determine compiler version
! [Lorenzo Monti] moved all "external" definitions to implementation section
! [Lorenzo Monti] changed FreeBitmap.pas, FreeUtils.pas and TargaImage.pas to reflect changes in the FreeImage.pas unit
July 17, 2006
+ [Herv<72> Drolon] added FIF_FAXG3 and FIF_SGI definitions, added FreeImage_MakeThumbnail definition.
January 20, 2006
! [Anatoliy Pulyaevskiy] updated WinBitmap demo
* [Anatoliy Pulyaevskiy] fixed TFreeBitmap.ConvertToStandartType renamed to TFreeBitmap.ConvertToStandardType
* [Anatoliy Pulyaevskiy] fixed using of SetFreeImageMarker (only for HDR dib)
October 19, 2005
+ [Anatoliy Pulyaevskiy] updated wrapper for FreeImage 3.8.0
+ [Anatoliy Pulyaevskiy] added Delphi 5 support
+ [Anatoliy Pulyaevskiy] added TFreeBitmap.OnChanging event
! [Anatoliy Pulyaevskiy] changed declaration of TFreeBitmap.Assign method
+ [Anatoliy Pulyaevskiy] added TFreeBitmap.CanSave function
! [Anatoliy Pulyaevskiy] property TFreeBitmap.Dib now have read/write access
+ [Anatoliy Pulyaevskiy] added TFreeTag class incapsulating FreeImage FITAG type
August 5, 2005
* [kaare-nysite] fixed the prototype of FreeImage_ConvertFromRawBits
June 21, 2005
* [Maarten Veerman] fixed the prototype of FreeImage_OpenMultiBitmap
February 17, 2005 - Version 1.3.0
+ [Anatoliy Pulyaevskiy] updated the wrapper for FreeImage 3.6.0
! [Anatoliy Pulyaevskiy] FreeImage.pas unit has been reworked
January 14, 2005 - Version 1.2.1
+ [Anatoliy Pulyaevskiy] updated the wrapper for FreeImage 3.5.3
+ [Anatoliy Pulyaevskiy] added TFreeBitmap.SetHorizontalResolution and TFreeBitmap.SetVerticalResolution
+ [Anatoliy Pulyaevskiy] added TFreeBitmap.MakeThumbnail procedure ( an adapted version of function given by Enzo Costantini)
+ [Enzo Costantini] added FIU_GetFIFType utility function
+ [Enzo Costantini] added TFreeWinBitmap.CopyToBitmapH function
* [Anatoliy Pulyaevskiy] fixed TFreeBitmap.Rotate (fix from FreeImage CVS)
+ [Anatoliy Pulyaevskiy] added TFreeBitmap.ConvertToStandartType
December 20, 2004 - Version 1.2.0
+ [Anatoliy Pulyaevskiy] added MultiBitmap Demo
* [Anatoliy Pulyaevskiy] fixed TFreeMultiBitmap.LockPage due to error with Locking/Unlocking pages
+ [Anatoliy Pulyaevskiy] added TFreeBitmap.ConvertTo4Bits
* [Anatoliy Pulyaevskiy] TFreeBitmap.ConvertToGrayScale fixed converting bitmaps with FIC_MINISWHITE color type
* [Anatoliy Pulyaevskiy] fixed TFreeWinBitmap.DrawEx FDisplayDib deleting
+ [Anatoliy Pulyaevskiy] updated the wrapper for FreeImage 3.5.2
November 12, 2004 - Version 1.1.0
+ [Anatoliy Pulyaevskiy] added TFreeBitmap.Assign(Source: PFIBITMAP)
- [Anatoliy Pulyaevskiy] removed TFreeBitmap.SetDib
! [Anatoliy Pulyaevskiy] TFreeBitmap.Dib property now read-only
* [Anatoliy Pulyaevskiy] TFreeMultiBitmap.UnlockPage implemented
* [Anatoliy Pulyaevskiy] fixed TFreeBitmap.Rescale not applies changes
November 8, 2004 - Version 1.0.0
+ [Anatoliy Pulyaevskiy] added Delphi version of FreeImagePlus
+ [Anatoliy Pulyaevskiy] updated the wrapper for FreeImage 3.5.0
January 7, 2004
+ [Tommy] added TargaImage unit
October 28, 2003
+ [Peter Bystr<74>m] updated the wrapper for FreeImage 3.0.2
August 9, 2003
+ [Simon Beavis] added a wrapper for FreeImage 2.6.1

View File

@@ -0,0 +1,13 @@
del /S *.~*
del /S *.dcu
del /S *.dsk
del /S *.cfg
del /S *.dof
del /S *.obj
del /S *.hpp
del /S *.ddp
del /S *.mps
del /S *.mpt
del /S *.bak
del /S *.exe
del /S *.stat

View File

@@ -0,0 +1,13 @@
program ImagePreview;
uses
Forms,
MainFrm in 'MainFrm.pas' {MainForm};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.

View File

@@ -0,0 +1,135 @@
object MainForm: TMainForm
Left = 304
Top = 165
Width = 467
Height = 405
Caption = 'Image Preview'
Color = clWhite
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
KeyPreview = True
OldCreateOrder = False
Position = poDesktopCenter
OnCreate = FormCreate
OnDestroy = FormDestroy
OnKeyUp = FormKeyUp
OnMouseWheel = ScrollBoxMouseWheel
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object ImgView32: TImgView32
Left = 0
Top = 0
Width = 459
Height = 371
Align = alClient
ParentShowHint = False
PopupMenu = PopupMenu
Scale = 1
ScrollBars.Color = clScrollBar
ScrollBars.ShowHandleGrip = True
ScrollBars.Style = rbsDefault
ShowHint = True
SizeGrip = sgAuto
TabOrder = 0
OnScroll = ImgView32Scroll
object AlphaView: TImgView32
Left = 8
Top = 8
Width = 161
Height = 145
Scale = 1
ScrollBars.Color = clScrollBar
ScrollBars.ShowHandleGrip = True
ScrollBars.Style = rbsDefault
SizeGrip = sgAuto
TabOrder = 2
Visible = False
end
end
object PopupMenu: TPopupMenu
Left = 304
Top = 28
object ZoomInItem: TMenuItem
Caption = 'Zoom In'
OnClick = ZoomInItemClick
end
object ZoomOutItem: TMenuItem
Caption = 'Zoom Out'
OnClick = ZoomOutItemClick
end
object ActualSizeItem: TMenuItem
Caption = 'Actual Size'
OnClick = ActualSizeItemClick
end
object N1: TMenuItem
Caption = '-'
end
object RotateClockwiseItem: TMenuItem
Caption = 'Rotate Clockwise'
OnClick = RotateClockwiseItemClick
end
object RotateAntiClockwiseItem: TMenuItem
Caption = 'Rotate Anti-Clockwise'
OnClick = RotateAntiClockwiseItemClick
end
object N4: TMenuItem
Caption = '-'
end
object FlipHorizontalItem: TMenuItem
Caption = 'Flip Horizontal'
OnClick = FlipHorizontalItemClick
end
object FilpVerticalItem: TMenuItem
Caption = 'Filp Vertical'
OnClick = FilpVerticalItemClick
end
object N3: TMenuItem
Caption = '-'
end
object ShowAlphaItem: TMenuItem
Caption = 'Show Just Alpha Channel'
OnClick = ShowAlphaItemClick
end
object ShowWithAlphaItem: TMenuItem
Caption = 'Show With Alpha Channel'
OnClick = ShowWithAlphaItemClick
end
object N2: TMenuItem
Caption = '-'
end
object OpenImageItem: TMenuItem
Caption = 'Open New Image'
OnClick = OpenImageItemClick
end
end
object FilterTimer: TTimer
Interval = 500
OnTimer = FilterTimerTimer
Left = 308
Top = 84
end
object OpenDialog: TOpenDialog
Filter =
'All image files|*.bmp;*.cut;*.ico;*.iff;*.lbm;*.jng;*.jpg;*.jpeg' +
';*.koa;*.mng;*.pbm;*.pcd;*.pcx;*.pgm;*.png;*.ppm;*.psd;*.ras;*.t' +
'ga;*.tif;*.tiff;.wbmp;*.xbm;*.xpm)|Windows or OS/2 Bitmap File (' +
'*.BMP)|*.BMP|Dr. Halo (*.CUT)|*.CUT|Windows Icon (*.ICO)|*.ICO|A' +
'miga IFF (*.IFF, *.LBM)|*.IFF;*.LBM|JPEG Network Graphics (*.JNG' +
')|*.JNG|Independent JPEG Group (*.JPG)|*.JPG|Commodore 64 Koala ' +
'(*.KOA)|*.KOA|Multiple Network Graphics (*.MNG)|*.MNG|Portable B' +
'itmap (*.PBM)|*.PBM|Kodak PhotoCD (*.PCD)|*.PCD|PCX bitmap forma' +
't (*.PCX)|*.PCX|Portable Graymap (*.PGM)|*.PGM|Portable Network ' +
'Graphics (*.PNG)|*.PNG|Portable Pixelmap (*.PPM)|*.PPM|Photoshop' +
' (*.PSD)|*.PSD|Sun Rasterfile (*.RAS)|*.RAS|Targa files (*.TGA)|' +
'*.TGA|Tagged Image File Format (*.TIF)|*.TIF;*.TIFF|Wireless Bit' +
'map (*.WBMP)|*.WBMP|X11 Bitmap Format (*.XBM)|*.XBM|X11 Pixmap F' +
'ormat (*.XPM)|*.XPM'
Title = 'Open Image File'
Left = 328
Top = 228
end
end

View File

@@ -0,0 +1,518 @@
unit MainFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls, Math, GR32, GR32_Image, GR32_Transforms,
ExtDlgs;
type
TMainForm = class(TForm)
PopupMenu: TPopupMenu;
ZoomInItem: TMenuItem;
ZoomOutItem: TMenuItem;
ActualSizeItem: TMenuItem;
ImgView32: TImgView32;
N1: TMenuItem;
AlphaView: TImgView32;
ShowAlphaItem: TMenuItem;
RotateClockwiseItem: TMenuItem;
RotateAntiClockwiseItem: TMenuItem;
N3: TMenuItem;
ShowWithAlphaItem: TMenuItem;
N4: TMenuItem;
FlipHorizontalItem: TMenuItem;
FilpVerticalItem: TMenuItem;
FilterTimer: TTimer;
OpenImageItem: TMenuItem;
N2: TMenuItem;
OpenDialog: TOpenDialog;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ZoomInItemClick(Sender: TObject);
procedure ZoomOutItemClick(Sender: TObject);
procedure ActualSizeItemClick(Sender: TObject);
procedure ScrollBoxMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
procedure FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure ShowAlphaItemClick(Sender: TObject);
procedure RotateClockwiseItemClick(Sender: TObject);
procedure RotateAntiClockwiseItemClick(Sender: TObject);
procedure ShowWithAlphaItemClick(Sender: TObject);
procedure FlipHorizontalItemClick(Sender: TObject);
procedure FilpVerticalItemClick(Sender: TObject);
procedure FilterTimerTimer(Sender: TObject);
procedure ImgView32Scroll(Sender: TObject);
procedure OpenImageItemClick(Sender: TObject);
private
{ Private declarations }
OrigWidth : integer;
OrigHeight : integer;
BPP : longword;
procedure LoadImage( Name : string);
procedure RecalcWindowSize;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
uses FreeImage;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
procedure TMainForm.FormCreate(Sender: TObject);
begin
AlphaView.Visible := False;
AlphaView.Align := alClient;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.FormDestroy(Sender: TObject);
begin
// ...
end;
// -----------------------------------------------------------------------------
procedure TMainForm.FormShow(Sender: TObject);
begin
ImgView32.Bitmap.StretchFilter := sfSPline;
if ParamCount = 1 then
LoadImage(ParamStr(1));
end;
// -----------------------------------------------------------------------------
procedure TMainForm.LoadImage( Name : string);
var
dib : PFIBITMAP;
PBH : PBITMAPINFOHEADER;
PBI : PBITMAPINFO;
t : FREE_IMAGE_FORMAT;
Ext : string;
BM : TBitmap;
x, y : integer;
BP : PLONGWORD;
DC : HDC;
begin
try
t := FreeImage_GetFileType(PChar(Name), 16);
if t = FIF_UNKNOWN then
begin
// Check for types not supported by GetFileType
Ext := UpperCase(ExtractFileExt(Name));
if (Ext = '.TGA') or(Ext = '.TARGA') then
t := FIF_TARGA
else if Ext = '.MNG' then
t := FIF_MNG
else if Ext = '.PCD' then
t := FIF_PCD
else if Ext = '.WBMP' then
t := FIF_WBMP
else if Ext = '.CUT' then
t := FIF_CUT
else
raise Exception.Create('The file "' + Name + '" cannot be displayed because SFM does not recognise the file type.');
end;
dib := FreeImage_Load(t, PChar(name), 0);
if Dib = nil then
Close;
PBH := FreeImage_GetInfoHeader(dib);
PBI := FreeImage_GetInfo(dib^);
BPP := FreeImage_GetBPP(dib);
ShowWithAlphaItem.Enabled := BPP = 32;
ShowAlphaItem.Enabled := BPP = 32;
if BPP = 32 then
begin
ImgView32.Bitmap.SetSize(FreeImage_GetWidth(dib), FreeImage_GetHeight(dib));
BP := PLONGWORD(FreeImage_GetBits(dib));
for y := ImgView32.Bitmap.Height - 1 downto 0 do
for x := 0 to ImgView32.Bitmap.Width - 1 do
begin
ImgView32.Bitmap.Pixel[x, y] := BP^;
inc(BP);
end;
end
else
begin
BM := TBitmap.Create;
BM.Assign(nil);
DC := GetDC(Handle);
BM.handle := CreateDIBitmap(DC,
PBH^,
CBM_INIT,
PChar(FreeImage_GetBits(dib)),
PBI^,
DIB_RGB_COLORS);
ImgView32.Bitmap.Assign(BM);
AlphaView.Bitmap.Assign(BM);
BM.Free;
ReleaseDC(Handle, DC);
end;
FreeImage_Unload(dib);
OrigWidth := ImgView32.Bitmap.Width;
OrigHeight := ImgView32.Bitmap.Height;
Caption := ExtractFileName( Name ) + ' (' + IntToStr(OrigWidth) +
' x ' + IntToStr(OrigHeight) + ')';
if BPP = 32 then
Caption := Caption + ' + Alpha';
AlphaView.Bitmap.SetSize(OrigWidth, OrigWidth);
ImgView32.Hint := 'Name: ' + Name + #13 +
'Width: ' + IntToStr(OrigWidth) + #13 +
'Height: ' + IntToStr(OrigHeight) + #13 +
'BPP: ' + IntToStr(BPP);
RecalcWindowSize;
Show;
except
on e:exception do
begin
Application.BringToFront;
MessageDlg(e.message, mtInformation, [mbOK], 0);
Close;
end;
end;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.ZoomInItemClick(Sender: TObject);
begin
FilterTimer.Enabled := False;
if ImgView32.Bitmap.StretchFilter <> sfNearest then
ImgView32.Bitmap.StretchFilter := sfNearest;
FilterTimer.Enabled := True;
ImgView32.Scale := ImgView32.Scale * 2.0;
RecalcWindowSize;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.ZoomOutItemClick(Sender: TObject);
begin
FilterTimer.Enabled := False;
if ImgView32.Bitmap.StretchFilter <> sfNearest then
ImgView32.Bitmap.StretchFilter := sfNearest;
FilterTimer.Enabled := True;
ImgView32.Scale := ImgView32.Scale / 2.0;
RecalcWindowSize;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.ActualSizeItemClick(Sender: TObject);
begin
FilterTimer.Enabled := False;
if ImgView32.Bitmap.StretchFilter <> sfNearest then
ImgView32.Bitmap.StretchFilter := sfNearest;
FilterTimer.Enabled := True;
ImgView32.Scale := 1.0;
RecalcWindowSize;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.RecalcWindowSize;
var
Rect : TRect;
CW, CH : integer;
WSH, WSW : integer;
TitleH : integer;
BorderY : integer;
BorderX : integer;
begin
CW := ImgView32.Bitmap.Width + GetSystemMetrics(SM_CXVSCROLL);
CH := ImgView32.Bitmap.Height + GetSystemMetrics(SM_CYVSCROLL);
SystemParametersInfo( SPI_GETWORKAREA, 0, @Rect, 0);
WSH := Rect.Bottom - Rect.Top;
WSW := Rect.Right - Rect.Left;
TitleH := GetSystemMetrics(SM_CYCAPTION);
BorderY := GetSystemMetrics(SM_CYSIZEFRAME) * 2;
BorderX := GetSystemMetrics(SM_CXSIZEFRAME) * 2;
if (Top + CH + TitleH + BorderY > WSH) or (CH + TitleH + BorderY > WSH) then
begin
Top := Rect.Bottom - CH - BorderY;
if Top < 0 then
begin
Top := 0;
CH := WSH - TitleH - BorderY;
CW := CW + GetSystemMetrics(SM_CXVSCROLL);
if CW + BorderX > WSW then
CH := CH - GetSystemMetrics(SM_CYVSCROLL);
end;
end;
if (Left + CW + BorderX > WSW) or (CW + BorderX > WSW) then
begin
Left := Rect.Right - CW - BorderX;
if Left < 0 then
begin
Left := 0;
CW := WSW - BorderX;
CH := CH + GetSystemMetrics(SM_CYVSCROLL);
if CH + TitleH + BorderY > WSH then
CW := CW + GetSystemMetrics(SM_CXVSCROLL);
end
end;
ClientWidth := CW;
ClientHeight := CH;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.ScrollBoxMouseWheel(Sender: TObject;
Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
var Handled: Boolean);
begin
FilterTimer.Enabled := False;
if ImgView32.Bitmap.StretchFilter <> sfNearest then
ImgView32.Bitmap.StretchFilter := sfNearest;
FilterTimer.Enabled := True;
if WheelDelta < 0 then
ImgView32.Scroll(0, 20)
else
ImgView32.Scroll(0, -20);
Handled := True;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
Amount : integer;
begin
FilterTimer.Enabled := False;
if ImgView32.Bitmap.StretchFilter <> sfNearest then
ImgView32.Bitmap.StretchFilter := sfNearest;
FilterTimer.Enabled := True;
if ssShift in Shift then
Amount := 20 * 2
else
Amount := 20;
case Key of
VK_ESCAPE:
Close;
VK_UP:
ImgView32.Scroll(0, -Amount);
VK_DOWN:
ImgView32.Scroll(0, Amount);
VK_LEFT:
ImgView32.Scroll(-Amount, 0);
VK_RIGHT:
ImgView32.Scroll(Amount, 0);
VK_HOME:
ImgView32.ScrollToCenter(0, 0);
VK_END:
ImgView32.ScrollToCenter(ImgView32.Bitmap.Width, ImgView32.Bitmap.Height);
VK_NEXT:
ImgView32.Scroll(0, (Trunc(ImgView32.Bitmap.Height div 4)));
VK_PRIOR:
ImgView32.Scroll(0, -(Trunc(ImgView32.Bitmap.Height div 4)));
end;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.ShowAlphaItemClick(Sender: TObject);
var
x, y : integer;
Col : TColor32;
Alpha : TColor;
begin
if ShowAlphaItem.Checked then
begin
AlphaView.Visible := False;
AlphaView.Bitmap.Delete;
end
else
begin
AlphaView.Bitmap.Width := ImgView32.Bitmap.Width;
AlphaView.Bitmap.Height := ImgView32.Bitmap.Height;
for x := 0 to AlphaView.Bitmap.Width - 1 do
for y := 0 to AlphaView.Bitmap.Height - 1 do
begin
Col := ImgView32.Bitmap.Pixel[x, y];
Alpha := Col shr 24;
AlphaView.Bitmap.Pixel[x, y] := Alpha + (Alpha shl 8) + (Alpha shl 16);
end;
AlphaView.Visible := True;
end;
ShowAlphaItem.Checked := not ShowAlphaItem.Checked;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.RotateClockwiseItemClick(Sender: TObject);
var
x : integer;
y : integer;
DestX : integer;
DestY : integer;
C : TColor32;
begin
AlphaView.Bitmap.Assign(ImgView32.Bitmap);
ImgView32.BeginUpdate;
ImgView32.Bitmap.Width := AlphaView.Bitmap.Height;
ImgView32.Bitmap.Height := AlphaView.Bitmap.Width;
for x := 0 to AlphaView.Bitmap.Width - 1 do
for y := 0 to AlphaView.Bitmap.Height - 1 do
begin
C := AlphaView.Bitmap.Pixel[x, y];
DestX := (ImgView32.Bitmap.Width - 1) - Y;
DestY := X;
ImgView32.Bitmap.Pixels[DestX, DestY] := C;
end;
ImgView32.EndUpdate;
ImgView32.Refresh;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.RotateAntiClockwiseItemClick(Sender: TObject);
var
x : integer;
y : integer;
DestX : integer;
DestY : integer;
C : TColor32;
begin
AlphaView.Bitmap.Assign(ImgView32.Bitmap);
ImgView32.BeginUpdate;
ImgView32.Bitmap.Width := AlphaView.Bitmap.Height;
ImgView32.Bitmap.Height := AlphaView.Bitmap.Width;
for x := 0 to AlphaView.Bitmap.Width - 1 do
for y := 0 to AlphaView.Bitmap.Height - 1 do
begin
C := AlphaView.Bitmap.Pixel[x, y];
DestX := Y;
DestY := (ImgView32.Bitmap.Height - 1) -X;
ImgView32.Bitmap.Pixels[DestX, DestY] := C;
end;
ImgView32.EndUpdate;
ImgView32.Refresh;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.ShowWithAlphaItemClick(Sender: TObject);
begin
if ShowWithAlphaItem.Checked then
ImgView32.Bitmap.DrawMode := dmOpaque
else
ImgView32.Bitmap.DrawMode := dmBlend;
ShowWithAlphaItem.Checked := not ShowWithAlphaItem.Checked;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.FlipHorizontalItemClick(Sender: TObject);
var
x : integer;
y : integer;
DestX : integer;
DestY : integer;
C : TColor32;
begin
AlphaView.Bitmap.Assign(ImgView32.Bitmap);
ImgView32.BeginUpdate;
ImgView32.Bitmap.Width := AlphaView.Bitmap.Width;
ImgView32.Bitmap.Height := AlphaView.Bitmap.Height;
for x := 0 to AlphaView.Bitmap.Width - 1 do
for y := 0 to AlphaView.Bitmap.Height - 1 do
begin
C := AlphaView.Bitmap.Pixel[x, y];
DestX := (ImgView32.Bitmap.Width - 1) -X;
DestY := Y;
ImgView32.Bitmap.Pixels[DestX, DestY] := C;
end;
ImgView32.EndUpdate;
ImgView32.Refresh;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.FilpVerticalItemClick(Sender: TObject);
var
x : integer;
y : integer;
DestX : integer;
DestY : integer;
C : TColor32;
begin
AlphaView.Bitmap.Assign(ImgView32.Bitmap);
ImgView32.BeginUpdate;
ImgView32.Bitmap.Width := AlphaView.Bitmap.Width;
ImgView32.Bitmap.Height := AlphaView.Bitmap.Height;
for x := 0 to AlphaView.Bitmap.Width - 1 do
for y := 0 to AlphaView.Bitmap.Height - 1 do
begin
C := AlphaView.Bitmap.Pixel[x, y];
DestX := X;
DestY := (ImgView32.Bitmap.Height - 1) - Y;
ImgView32.Bitmap.Pixels[DestX, DestY] := C;
end;
ImgView32.EndUpdate;
ImgView32.Refresh;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.FilterTimerTimer(Sender: TObject);
begin
FilterTimer.Enabled := False;
ImgView32.Bitmap.StretchFilter := sfSPline;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.ImgView32Scroll(Sender: TObject);
begin
FilterTimer.Enabled := False;
if ImgView32.Bitmap.StretchFilter <> sfNearest then
ImgView32.Bitmap.StretchFilter := sfNearest;
FilterTimer.Enabled := True;
end;
// -----------------------------------------------------------------------------
procedure TMainForm.OpenImageItemClick(Sender: TObject);
begin
if OpenDialog.Execute then
begin
try
Screen.Cursor := crHourGlass;
LoadImage(OpenDialog.FileName);
finally
Screen.Cursor := crDefault;
end;
end;
end;
end.

View File

@@ -0,0 +1,8 @@
This is a simple image viewing application that uses the FreeImage library to display images in many different formats.
The app displays the image whose name is passed in as a command line argument.
To compile the app you will also need the Graphics32 library available from www.g32.org. It has been tested with version 1.5.1 of Graphics32.
SJB.

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

View File

@@ -0,0 +1,13 @@
program MultiBitmap;
uses
Forms,
mbMainForm in 'mbMainForm.pas' {MainForm};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.

View File

@@ -0,0 +1,10 @@
[Stats]
EditorSecs=82
DesignerSecs=5
InspectorSecs=1
CompileSecs=850
OtherSecs=5
StartTime=20.12.2004 11:40:22
RealKeys=0
EffectiveKeys=0
DebugSecs=19

View File

@@ -0,0 +1,89 @@
object MainForm: TMainForm
Left = 203
Top = 192
Width = 696
Height = 480
Caption = 'MultiBitmap Demo'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Shell Dlg 2'
Font.Style = []
OldCreateOrder = False
OnPaint = FormPaint
OnResize = FormResize
PixelsPerInch = 96
TextHeight = 13
object ToolBar: TToolBar
Left = 0
Top = 0
Width = 688
Height = 25
AutoSize = True
ButtonHeight = 21
ButtonWidth = 33
Caption = 'ToolBar'
EdgeBorders = [ebLeft, ebTop, ebRight, ebBottom]
Flat = True
Indent = 3
ShowCaptions = True
TabOrder = 0
object tbLoad: TToolButton
Left = 3
Top = 0
Caption = 'Load'
ImageIndex = 0
OnClick = tbLoadClick
end
object ToolButton1: TToolButton
Left = 36
Top = 0
Width = 8
Caption = 'ToolButton1'
ImageIndex = 1
Style = tbsSeparator
end
object tbClose: TToolButton
Left = 44
Top = 0
Caption = 'Close'
ImageIndex = 1
OnClick = tbCloseClick
end
object ToolButton2: TToolButton
Left = 77
Top = 0
Width = 8
Caption = 'ToolButton2'
ImageIndex = 2
Style = tbsSeparator
end
object Label1: TLabel
Left = 85
Top = 0
Width = 36
Height = 21
Caption = 'Pages: '
Layout = tlCenter
end
object cbPages: TComboBox
Left = 121
Top = 0
Width = 60
Height = 21
Style = csDropDownList
DropDownCount = 15
ItemHeight = 13
TabOrder = 0
OnChange = cbPagesChange
end
end
object OD: TOpenDialog
Filter = 'TIFF multibitmap (*.tiff, *.tif)|*.tiff; *.tif|ICO|*.ico'
Options = [ofHideReadOnly, ofPathMustExist, ofFileMustExist, ofEnableSizing]
Title = 'Open multibitmap..'
Left = 64
Top = 96
end
end

View File

@@ -0,0 +1,150 @@
unit mbMainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ToolWin, StdCtrls, FreeBitmap;
type
TMainForm = class(TForm)
ToolBar: TToolBar;
tbLoad: TToolButton;
ToolButton1: TToolButton;
tbClose: TToolButton;
ToolButton2: TToolButton;
cbPages: TComboBox;
Label1: TLabel;
OD: TOpenDialog;
procedure tbLoadClick(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure tbCloseClick(Sender: TObject);
procedure cbPagesChange(Sender: TObject);
procedure FormResize(Sender: TObject);
private
FMultiBitmap: TFreeMultiBitmap;
FPage: TFreeWinBitmap;
procedure PageBitmapChangeHandler(Sender: TObject);
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure OpenMultiBitmap(const FileName: string);
procedure CloseMultiBitmap;
procedure OpenPage(Number: Integer);
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
{ TMainForm }
procedure TMainForm.CloseMultiBitmap;
begin
if FPage.IsValid then
FMultiBitmap.UnlockPage(Fpage, False);
FMultiBitmap.Close;
cbPages.Clear;
end;
constructor TMainForm.Create(AOwner: TComponent);
begin
inherited;
FMultiBitmap := TFreeMultiBitmap.Create;
FPage := TFreeWinBitmap.Create;
FPage.OnChange := PageBitmapChangeHandler;
end;
destructor TMainForm.Destroy;
begin
if FMultiBitmap.IsValid then
CloseMultiBitmap;
FMultiBitmap.Free;
inherited;
end;
procedure TMainForm.OpenMultiBitmap(const FileName: string);
var
I, Cnt: Integer;
begin
if FMultiBitmap.IsValid then CloseMultiBitmap;
FMultiBitmap.Open(FileName, False, True);
Cnt := FMultiBitmap.GetPageCount;
cbPages.OnChange := nil;
cbPages.Clear;
for I := 0 to Cnt - 1 do
cbPages.Items.Add(IntToStr(I));
cbPages.OnChange := cbPagesChange;
end;
procedure TMainForm.OpenPage(Number: Integer);
begin
if not FMultiBitmap.IsValid then Exit;
if FPage.IsValid then
FMultiBitmap.UnlockPage(FPage, False);
FMultiBitmap.LockPage(Number, FPage);
end;
procedure TMainForm.PageBitmapChangeHandler(Sender: TObject);
begin
Invalidate;
end;
procedure TMainForm.tbLoadClick(Sender: TObject);
begin
if OD.Execute then
begin
try
OpenMultiBitmap(OD.FileName);
except
raise Exception.CreateFmt('Can not load file %s', [OD.FileName]);
end;
end;
end;
procedure TMainForm.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
Message.Result := 1;
end;
procedure TMainForm.FormPaint(Sender: TObject);
begin
if not FPage.IsValid then
begin
Canvas.Brush.Color := clBtnFace;
Canvas.FillRect(ClientRect);
end
else
FPage.Draw(Canvas.Handle, ClientRect);
end;
procedure TMainForm.tbCloseClick(Sender: TObject);
begin
if FMultiBitmap.IsValid then
CloseMultiBitmap;
end;
procedure TMainForm.cbPagesChange(Sender: TObject);
var
Page: Integer;
begin
Page := StrToInt(cbPages.Text);
OpenPage(Page);
end;
procedure TMainForm.FormResize(Sender: TObject);
begin
Invalidate;
end;
end.

View File

@@ -0,0 +1,22 @@
TargaImage.pas is a TGraphic descendant for Delphi. Installing it
will allow Delphi TImage and TDBImage components to read Targa files
just like BMP & WMF files with no coding on your part.
It also adds the TGA file type to the Delphi Open/Save Picture dialog
boxes.
To install this unit, place it in your one of your library folders
and make it available to all your Delphi projects by using
Component>Install Component from the Delphi menus.
NOTE: any Delphi applications using this *must* have FreeImage.dll
installed in your application's folder, or somewhere in the path.
-----------------------
Tommy
Edinburgh, Scotland
LeTene@battlefieldeurope.org

View File

@@ -0,0 +1,212 @@
unit TargaImage;
// ==========================================================
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
//
// ==========================================================
interface
uses
Windows,
Classes,
FreeImage,
Graphics,
Types;
type
TTargaImage = class(TGraphic)
private
fImage: PFIBITMAP;
fWidth: Integer;
fHeight: Integer;
protected
procedure Draw(ACanvas: TCanvas; const ARect: TRect); override;
function GetEmpty: Boolean; override;
function GetHeight: Integer; override;
function GetWidth: Integer; override;
procedure SetHeight(Value: Integer); override;
procedure SetWidth(Value: Integer); override;
public
constructor Create; override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure LoadFromClipboardFormat(AFormat: Word; AData: THandle; APalette: HPALETTE); override;
procedure LoadFromStream(Stream: TStream); override;
procedure SaveToClipboardFormat(var AFormat: Word; var AData: THandle; var APalette: HPALETTE); override;
procedure SaveToStream(Stream: TStream); override;
end;
procedure Register;
implementation
{ Design-time registration }
procedure Register;
begin
TPicture.RegisterFileFormat('tga', 'TARGA Files', TTargaImage);
end;
{ IO functions }
function FI_ReadProc(buffer : pointer; size : Cardinal; count : Cardinal; handle : fi_handle) : UInt; stdcall;
var
stream: TStream;
bytesToRead: Cardinal;
begin
stream := TStream(handle);
bytesToRead := size*count;
Result := stream.Read(buffer^, bytesToRead);
end;
function FI_WriteProc(buffer : pointer; size, count : Cardinal; handle : fi_handle) : UInt; stdcall;
var
stream: TStream;
bytesToWrite: Cardinal;
begin
stream := TStream(handle);
bytesToWrite := size*count;
Result := stream.Write(buffer^, bytesToWrite);
end;
function FI_SeekProc(handle : fi_handle; offset : longint; origin : integer) : Integer; stdcall;
begin
TStream(handle).Seek(offset, origin);
Result := 0;
end;
function FI_TellProc(handle : fi_handle) : LongInt; stdcall;
begin
Result := TStream(handle).Position;
end;
{ TTargaImage }
constructor TTargaImage.Create;
begin
fImage := nil;
fWidth := 0;
fHeight := 0;
inherited;
end;
destructor TTargaImage.Destroy;
begin
if Assigned(fImage) then
FreeImage_Unload(fImage);
inherited;
end;
procedure TTargaImage.Assign(Source: TPersistent);
begin
if Source is TTargaImage then begin
fImage := FreeImage_Clone(TTargaImage(Source).fImage);
fWidth := FreeImage_GetWidth(fImage);
fHeight := FreeImage_GetHeight(fImage);
Changed(Self);
end else
inherited;
end;
procedure TTargaImage.Draw(ACanvas: TCanvas; const ARect: TRect);
var
pbi: PBitmapInfo;
begin
if Assigned(fImage) then begin
pbi := FreeImage_GetInfo(fImage);
SetStretchBltMode(ACanvas.Handle, COLORONCOLOR);
StretchDIBits(ACanvas.Handle, ARect.left, ARect.top,
ARect.right-ARect.left, ARect.bottom-ARect.top,
0, 0, fWidth, fHeight,
FreeImage_GetBits(fImage), pbi^, DIB_RGB_COLORS, SRCCOPY);
end;
end;
function TTargaImage.GetEmpty: Boolean;
begin
Result := Assigned(fImage);
end;
function TTargaImage.GetHeight: Integer;
begin
Result := fHeight;
end;
function TTargaImage.GetWidth: Integer;
begin
Result := fWidth;
end;
procedure TTargaImage.LoadFromClipboardFormat(AFormat: Word; AData: THandle; APalette: HPALETTE);
begin
if Assigned(fImage) then begin
end;
end;
procedure TTargaImage.LoadFromStream(Stream: TStream);
var
io: FreeImageIO;
begin
with io do begin
read_proc := FI_ReadProc;
write_proc := FI_WriteProc;
seek_proc := FI_SeekProc;
tell_proc := FI_TellProc;
end;
fImage := FreeImage_LoadFromHandle(FIF_TARGA, @io, Stream);
if Assigned(fImage) then begin
fWidth := FreeImage_GetWidth(fImage);
fHeight := FreeImage_GetHeight(fImage);
end;
end;
procedure TTargaImage.SaveToClipboardFormat(var AFormat: Word; var AData: THandle; var APalette: HPALETTE);
begin
end;
procedure TTargaImage.SaveToStream(Stream: TStream);
var
io: FreeImageIO;
begin
with io do begin
read_proc := FI_ReadProc;
write_proc := FI_WriteProc;
seek_proc := FI_SeekProc;
tell_proc := FI_TellProc;
end;
FreeImage_SaveToHandle(FIF_TARGA, fImage, @io, Stream);
end;
procedure TTargaImage.SetHeight(Value: Integer);
begin
if Assigned(fImage) then begin
fHeight := Value;
FreeImage_Rescale(fImage, fWidth, fHeight, FILTER_BICUBIC);
end;
end;
procedure TTargaImage.SetWidth(Value: Integer);
begin
if Assigned(fImage) then begin
fWidth := Value;
FreeImage_Rescale(fImage, fWidth, fHeight, FILTER_BICUBIC);
end;
end;
initialization
TPicture.RegisterFileFormat('tga', 'TARGA Files', TTargaImage);
end.

View File

@@ -0,0 +1,13 @@
program MainDemo;
uses
Forms,
MainForm in 'MainForm.pas' {fwbMainForm};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TfwbMainForm, fwbMainForm);
Application.Run;
end.

View File

@@ -0,0 +1,607 @@
object fwbMainForm: TfwbMainForm
Left = 205
Top = 206
Width = 696
Height = 480
Caption = 'FreeWinBitmap - MainDemo'
Color = clCaptionText
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
Menu = MainMenu
OldCreateOrder = False
ShowHint = True
OnCreate = FormCreate
OnDestroy = FormDestroy
OnPaint = FormPaint
OnResize = FormResize
PixelsPerInch = 96
TextHeight = 13
object StatusBar: TStatusBar
Left = 0
Top = 411
Width = 688
Height = 23
Panels = <
item
Alignment = taCenter
Width = 120
end
item
Alignment = taCenter
Width = 80
end
item
Width = 50
end>
end
object tbTools: TToolBar
Left = 0
Top = 0
Width = 688
Height = 29
Caption = 'ToolBar'
Color = clBtnFace
EdgeBorders = [ebTop, ebBottom]
Flat = True
Images = ImageList1
ParentColor = False
TabOrder = 1
object ToolButton1: TToolButton
Left = 0
Top = 0
Width = 8
Caption = 'ToolButton1'
ImageIndex = 1
Style = tbsSeparator
end
object btnOpen: TToolButton
Left = 8
Top = 0
Hint = 'Open image file...'
Caption = 'Open...'
ImageIndex = 0
OnClick = mnuFileOpenClick
end
object ToolButton4: TToolButton
Left = 31
Top = 0
Width = 8
Caption = 'ToolButton4'
ImageIndex = 4
Style = tbsSeparator
end
object btnCopy: TToolButton
Left = 39
Top = 0
Hint = 'Copy to clipboard'
Caption = 'Copy'
ImageIndex = 1
OnClick = btnCopyClick
end
object btnPaste: TToolButton
Left = 62
Top = 0
Hint = 'Paste from from clipboard'
Caption = 'Paste'
ImageIndex = 2
OnClick = btnPasteClick
end
object ToolButton3: TToolButton
Left = 85
Top = 0
Width = 8
Caption = 'ToolButton3'
ImageIndex = 4
Style = tbsSeparator
end
object btnClear: TToolButton
Left = 93
Top = 0
Caption = 'Clear'
ImageIndex = 3
OnClick = btnClearClick
end
end
object MainMenu: TMainMenu
Left = 120
Top = 48
object mnuFile: TMenuItem
Caption = '&File'
object mnuFileOpen: TMenuItem
Caption = '&Open'
OnClick = mnuFileOpenClick
end
object mnuExit: TMenuItem
Caption = 'E&xit'
OnClick = mnuExitClick
end
end
object mnuImage: TMenuItem
Caption = 'Image'
object mnuImageFlip: TMenuItem
Caption = 'Flip'
object mnuFlipHorz: TMenuItem
Caption = 'Horizontal'
OnClick = mnuFlipHorzClick
end
object mnuFlipVert: TMenuItem
Caption = 'Vertical'
OnClick = mnuFlipHorzClick
end
end
object mnuConvert: TMenuItem
Caption = 'Convert'
object mnuTo4Bits: TMenuItem
Caption = 'To 4 Bits'
OnClick = mnuFlipHorzClick
end
object mnuTo8Bits: TMenuItem
Caption = 'To 8 Bits'
OnClick = mnuFlipHorzClick
end
object mnuTo16Bits555: TMenuItem
Caption = 'To 16 Bits (555)'
OnClick = mnuFlipHorzClick
end
object mnuTo16Bits565: TMenuItem
Caption = 'To 16 Bits (565)'
OnClick = mnuFlipHorzClick
end
object mnuTo24Bits: TMenuItem
Caption = 'To 24 Bits'
OnClick = mnuFlipHorzClick
end
object mnuTo32Bits: TMenuItem
Caption = 'To 32 Bits'
OnClick = mnuFlipHorzClick
end
object mnuDither: TMenuItem
Caption = 'Dither'
OnClick = mnuFlipHorzClick
end
object mnuQuantize: TMenuItem
Caption = 'Quantize'
OnClick = mnuFlipHorzClick
end
object mnuGrayScale: TMenuItem
Caption = 'GrayScale'
OnClick = mnuFlipHorzClick
end
end
object mnuRotate: TMenuItem
Caption = 'Rotate'
object mnuClockwise: TMenuItem
Caption = 'Clockwise'
OnClick = mnuFlipHorzClick
end
object mnuAntiClockwise: TMenuItem
Caption = 'AntiClockwise'
OnClick = mnuFlipHorzClick
end
end
object mnuInvert: TMenuItem
Caption = 'Invert'
OnClick = mnuFlipHorzClick
end
object mnuClear: TMenuItem
Caption = 'Clear'
OnClick = mnuFlipHorzClick
end
end
end
object OD: TOpenDialog
Title = 'Open file ...'
Left = 152
Top = 48
end
object ImageList1: TImageList
Left = 184
Top = 48
Bitmap = {
494C010104000900040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
0000000000003600000028000000400000003000000001002000000000000030
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000007088900060809000607880005070
8000506070004058600040485000303840002030300020203000101820001010
1000101020000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000080685000203040002030400020304000203040002030
4000203040002030400020304000203040000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000DFE2F700EFF0FB0000000000000000007088900090A0B00070B0D0000090
D0000090D0000090D0000090C0001088C0001080B0001080B0002078A0002070
900020486000B9BEBE0000000000000000000000000000000000000000000000
00000000000000000000C0704000B0583000B0583000A0502000A05020009048
2000904820009040200080402000000000007086900060809000506070004050
6000304050002030400090706000F0E0D000B0A09000B0A09000B0A09000B0A0
9000B0A09000B0A09000B0A0900020304000000000000000000000000000EFF1
FF001F3BF100EFF1FF000000000000000000000000000000000000000000CFD3
F3001F2DB900CFD2F30000000000000000008088900080C0D00090A8B00080E0
FF0060D0FF0050C8FF0050C8FF0040C0F00030B0F00030A8F00020A0E0001090
D00020688000656A700000000000000000000000000000000000000000000000
00000000000000000000C0785000FFF8F000D0B0A000D0B0A000D0B0A000C0B0
A000C0A8A000C0A8900090402000000000007080900020B8F0000090D0000090
D0000090D0000090D00090786000F0E8E000F0D8D000E0D0C000E0C8C000D0C0
B000D0B8B000D0B8B000B0A09000203040000000000000000000F0F2FF00576F
FF001030FF001E34FF00EFF1FF00000000000000000000000000DFE2F7003F51
CF000018C0000F1EB400DFE2F700000000008090A00080D0F00090A8B00090C0
D00070D8FF0060D0FF0060D0FF0050C8FF0050C0FF0040B8F00030B0F00030A8
F0001088D00020486000E1E4E500000000000000000000000000000000000000
00000000000000000000D0886000FFFFFF00E0906000D0805000D0805000D080
5000D0805000C0A8A00090482000000000007088900070C8F00010B8F00010B0
F00000A8E0000098D000A0807000F0F0F000C0B0A000C0B0A000C0A8A000B0A0
9000D0C0B000B0A09000B0A0900020304000000000000000000000000000F1F2
FF002D52FF001030FF000028FF00CFD5FF0000000000CFD3F3001F34C7000018
D0000F25C300BFC5EF0000000000000000008090A00080D8F00080C8E00090A8
B00080E0FF0070D0FF0060D8FF0060D0FF0060D0FF0050C8FF0040C0F00040B8
F00030B0F000206880007897A50000000000B0A0900060483000604830006048
30006048300060483000D0907000FFFFFF00FFFFFF00FFF0F000F0E0D000F0D0
C000F0C0B000C0B0A00090482000000000008088900070D0F00030C0F00010B8
F00000A8F00000A0E000A0888000FFF8FF00F0F0F000F0E8E000F0D8D000E0D0
C000705850006050400050484000404040000000000000000000000000000000
0000F1F2FF002D52FF001030FF000F2DFF00CFD3F6001F34D5000020E0000F25
D200DFE2F7000000000000000000000000008098A00090E0F00090E0FF0090A8
B00090B8C00070D8FF0060D8FF0060D8FF0060D8FF0060D0FF0050D0FF0050C8
FF0040B8F00030A0E0004B697800DEE1E400B0A09000FFF0F000F0E0D000E0D8
D000E0D0C000E0C8C000E0A08000FFFFFF00F0A88000E0987000E0906000D080
5000D0805000D0B0A000A0482000000000008090A00080D8F00040C8F00030C0
F00010B8F00000A0E000B0908000FFFFFF00C0B0A000C0B0A000C0A8A000F0E0
D00080605000D0C8C00060504000000000000000000000000000000000000000
000000000000E3E6FF005669FF001038FF000020F0000F2DF0002F42D800DFE2
F700000000000000000000000000000000008098A00090E0F000A0E8FF0080C8
E00090A8B00080E0FF0080E0FF0080E0FF0080E0FF0080E0FF0080E0FF0080E0
FF0070D8FF0070D8FF0050A8D000919BA500B0A09000FFF8F000E0B08000E0A0
7000E0A07000D0987000E0A89000FFFFFF00FFFFFF00FFFFFF00FFF8F000F0E8
E000F0D0C000D0B0A000A0502000000000008098A00090E0F00060D8F00050C8
F00030C0F00010B0F000B0989000FFFFFF00FFFFFF00FFF8FF00F0F0F000F0E8
E000806850008060500000000000000000000000000000000000000000000000
00000000000000000000C3CAFF002048FF001030FF000F2DF000CFD3F6000000
00000000000000000000000000000000000090A0A000A0E8F000A0E8FF00A0E8
FF0090B0C00090B0C00090A8B00090A8B00080A0B00080A0B0008098A0008098
A0008090A0008090A0008088900070889000C0A89000FFFFFF00FFF8F000F0F0
F000F0E8E000F0E0D000E0B8A000FFFFFF00FFB09000FFB09000F0D8D000E090
6000B0583000B0583000A0502000000000008098A000A0E8F00080E0F00070D8
F00050D0F00010B0F000B0A09000B0989000B0908000A0888000A08070009078
6000907060000000000000000000000000000000000000000000000000000000
000000000000CFD7FF004060FF003050FF002D4BFF001038FF000020F000DFE3
FD000000000000000000000000000000000090A0B000A0E8F000A0F0FF00A0E8
FF00A0E8FF0080D8FF0060D8FF0060D8FF0060D8FF0060D8FF0060D8FF0060D8
FF0070889000000000000000000000000000C0A8A000FFFFFF00FFC8A000F0B8
9000E0B08000E0A07000F0C0A000FFFFFF00FFFFFF00FFFFFF00FFFFFF00F098
7000F0C8B000B0583000EBD5CB000000000090A0A000B0F0FF00A0E8FF0090E0
F00070D0F00010A0D00010A0D00010A0D0001098D0000090D0000090D0000090
D000303840000000000000000000000000000000000000000000000000000000
0000DBE1FF004060FF004058FF004B70FF00CFD5FF004B69FF002040FF000020
F000CFD5FC0000000000000000000000000090A0B000A0F0F000B0F0F000A0F0
FF00A0E8FF00A0E8FF0070D8FF0090A0A0008098A0008098A0008090A0008090
900070889000000000000000000000000000C0B0A000FFFFFF00FFFFFF00FFF8
FF00FFF0F000F0E8E000F0C8B000FFFFFF00FFFFFF00FFFFFF00FFFFFF00F0A8
8000C0683000EFD9CB00000000000000000090A0B000B0F0FF00A0F0FF006080
9000607080005070800050687000506870005060700040587000207090000090
D00040486000000000000000000000000000000000000000000000000000E7EB
FF005070FF005078FF00708AFF00E7EBFF0000000000DBDFFF004B69FF003048
FF000020F000CFD5FC00000000000000000090A8B000A0D0E000B0F0F000B0F0
F000A0F0FF00A0E8FF0090A0B000B3C7CB000000000000000000000000000000
000000000000906850009068500090685000D0B8B000FFFFFF00FFD8C000FFD0
B000F0E0D000B0A09000F0C8B000F0C0B000F0C0B000F0B8A000F0B09000F0B0
9000F7E3D70000000000000000000000000090A8B000B0F0FF00B0F0FF006088
900090C8D00090E8F00080D8E00060C8E0005098B000405860002080A0000090
D000505870000000000000000000000000000000000000000000F3F5FF006078
FF006078FF00697FFF00F3F5FF00000000000000000000000000E7EAFF004B69
FF003050FF000028FF00DFE3FD0000000000DCE3E60090A8B00090A8B00090A8
B00090A8B00090A8B000AAB3B400000000000000000000000000000000000000
000000000000E1D4D2009068500090685000D0C0B000FFFFFF00FFFFFF00FFFF
FF00FFFFFF00C0A89000D0C8C00090706000E1DCD80000000000000000000000
00000000000000000000000000000000000090A8B000B0F0F000B0F0FF00A0F0
F0007098A000A0F0F00060757C0080C8D000507080003060800060C0F00020B8
F00050607000000000000000000000000000000000000000000000000000E7EB
FF006987FF00F3F5FF000000000000000000000000000000000000000000E7EA
FF005773FF00E1E5FF0000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000090786000B7A498000000
0000F9F6F600A0908000E1D9D20090786000E0C0B000FFFFFF00FFFFFF00FFFF
FF00FFFFFF00C0B0A000A0806000E1DCD8000000000000000000000000000000
000000000000000000000000000000000000CED8DC0090A8B00090A8B00090A8
B0006090A000A0E8F000A0E8F00090D8E0004068700070889000808890007088
9000D7DADC000000000000000000000000000000000000000000000000000000
0000F3F5FF000000000000000000000000000000000000000000000000000000
0000E7EAFF000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000D1CFC900A0908000A088
8000B0988000CFC7BF000000000000000000E0C0B000E0C0B000D0C0B000D0C0
B000D0B8B000D0B0A000E6DEDC00000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000080B0C00080B0C00080A0B000DEE1E40000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000424D3E000000000000003E000000
2800000040000000300000000100010000000000800100000000000000000000
000000000000000000000000FFFFFF0000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000FFFFFFFFFFFFFFFF0007FFFFFC00FFF3
0003FC010000E3E30003FC010000C1C10001FC010000E083000100010000F007
000000010001F80F000000010003FC1F000000010007F80F000700010007F007
000700030007E08300F800070007C1C101F8007F0007E3E3FF9000FF0007F7F7
FF8301FFF87FFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000
000000000000}
end
end

View File

@@ -0,0 +1,227 @@
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, FreeBitmap, ComCtrls, ImgList, ToolWin;
type
TfwbMainForm = class(TForm)
MainMenu: TMainMenu;
mnuFile: TMenuItem;
mnuFileOpen: TMenuItem;
mnuExit: TMenuItem;
OD: TOpenDialog;
StatusBar: TStatusBar;
mnuImage: TMenuItem;
mnuImageFlip: TMenuItem;
mnuFlipHorz: TMenuItem;
mnuFlipVert: TMenuItem;
mnuConvert: TMenuItem;
mnuTo8Bits: TMenuItem;
mnuTo16Bits555: TMenuItem;
mnuTo16Bits565: TMenuItem;
mnuTo24Bits: TMenuItem;
mnuTo32Bits: TMenuItem;
mnuDither: TMenuItem;
mnuQuantize: TMenuItem;
mnuGrayScale: TMenuItem;
mnuRotate: TMenuItem;
mnuClockwise: TMenuItem;
mnuAntiClockwise: TMenuItem;
mnuInvert: TMenuItem;
mnuClear: TMenuItem;
mnuTo4Bits: TMenuItem;
tbTools: TToolBar;
btnCopy: TToolButton;
ImageList1: TImageList;
ToolButton1: TToolButton;
btnPaste: TToolButton;
btnClear: TToolButton;
btnOpen: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
procedure FormDestroy(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure mnuExitClick(Sender: TObject);
procedure mnuFileOpenClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure mnuFlipHorzClick(Sender: TObject);
procedure btnCopyClick(Sender: TObject);
procedure btnClearClick(Sender: TObject);
procedure btnPasteClick(Sender: TObject);
private
FBitmap: TFreeWinBitmap;
procedure WMEraseBkgnd(var Message: TMessage); message WM_ERASEBKGND;
public
{ Public declarations }
end;
var
fwbMainForm: TfwbMainForm;
implementation
{$R *.dfm}
uses
FreeUtils, FreeImage, Math;
procedure TfwbMainForm.FormDestroy(Sender: TObject);
begin
if Assigned(FBitmap) then
FBitmap.Free;
end;
procedure TfwbMainForm.FormPaint(Sender: TObject);
var
dx, dy, w, h: Integer;
r1, r2: Double;
R: TRect;
begin
if FBitmap.IsValid then // draw the bitmap
begin
// determine paint rect
r1 := FBitmap.GetWidth / FBitmap.GetHeight;
r2 := ClientWidth / ClientHeight;
if r1 > r2 then // fit by width
begin
w := ClientWidth;
h := Floor(w / r1);
dx := 0;
dy := (ClientHeight - h) div 2;
end
else // fit by height
begin
h := ClientHeight;
w := Floor(h * r1);
dy := 0;
dx := (ClientWidth - w) div 2;
end;
with ClientRect do
R := Bounds(Left + dx, Top + dy, w, h);
FBitmap.Draw(Canvas.Handle, R);
// erase area around the image
Canvas.Brush.Color := Color;
if dx > 0 then
begin
with ClientRect do
R := Bounds(Left, Top, dx, ClientHeight);
Canvas.FillRect(R);
with ClientRect do
R := Bounds(Right - dx, Top, dx, ClientHeight);
Canvas.FillRect(R);
end else
if dy > 0 then
begin
with ClientRect do
R := Bounds(Left, Top, ClientWidth, dy);
Canvas.FillRect(R);
with ClientRect do
R := Bounds(Left, Bottom - dy, ClientWidth, dy);
Canvas.FillRect(R);
end
end
else // clear
begin
Canvas.Brush.Color := Color;
Canvas.FillRect(ClientRect);
end
end;
procedure TfwbMainForm.FormCreate(Sender: TObject);
begin
FBitmap := TFreeWinBitmap.Create;
mnuImage.Enabled := FBitmap.IsValid;
OD.Filter := FIU_GetAllFilters;
end;
procedure TfwbMainForm.mnuExitClick(Sender: TObject);
begin
Close;
end;
procedure TfwbMainForm.mnuFileOpenClick(Sender: TObject);
var
t: Cardinal;
begin
if OD.Execute then
begin
t := GetTickCount;
FBitmap.Load(OD.FileName);
t := GetTickCount - t;
mnuImage.Enabled := FBitmap.IsValid;
StatusBar.Panels[0].Text := 'Loaded in ' + IntToStr(t) + ' msec.';
StatusBar.Panels[1].Text := Format('%dx%d', [FBitmap.GetWidth, FBitmap.GetHeight]);
Invalidate;
end;
end;
procedure TfwbMainForm.FormResize(Sender: TObject);
begin
Invalidate
end;
procedure TfwbMainForm.WMEraseBkgnd(var Message: TMessage);
begin
Message.Result := 1;
end;
procedure TfwbMainForm.mnuFlipHorzClick(Sender: TObject);
begin
with FBitmap do
if Sender = mnuFlipHorz then
FLipHorizontal else
if Sender = mnuFlipVert then
FlipVertical else
if Sender = mnuTo4Bits then
ConvertTo4Bits else
if Sender = mnuTo8Bits then
ConvertTo8Bits else
if Sender = mnuTo16Bits555 then
ConvertTo16Bits555 else
if Sender = mnuTo16Bits565 then
ConvertTo16Bits565 else
if Sender = mnuTo24Bits then
ConvertTo24Bits else
if Sender = mnuTo32Bits then
ConvertTo32Bits else
if Sender = mnuDither then
Dither(FID_FS) else
if Sender = mnuQuantize then
ColorQuantize(FIQ_WUQUANT) else
if Sender = mnuGrayScale then
ConvertToGrayscale else
if Sender = mnuClockwise then
Rotate(-90) else
if Sender = mnuAntiClockwise then
Rotate(90) else
if Sender = mnuInvert then
Invert else
if Sender = mnuClear then
Clear;
Invalidate;
end;
procedure TfwbMainForm.btnCopyClick(Sender: TObject);
begin
if FBitmap.IsValid then FBitmap.CopyToClipBoard(Handle);
end;
procedure TfwbMainForm.btnClearClick(Sender: TObject);
begin
FBitmap.Clear;
Invalidate;
end;
procedure TfwbMainForm.btnPasteClick(Sender: TObject);
begin
FBitmap.PasteFromClipBoard;
Invalidate;
end;
end.

View File

@@ -0,0 +1,3 @@
The contents of FreeImageDW package are subject to the FreeImage Public License Version 1.0 (the "License"); you may not use this package except in compliance with the License. You may obtain a copy of the License at http://home.wxs.nl/~flvdberg/freeimage-license.txt
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,186 @@
unit FreeUtils;
// ==========================================================
//
// Delphi wrapper for FreeImage 3
//
// Design and implementation by
// - Anatoliy Pulyaevskiy (xvel84@rambler.ru)
//
// Contributors:
// - Enzo Costantini (enzocostantini@libero.it)
// - Armindo (tech1.yxendis@wanadoo.fr)
// - Lorenzo Monti (LM) lomo74@gmail.com
//
// Revision history
// When Who What
// ----------- ----- -----------------------------------------------------------
// 2010-07-14 LM made RAD2010 compliant (unicode)
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
//
// ==========================================================
interface
{$I 'Version.inc'}
uses
{$IFDEF DELPHI2010}AnsiStrings,{$ENDIF} SysUtils, Classes, FreeImage;
function FIU_GetFIFType(filename: AnsiString): FREE_IMAGE_FORMAT;
// returns FIF (plugin) description string
function FIU_GetFIFDescription(fif: FREE_IMAGE_FORMAT): AnsiString;
procedure FIU_GetAllDescriptions(var Descriptions: TStringList);
// returns file extentions for FIF (e.g. '*.tif;*.tiff)
function FIU_GetFIFExtList(fif: FREE_IMAGE_FORMAT): AnsiString;
// returns file extentions for all plugins
function FIU_GetFullExtList: AnsiString;
// returns "Description + | + ExtList" for specified FIF
function FIU_GetFIFFilter(fif: FREE_IMAGE_FORMAT): AnsiString;
// All supported formats + Full filter list for FIFs
function FIU_GetAllFilters: AnsiString;
//Filter for OpenDialogs
function FIU_GetAllOpenFilters: AnsiString;
//Filter for SaveDialogs
function FIU_GetAllSaveFilters: AnsiString;
implementation
const
FIF_START = FIF_UNKNOWN;
FIF_END = FIF_XPM;
function FIU_GetFIFType(filename: AnsiString): FREE_IMAGE_FORMAT;
begin
Result := FreeImage_GetFileType(PAnsiChar(filename), 0);
end;
function FIU_GetFIFDescription(fif: FREE_IMAGE_FORMAT): AnsiString;
begin
Result := FreeImage_GetFIFDescription(fif)
end;
procedure FIU_GetAllDescriptions(var Descriptions: TStringList);
var
fif: FREE_IMAGE_FORMAT;
begin
Descriptions.Clear;
for fif := FIF_START to FIF_END do
Descriptions.Add(string(FreeImage_GetFIFDescription(fif)) + ' (' +
string(FIu_GetFIFExtList(fif)) + ')');
end;
function FIU_GetFIFExtList(fif: FREE_IMAGE_FORMAT): AnsiString;
var
ExtList: AnsiString;
I: Smallint;
C: AnsiChar;
begin
Result := '*.';
ExtList := FreeImage_GetFIFExtensionList(fif);
for I := 1 to Length(ExtList) do
begin
C := ExtList[i];
if C <> ',' then
Result := Result + C
else
Result := Result + ';*.';
end
end;
function FIU_GetFullExtList: AnsiString;
var
fif: FREE_IMAGE_FORMAT;
begin
Result := FIU_GetFIFExtList(FIF_START);
for fif := FIF_START to FIF_END do
Result := Result + ';' + FIU_GetFIFExtList(fif)
end;
function FIU_GetFIFFilter(fif: FREE_IMAGE_FORMAT): AnsiString;
var
Text, ExtList: AnsiString;
begin
Result := '';
if fif <> FIF_UNKNOWN then
begin
Text := {$IFDEF DELPHI2010}AnsiStrings.{$ENDIF}Trim(FreeImage_GetFIFDescription(fif));
ExtList := FIU_GetFIFExtList(fif);
Result := Text + '(' + ExtList + ')' + '|' + ExtList
end
end;
function FIU_GetAllFilters: AnsiString;
var
fif: FREE_IMAGE_FORMAT;
begin
Result := 'All supported formats|' + FIU_GetFullExtList;
for fif := FIF_START to FIF_END do
begin
Result := Result + '|' + FIU_GetFIFFilter(fif)
end;
end;
function FIU_GetAllOpenFilters: AnsiString;
var
fif: FREE_IMAGE_FORMAT;
begin
Result := 'All supported formats|' + FIU_GetFullExtList;
for fif := FIF_START to FIF_END do
if FreeImage_FIFSupportsReading(fif) then
begin
Result := Result + '|' + FIU_GetFIFFilter(fif)
end;
end;
function FIU_GetAllSaveFilters: AnsiString;
var
ExtList: AnsiString;
I: Smallint;
C: AnsiChar;
fif: FREE_IMAGE_FORMAT;
s: AnsiString;
begin
result := '';
for fif := FIF_START to FIF_END do
if FreeImage_FIFSupportsWriting(fif) then
begin
ExtList := FreeImage_GetFIFExtensionList(fif);
s := '';
for I := 1 to Length(ExtList) do
begin
C := ExtList[i];
if C <> ',' then
S := S + C
else
begin
result := Result + FreeImage_GetFIFDescription(fif) + ' (' + UpperCase(s) + ')|*.' + s + '|';
s := '';
end;
end;
result := Result + FreeImage_GetFIFDescription(fif) + ' (' + UpperCase(s) + ')|*.' + s + '|';
end;
end;
end.

View File

@@ -0,0 +1,186 @@
// ==========================================================
// Delphi wrapper for FreeImage 3
//
// Design and implementation by
// - Simon Beavis
// - Peter Bystr<74>m
// - Anatoliy Pulyaevskiy (xvel84@rambler.ru)
//
// Contributors:
// - Lorenzo Monti (LM) lomo74@gmail.com
//
// Revision history
// When Who What
// ----------- ----- -----------------------------------------------------------
// 2010-07-29 LM Added Free Pascal / Lazarus 32 bit support
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================
//some older Delphi version will define WIN32 but not MSWINDOWS
{$IFNDEF MSWINDOWS}
{$IFDEF WIN32}
{$DEFINE MSWINDOWS}
{$ENDIF}
{$ENDIF}
//test for compiler
{$IFDEF FPC}
//Free pascal
{$IFNDEF CPU32}
{$ERROR "64 bit platforms not tested yet. Remove this line if you feel brave."}
{$ENDIF}
{$IFNDEF ENDIAN_LITTLE}
{$ERROR "Big endian CPUs not tested yet. Remove this line if you feel brave."}
{$ENDIF}
{$DEFINE DELPHI1}
{$DEFINE DELPHI2}
{$DEFINE DELPHI3}
{$DEFINE DELPHI4}
{$DEFINE DELPHI5}
{$DEFINE DELPHI6}
{$DEFINE DELPHI7}
{$ELSE}
//Delphi
{$IFDEF VER80}
{$DEFINE DELPHI1}
{$ENDIF}
{$IFDEF VER90}
{$DEFINE DELPHI1}
{$DEFINE DELPHI2}
{$ENDIF}
{$IFDEF VER100}
{$DEFINE DELPHI1}
{$DEFINE DELPHI2}
{$DEFINE DELPHI3}
{$ENDIF}
{$IFDEF VER120}
{$DEFINE DELPHI1}
{$DEFINE DELPHI2}
{$DEFINE DELPHI3}
{$DEFINE DELPHI4}
{$ENDIF}
{$IFDEF VER130}
{$DEFINE DELPHI1}
{$DEFINE DELPHI2}
{$DEFINE DELPHI3}
{$DEFINE DELPHI4}
{$DEFINE DELPHI5}
{$ENDIF}
{$IFDEF VER140}
{$DEFINE DELPHI1}
{$DEFINE DELPHI2}
{$DEFINE DELPHI3}
{$DEFINE DELPHI4}
{$DEFINE DELPHI5}
{$DEFINE DELPHI6}
{$ENDIF}
{$IFDEF VER150}
{$DEFINE DELPHI1}
{$DEFINE DELPHI2}
{$DEFINE DELPHI3}
{$DEFINE DELPHI4}
{$DEFINE DELPHI5}
{$DEFINE DELPHI6}
{$DEFINE DELPHI7}
{$ENDIF}
{$IFDEF VER160}
{$DEFINE DELPHI1}
{$DEFINE DELPHI2}
{$DEFINE DELPHI3}
{$DEFINE DELPHI4}
{$DEFINE DELPHI5}
{$DEFINE DELPHI6}
{$DEFINE DELPHI7}
{$DEFINE DELPHI8}
{$ENDIF}
{$IFDEF VER170}
{$DEFINE DELPHI1}
{$DEFINE DELPHI2}
{$DEFINE DELPHI3}
{$DEFINE DELPHI4}
{$DEFINE DELPHI5}
{$DEFINE DELPHI6}
{$DEFINE DELPHI7}
{$DEFINE DELPHI8}
{$DEFINE DELPHI2005}
{$ENDIF}
{$IFDEF VER180}
{$DEFINE DELPHI1}
{$DEFINE DELPHI2}
{$DEFINE DELPHI3}
{$DEFINE DELPHI4}
{$DEFINE DELPHI5}
{$DEFINE DELPHI6}
{$DEFINE DELPHI7}
{$DEFINE DELPHI8}
{$DEFINE DELPHI2005}
{$DEFINE DELPHI2006}
{$ENDIF}
{$IFDEF VER185}
{$DEFINE DELPHI1}
{$DEFINE DELPHI2}
{$DEFINE DELPHI3}
{$DEFINE DELPHI4}
{$DEFINE DELPHI5}
{$DEFINE DELPHI6}
{$DEFINE DELPHI7}
{$DEFINE DELPHI8}
{$DEFINE DELPHI2005}
{$DEFINE DELPHI2006}
{$DEFINE DELPHI2007}
{$ENDIF}
{$IFDEF VER200}
{$DEFINE DELPHI1}
{$DEFINE DELPHI2}
{$DEFINE DELPHI3}
{$DEFINE DELPHI4}
{$DEFINE DELPHI5}
{$DEFINE DELPHI6}
{$DEFINE DELPHI7}
{$DEFINE DELPHI8}
{$DEFINE DELPHI2005}
{$DEFINE DELPHI2006}
{$DEFINE DELPHI2007}
{$DEFINE DELPHI2009}
{$ENDIF}
{$IFDEF VER210}
{$DEFINE DELPHI1}
{$DEFINE DELPHI2}
{$DEFINE DELPHI3}
{$DEFINE DELPHI4}
{$DEFINE DELPHI5}
{$DEFINE DELPHI6}
{$DEFINE DELPHI7}
{$DEFINE DELPHI8}
{$DEFINE DELPHI2005}
{$DEFINE DELPHI2006}
{$DEFINE DELPHI2007}
{$DEFINE DELPHI2009}
{$DEFINE DELPHI2010}
{$ENDIF}
{$ENDIF}

View File

@@ -0,0 +1,58 @@
#include "stdafx.h"
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly:AssemblyTitleAttribute("")];
[assembly:AssemblyDescriptionAttribute("")];
[assembly:AssemblyConfigurationAttribute("")];
[assembly:AssemblyCompanyAttribute("")];
[assembly:AssemblyProductAttribute("")];
[assembly:AssemblyCopyrightAttribute("")];
[assembly:AssemblyTrademarkAttribute("")];
[assembly:AssemblyCultureAttribute("")];
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the value or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly:AssemblyVersionAttribute("1.0.*")];
//
// In order to sign your assembly you must specify a key to use. Refer to the
// Microsoft .NET Framework documentation for more information on assembly signing.
//
// Use the attributes below to control which key is used for signing.
//
// Notes:
// (*) If no key is specified, the assembly is not signed.
// (*) KeyName refers to a key that has been installed in the Crypto Service
// Provider (CSP) on your machine. KeyFile refers to a file which contains
// a key.
// (*) If the KeyFile and the KeyName values are both specified, the
// following processing occurs:
// (1) If the KeyName can be found in the CSP, that key is used.
// (2) If the KeyName does not exist and the KeyFile does exist, the key
// in the KeyFile is installed into the CSP and used.
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
// When specifying the KeyFile, the location of the KeyFile should be
// relative to the project directory.
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
// documentation for more information on this.
//
[assembly:AssemblyDelaySignAttribute(false)];
[assembly:AssemblyKeyFileAttribute("")];
[assembly:AssemblyKeyNameAttribute("")];

View File

@@ -0,0 +1,69 @@
// ==========================================================
// FreeImageIO.Net
//
// Design and implementation by
// - Marcos Pernambuco Motta (marcos.pernambuco@gmail.com)
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================
#include "stdafx.h"
#include "FreeImageIO.Net.h"
extern "C" static unsigned __stdcall ReadProc (void *buffer, unsigned size, unsigned count, fi_handle handle)
{
int total_read = 0;
struct UNMANAGED_HANDLER* puh = (struct UNMANAGED_HANDLER*)handle;
gcroot<unsigned char __gc []> mbuffer = new unsigned char __gc[size];
try
{
total_read = puh->_stream->Read(mbuffer,0,size);
Marshal::Copy(mbuffer,0,buffer,total_read);
} __finally {
mbuffer=NULL;
}
return (unsigned)total_read;
}
extern "C" static unsigned __stdcall WriteProc (void *buffer, unsigned size, unsigned count, fi_handle handle)
{
struct UNMANAGED_HANDLER* puh = (struct UNMANAGED_HANDLER*)handle;
gcroot<unsigned char __gc []> mbuffer = new unsigned char __gc[size*count];
try
{
unsigned char __pin* pbuffer = &mbuffer[0];
memcpy(pbuffer,buffer,size*count);
puh->_stream->Write(mbuffer,0,size);
} __finally {
mbuffer=NULL;
}
return count;
}
extern "C" static int __stdcall SeekProc (fi_handle handle, long offset, int origin)
{
struct UNMANAGED_HANDLER* puh = (struct UNMANAGED_HANDLER*)handle;
return (int)puh->_stream->Seek(offset,(SeekOrigin) origin);
}
extern "C" static long __stdcall TellProc(fi_handle handle)
{
struct UNMANAGED_HANDLER* puh = (struct UNMANAGED_HANDLER*)handle;
return (long)puh->_stream->Position;
}

View File

@@ -0,0 +1,83 @@
// ==========================================================
// FreeImageIO.Net
//
// Design and implementation by
// - Marcos Pernambuco Motta (marcos.pernambuco@gmail.com)
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================
#pragma once
#include <vcclr.h>
#include "FreeImage.h"
using namespace System;
using namespace System::IO;
using namespace System::Runtime::InteropServices;
extern "C" {
// forward decls
unsigned __stdcall ReadProc (void *buffer, unsigned size, unsigned count, fi_handle handle);
unsigned __stdcall WriteProc (void *buffer, unsigned size, unsigned count, fi_handle handle);
int __stdcall SeekProc (fi_handle handle, long offset, int origin);
long __stdcall TellProc(fi_handle handle);
#pragma pack(push, 1)
__nogc struct UNMANAGED_HANDLER {
UNMANAGED_HANDLER() {
read_proc = &ReadProc;
write_proc = WriteProc;
seek_proc = SeekProc;
tell_proc = TellProc;
}
FI_ReadProc read_proc; // pointer to the function used to read data
FI_WriteProc write_proc; // pointer to the function used to write data
FI_SeekProc seek_proc; // pointer to the function used to seek
FI_TellProc tell_proc; // pointer to the function used to aquire the current position
gcroot<System::IO::Stream*> _stream;
};
#pragma pack(pop)
}
#define FREEIMAGE_DLL "freeimaged.dll"
namespace FreeImageIODotNet
{
__gc public class FreeImageStream
{
private:
struct UNMANAGED_HANDLER* _pUnmanaged;
public:
FreeImageStream(System::IO::Stream* stream)
{
FreeImage_SaveToHandle((FREE_IMAGE_FORMAT) 1,0,0,0,0);
_pUnmanaged = new struct UNMANAGED_HANDLER;
_pUnmanaged->_stream = stream;
}
~FreeImageStream()
{
_pUnmanaged->_stream = NULL;
delete _pUnmanaged;
}
bool SaveImage(FREE_IMAGE_FORMAT fif, unsigned int dib, int flags) {
return (bool)FreeImage_SaveToHandle(fif,(FIBITMAP*) dib,(FreeImageIO*)_pUnmanaged,(fi_handle)_pUnmanaged,flags);
}
unsigned int LoadImage(FREE_IMAGE_FORMAT fif, int flags) {
return (unsigned int)FreeImage_LoadFromHandle(fif,(FreeImageIO*)_pUnmanaged,(fi_handle)_pUnmanaged,flags);
}
};
}

View File

@@ -0,0 +1,176 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="FreeImageIO.Net"
ProjectGUID="{E87923FF-1FBD-450D-9287-539A90DE9776}"
RootNamespace="FreeImageIONet"
Keyword="ManagedCProj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="2"
ManagedExtensions="TRUE">
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/Zl"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG"
MinimalRebuild="FALSE"
BasicRuntimeChecks="0"
RuntimeLibrary="1"
UsePrecompiledHeader="3"
WarningLevel="3"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/noentry"
AdditionalDependencies="nochkclr.obj mscoree.lib msvcrt.lib FreeImaged.lib"
OutputFile="$(OutDir)\$(ProjectName).dll"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
AssemblyDebug="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="2"
ManagedExtensions="TRUE">
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/Zl"
PreprocessorDefinitions="WIN32;NDEBUG"
MinimalRebuild="FALSE"
RuntimeLibrary="0"
UsePrecompiledHeader="3"
WarningLevel="3"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/noentry"
AdditionalDependencies="nochkclr.obj mscoree.lib msvcrt.lib FreeImage.lib"
OutputFile="$(OutDir)\$(ProjectName).dll"
LinkIncremental="1"
GenerateDebugInformation="TRUE"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
<AssemblyReference
RelativePath="mscorlib.dll"/>
<AssemblyReference
RelativePath="System.dll"/>
<AssemblyReference
RelativePath="System.Data.dll"/>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\AssemblyInfo.cpp">
</File>
<File
RelativePath=".\FreeImageIO.Net.cpp">
</File>
<File
RelativePath=".\Stdafx.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath=".\FreeImageIO.Net.h">
</File>
<File
RelativePath=".\resource.h">
</File>
<File
RelativePath=".\Stdafx.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
<File
RelativePath=".\app.ico">
</File>
<File
RelativePath=".\app.rc">
</File>
</Filter>
<File
RelativePath=".\ReadMe.txt">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FreeImageIO.Net", "FreeImageIO.Net.vcproj", "{E87923FF-1FBD-450D-9287-539A90DE9776}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{E87923FF-1FBD-450D-9287-539A90DE9776}.Debug.ActiveCfg = Debug|Win32
{E87923FF-1FBD-450D-9287-539A90DE9776}.Debug.Build.0 = Debug|Win32
{E87923FF-1FBD-450D-9287-539A90DE9776}.Release.ActiveCfg = Release|Win32
{E87923FF-1FBD-450D-9287-539A90DE9776}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,27 @@
========================================================================
FreeImageIO.Net
Author: Marcos Pernambuco Motta (marcos.pernambuco@gmail.com)
========================================================================
This library allows programs that use FreeImage.Net to save images to or
to load images from .Net Streams.
The class FreeImageStream implements a FreeImageIO handler and routes
IO calls (read,write,tell and seek) to a wrapped System.IO.Stream.
Example:
using FreeImageAPI;
using FreeImageIODotNet;
uint dib = FreeImageAPI.FreeImage.Allocate(width,height,32,0,0,0);
// ... Image handling code goes here
System.IO.FileStream stream = new System.IO.FileStream(@"c:\sample.png",System.IO.FileMode.Create);
FreeImageStream imageStream = new FreeImageStream(stream);
imageStream.SaveImage((int)FREE_IMAGE_FORMAT.FIF_PNG,dib,0);
stream.Close();
Compile with VS2003.

View File

@@ -0,0 +1,5 @@
// stdafx.cpp : source file that includes just the standard includes
// FreeImageIO.Net.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"

View File

@@ -0,0 +1,6 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#pragma once

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,52 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon placed first or with lowest ID value becomes application icon
LANGUAGE 9, 1
#pragma code_page(1252)
1 ICON "app.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,3 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by app.rc

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
FreeImage .NET Wrapper Release Notes
The FreeImage .NET Wrapper included in the 3.14.1 release is still on version 3.13.1. It does not yet contain any new features or bug fixes. However, it is expected to work with the new FreeImage DLL with no problems.
The next version of FreeImage is expected to be released soon and will contain an updated .NET wrapper, including support for all new features, that have been introduced in this and the next version of FreeImage.
Regards, FreeImage .NET Wrapper Team

View File

@@ -0,0 +1,179 @@
using System;
using System.IO;
using FreeImageAPI;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
namespace Sample01
{
class Program
{
static void Main(string[] args)
{
// Check if FreeImage.dll is available (can be in %path%).
if (!FreeImage.IsAvailable())
{
Console.WriteLine("FreeImage.dll seems to be missing. Aborting.");
return;
}
Sample sample = new Sample();
// This example shows the basic loading and saving operations offered by FreeImage.
sample.Example01();
// This example shows a more comfortable way offered by the .NET Wrapper.
sample.Example02();
// This example shows the FreeImage-Errormessage-Callback
sample.Example03();
}
}
public class Sample
{
const string fileName = @"Sample.jpg";
const string outFileName = @"Sample.tif";
FIBITMAP dib = new FIBITMAP();
string message = null;
public void Example01()
{
if (!File.Exists(fileName))
{
Console.WriteLine(fileName + " does not exist. Aborting.");
return;
}
// Try to unload the bitmap handle (in case it is not null).
// Always assert that a handle (like dib) is unloaded before it is reused, because
// on unmanaged side there is no garbage collector that will clean up unreferenced
// objects.
// The following code will produce a memory leak (in case the bitmap is loaded
// successfully) because the handle to the first bitmap is lost:
// dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, fileName, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE);
// dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, fileName, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE);
if (!dib.IsNull)
FreeImage.Unload(dib);
// Loading a sample bitmap. In this case it's a .jpg file. 'Load' requires the file
// format or the loading process will fail. An additional flag (the default value is
// 'DEFAULT') can be set to enable special loading options.
dib = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, fileName, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE);
// Check if the handle is null which means the bitmap could not be loaded.
if (dib.IsNull)
{
Console.WriteLine("Loading bitmap failed. Aborting.");
// Check whether there was an error message.
return;
}
// Try flipping the bitmap.
if (!FreeImage.FlipHorizontal(dib))
{
Console.WriteLine("Unable to flip bitmap.");
// Check whether there was an error message.
}
// Store the bitmap back to disk. Again the desired format is needed. In this case the format is 'TIFF'.
// An output filename has to be chosen (which will be overwritten without a warning).
// A flag can be provided to enable pluginfunctions (compression is this case).
FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, dib, outFileName, FREE_IMAGE_SAVE_FLAGS.TIFF_DEFLATE);
// The bitmap was saved to disk but is still allocated in memory, so the handle has to be freed.
if (!dib.IsNull)
FreeImage.Unload(dib);
// Make sure to set the handle to null so that it is clear that the handle is not pointing to a bitmap.
dib.SetNull();
}
public void Example02()
{
// 'UnloadEx' is a comfortable way of unloading a bitmap. The coder can call 'UnloadEx' even
// when the handle is pointing to null (in this case nothing will happen). In case the handle
// is valid (valid means that it is NOT pointing to null) the bitmap will be unloaded and the
// handle will be set to null manually.
FreeImage.UnloadEx(ref dib);
// 'LoadEx' is a comfortable way of loading a bitmap. 'LoadEx' tries to find out the format of
// the file and will use this to load it. It will use DEFAULT loading values.
dib = FreeImage.LoadEx(fileName);
// Check if the handle is null which means the bitmap could not be loaded.
if (dib.IsNull)
{
Console.WriteLine("Loading bitmap failed. Aborting.");
return;
}
// 'SaveEx' (like 'LoadEx') will try to save the bitmap with default values.
// Before saving the bitmap, 'SaveEx' checks whether the extension is valid for the file type
// and if the plugin can use the colordepth of the bitmap. If not it will automatically convert
// the bitmap into the next best colordepth and save it.
if (!FreeImage.SaveEx(ref dib, @"Sample.gif", false))
{
Console.WriteLine("Saving bitmap failed.");
}
// The handle is still valid.
if (!FreeImage.SaveEx(
ref dib,
@"Sample", // No extension was selected so let 'SaveEx' decide.
FREE_IMAGE_FORMAT.FIF_PNG, // A format is needed this time.
FREE_IMAGE_SAVE_FLAGS.DEFAULT, // PNG has no options so use default.
FREE_IMAGE_COLOR_DEPTH.FICD_04_BPP, // 4bpp as result color depth.
true)) // We're done so unload
{
// SaveEx will not unload the bitmap in case saving failed.
// This way possible operations done to the bitmaps aren't lost.
FreeImage.UnloadEx(ref dib);
}
}
public void Example03()
{
// Safely unload to prevent memory leak.
FreeImage.UnloadEx(ref dib);
// Load the example bitmap.
dib = FreeImage.LoadEx(fileName);
// Check whether loading succeeded.
if (dib.IsNull)
{
return;
}
// Add this class to the callback event.
FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message);
// Try to save the bitmap as a gif
if (!FreeImage.Save(FREE_IMAGE_FORMAT.FIF_GIF, dib, @"Sample_fail.gif", FREE_IMAGE_SAVE_FLAGS.DEFAULT))
{
// Saving failed
// Check whether there was an error callback
if (message != null)
{
// Print the message and delete it.
Console.WriteLine("Error message recieved: {0}", message);
message = null;
}
}
// Unload bitmap.
FreeImage.UnloadEx(ref dib);
// Remove this class from the callback event.
FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message);
}
void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message)
{
this.message = message;
}
}
}

View File

@@ -0,0 +1,16 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("ac0569fe-c021-4f40-bfe9-275baf0fd21a")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,103 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{0D294AB6-FAD4-4364-AAB6-43C1796116A9}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sample01</RootNamespace>
<AssemblyName>Sample01</AssemblyName>
<StartupObject>
</StartupObject>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="FreeImageNET, Version=3.11.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Bin\FreeImageNET.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Sample.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

View File

@@ -0,0 +1,140 @@
using System;
using System.IO;
using FreeImageAPI;
namespace Sample02
{
class Program
{
static void Main(string[] args)
{
// Check if FreeImage.dll is available (can be in %path%).
if (!FreeImage.IsAvailable())
{
Console.WriteLine("FreeImage.dll seems to be missing. Aborting.");
return;
}
Sample sample = new Sample();
sample.Example();
}
}
public class Sample
{
const string fileName = @"multipaged.tif";
FIMULTIBITMAP dib = new FIMULTIBITMAP();
Random rand = new Random();
public void Example()
{
if (!File.Exists(fileName))
{
Console.WriteLine("File not found. Aborting.");
return;
}
// Load the multipaged bitmap.
// 'OpenMultiBitmapEx' tries to find the correct file format, loads the bitmap
// with default options, with write support and does not use caching.
dib = FreeImage.OpenMultiBitmapEx(fileName);
// Check whether loading succeeded.
if (dib.IsNull)
{
Console.WriteLine("File could not be loaded. Aborting.");
return;
}
// Get the number of bitmaps the multipaged bitmap contains.
int count = FreeImage.GetPageCount(dib);
// Multipaged bitmaps consist of multiple single FIBITMAPs
FIBITMAP page = new FIBITMAP();
// There are bitmaps we can work with.
if (count > 0)
{
// Lock a random bitmap to work with.
page = FreeImage.LockPage(dib, rand.Next(0, count));
}
// Check whether locking succeeded.
if (page.IsNull)
{
// Locking failed. Unload the bitmap and return.
FreeImage.CloseMultiBitmapEx(ref dib);
return;
}
// Get a list of locked pages. This can be usefull to check whether a page has already been locked.
int[] lockedPages = FreeImage.GetLockedPages(dib);
// Lets modify the page.
if (FreeImage.AdjustGamma(page, 2d))
{
Console.WriteLine("Successfully changed gamma of page {0}.", lockedPages[0]);
}
else
{
Console.WriteLine("Failed to adjust gamma ...");
}
// Print out the list of locked pages
foreach (int i in lockedPages)
Console.WriteLine("Page {0} is locked.", i);
// Use 'UnlockPage' instead of 'Unload' to free the page. Set the third parameter to 'true'
// so that FreeImage can store the changed page within the multipaged bitmap.
FreeImage.UnlockPage(dib, page, true);
// Retieve the list again to see whether unlocking succeeded.
lockedPages = FreeImage.GetLockedPages(dib);
// No output should be produced here.
foreach (int i in lockedPages)
Console.WriteLine("Page {0} is still locked.", i);
// If there are more than one page we can swap them
if (count > 1)
{
if (!FreeImage.MovePage(dib, 1, 0))
{
Console.WriteLine("Swapping pages failed.");
}
}
if (count > 2)
{
// Lock page 2
page = FreeImage.LockPage(dib, 2);
if (!page.IsNull)
{
// Clone the page for later appending
FIBITMAP temp = FreeImage.Clone(page);
// Unlock the page again
FreeImage.UnlockPage(dib, page, false);
// Delete the page form the multipaged bitmap
FreeImage.DeletePage(dib, 2);
// Append the clone again
FreeImage.AppendPage(dib, temp);
// Check whether the number of pages is still the same
Console.WriteLine("Pages before: {0}. Pages after: {1}", count, FreeImage.GetPageCount(dib));
// Unload clone to prevent memory leak
FreeImage.UnloadEx(ref temp);
}
}
// We are done and close the multipaged bitmap.
if (!FreeImage.CloseMultiBitmapEx(ref dib))
{
Console.WriteLine("Closing bitmap failed!");
}
}
}
}

View File

@@ -0,0 +1,16 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("35960522-c01a-40d2-a86b-37b9839b131c")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,95 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{AF8B72BD-1A8B-4E6B-A0F1-0BD57497777B}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sample02</RootNamespace>
<AssemblyName>Sample02</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="FreeImageNET, Version=3.11.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Bin\FreeImageNET.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="multipaged.tif">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,74 @@
using System;
using System.IO;
using FreeImageAPI;
namespace Sample03
{
class Program
{
static void Main(string[] args)
{
// Check if FreeImage.dll is available (can be in %path%).
if (!FreeImage.IsAvailable())
{
Console.WriteLine("FreeImage.dll seems to be missing. Aborting.");
return;
}
// Add this class to the message event
FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message);
Sample sample = new Sample();
sample.Example();
// Remove this class from the message event
FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message);
}
static void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message)
{
Console.WriteLine("Error for {0}: {1}", fif.ToString(), message);
}
}
public class Sample
{
FIBITMAP dib = new FIBITMAP();
public void Example()
{
// Allocating a new bitmap with 99x99 pixels, 16-bit color depth and an allocation of 5 bits for each color.
dib = FreeImage.Allocate(99, 99, 16, FreeImage.FI16_555_RED_MASK, FreeImage.FI16_555_GREEN_MASK, FreeImage.FI16_555_BLUE_MASK);
// Saving bitmap.
if (!FreeImage.SaveEx(ref dib, "example01.bmp", true))
{
Console.WriteLine("Saving 'example.bmp' failed.");
FreeImage.UnloadEx(ref dib);
}
// Allocation a new bitmap with 71x33 pixels, 4-bit color depth. Bitmaps below 16-bit have paletts.
// Each pixel references an index within the palette wich contains the true color.
// Therefor no bit-masks are needed and can be set to 0.
dib = FreeImage.Allocate(71, 33, 4, 0, 0, 0);
// Saving bitmap.
if (!FreeImage.SaveEx(ref dib, "example02.tif", true))
{
Console.WriteLine("Saving 'example02.tif' failed.");
FreeImage.UnloadEx(ref dib);
}
// Allocation a new bitmap. This time 'AllocateT' is used because 'Allocate' can only create standard bitmaps.
// In this case a RGBF bitmap is created. Red, green and blue are represented by a float-value so no bit-masks are needed.
dib = FreeImage.AllocateT(FREE_IMAGE_TYPE.FIT_RGBF, 50, 75, 9, 0, 0, 0);
// Saving bitmap.
if (!FreeImage.SaveEx(ref dib, "example03.hdr", true))
{
Console.WriteLine("Saving 'example03.hdr' failed.");
FreeImage.UnloadEx(ref dib);
}
}
}
}

View File

@@ -0,0 +1,16 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("7139f1dc-3312-4c76-aeb3-891f869409b3")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,89 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A7E452A1-1A43-47C4-8BF3-DA28E1402FB9}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sample03</RootNamespace>
<AssemblyName>Sample03</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="FreeImageNET, Version=3.11.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Bin\FreeImageNET.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,205 @@
namespace Sample04
{
partial class MainForm
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.ofd = new System.Windows.Forms.OpenFileDialog();
this.bOpenFile = new System.Windows.Forms.Button();
this.lWidth = new System.Windows.Forms.Label();
this.lHeight = new System.Windows.Forms.Label();
this.lBPP = new System.Windows.Forms.Label();
this.lRedMask = new System.Windows.Forms.Label();
this.lGreenMask = new System.Windows.Forms.Label();
this.lBlueMask = new System.Windows.Forms.Label();
this.lImageType = new System.Windows.Forms.Label();
this.lDPIY = new System.Windows.Forms.Label();
this.lDPIX = new System.Windows.Forms.Label();
this.lFormat = new System.Windows.Forms.Label();
this.lHeader = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// ofd
//
this.ofd.Filter = "All files (*.*)|*.*";
//
// bOpenFile
//
this.bOpenFile.Location = new System.Drawing.Point(12, 358);
this.bOpenFile.Name = "bOpenFile";
this.bOpenFile.Size = new System.Drawing.Size(75, 23);
this.bOpenFile.TabIndex = 4;
this.bOpenFile.Text = "Open file";
this.bOpenFile.UseVisualStyleBackColor = true;
this.bOpenFile.Click += new System.EventHandler(this.bOpenFile_Click);
//
// lWidth
//
this.lWidth.AutoSize = true;
this.lWidth.Location = new System.Drawing.Point(9, 51);
this.lWidth.Name = "lWidth";
this.lWidth.Size = new System.Drawing.Size(46, 16);
this.lWidth.TabIndex = 0;
this.lWidth.Text = "Width:";
//
// lHeight
//
this.lHeight.AutoSize = true;
this.lHeight.Location = new System.Drawing.Point(9, 76);
this.lHeight.Name = "lHeight";
this.lHeight.Size = new System.Drawing.Size(53, 16);
this.lHeight.TabIndex = 1;
this.lHeight.Text = "Height: ";
//
// lBPP
//
this.lBPP.AutoSize = true;
this.lBPP.Location = new System.Drawing.Point(9, 101);
this.lBPP.Name = "lBPP";
this.lBPP.Size = new System.Drawing.Size(80, 16);
this.lBPP.TabIndex = 2;
this.lBPP.Text = "Color Depth:";
//
// lRedMask
//
this.lRedMask.AutoSize = true;
this.lRedMask.Location = new System.Drawing.Point(9, 129);
this.lRedMask.Name = "lRedMask";
this.lRedMask.Size = new System.Drawing.Size(68, 16);
this.lRedMask.TabIndex = 3;
this.lRedMask.Text = "Red Mask:";
//
// lGreenMask
//
this.lGreenMask.AutoSize = true;
this.lGreenMask.Location = new System.Drawing.Point(9, 188);
this.lGreenMask.Name = "lGreenMask";
this.lGreenMask.Size = new System.Drawing.Size(80, 16);
this.lGreenMask.TabIndex = 5;
this.lGreenMask.Text = "Green Mask:";
//
// lBlueMask
//
this.lBlueMask.AutoSize = true;
this.lBlueMask.Location = new System.Drawing.Point(9, 158);
this.lBlueMask.Name = "lBlueMask";
this.lBlueMask.Size = new System.Drawing.Size(70, 16);
this.lBlueMask.TabIndex = 6;
this.lBlueMask.Text = "Blue Mask:";
//
// lImageType
//
this.lImageType.AutoSize = true;
this.lImageType.Location = new System.Drawing.Point(9, 215);
this.lImageType.Name = "lImageType";
this.lImageType.Size = new System.Drawing.Size(81, 16);
this.lImageType.TabIndex = 7;
this.lImageType.Text = "Image Type:";
//
// lDPIY
//
this.lDPIY.AutoSize = true;
this.lDPIY.Location = new System.Drawing.Point(9, 244);
this.lDPIY.Name = "lDPIY";
this.lDPIY.Size = new System.Drawing.Size(43, 16);
this.lDPIY.TabIndex = 8;
this.lDPIY.Text = "DPI Y:";
//
// lDPIX
//
this.lDPIX.AutoSize = true;
this.lDPIX.Location = new System.Drawing.Point(9, 273);
this.lDPIX.Name = "lDPIX";
this.lDPIX.Size = new System.Drawing.Size(44, 16);
this.lDPIX.TabIndex = 9;
this.lDPIX.Text = "DPI X:";
//
// lFormat
//
this.lFormat.AutoSize = true;
this.lFormat.Location = new System.Drawing.Point(9, 302);
this.lFormat.Name = "lFormat";
this.lFormat.Size = new System.Drawing.Size(78, 16);
this.lFormat.TabIndex = 10;
this.lFormat.Text = "File Format:";
//
// lHeader
//
this.lHeader.AutoSize = true;
this.lHeader.Location = new System.Drawing.Point(117, 19);
this.lHeader.Name = "lHeader";
this.lHeader.Size = new System.Drawing.Size(162, 16);
this.lHeader.TabIndex = 11;
this.lHeader.Text = "Bitmap-Information Viewer";
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(400, 393);
this.Controls.Add(this.lHeader);
this.Controls.Add(this.lFormat);
this.Controls.Add(this.lDPIX);
this.Controls.Add(this.lDPIY);
this.Controls.Add(this.lImageType);
this.Controls.Add(this.lBlueMask);
this.Controls.Add(this.lGreenMask);
this.Controls.Add(this.bOpenFile);
this.Controls.Add(this.lRedMask);
this.Controls.Add(this.lBPP);
this.Controls.Add(this.lHeight);
this.Controls.Add(this.lWidth);
this.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Sample04";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.OpenFileDialog ofd;
private System.Windows.Forms.Button bOpenFile;
private System.Windows.Forms.Label lWidth;
private System.Windows.Forms.Label lHeight;
private System.Windows.Forms.Label lBPP;
private System.Windows.Forms.Label lRedMask;
private System.Windows.Forms.Label lGreenMask;
private System.Windows.Forms.Label lBlueMask;
private System.Windows.Forms.Label lImageType;
private System.Windows.Forms.Label lDPIY;
private System.Windows.Forms.Label lDPIX;
private System.Windows.Forms.Label lFormat;
private System.Windows.Forms.Label lHeader;
}
}

View File

@@ -0,0 +1,120 @@
using System;
using System.Windows.Forms;
using FreeImageAPI;
namespace Sample04
{
public partial class MainForm : Form
{
string message = null;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
public MainForm()
{
InitializeComponent();
FreeImageEngine.Message += new OutputMessageFunction(FreeImage_Message);
}
~MainForm()
{
FreeImageEngine.Message -= new OutputMessageFunction(FreeImage_Message);
}
void FreeImage_Message(FREE_IMAGE_FORMAT fif, string message)
{
if (this.message == null)
{
this.message = message;
}
else
{
this.message += "\n" + message;
}
}
private void bOpenFile_Click(object sender, EventArgs e)
{
// Resetting filename
ofd.FileName = "";
// Was a file selected
if (ofd.ShowDialog() == DialogResult.OK)
{
// Format is stored in 'format' on successfull load.
FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
// Try loading the file
FIBITMAP dib = FreeImage.LoadEx(ofd.FileName, ref format);
try
{
// Error handling
if (dib.IsNull)
{
// Chech whether FreeImage generated an error messe
if (message != null)
{
MessageBox.Show("File could not be loaded!\nError:{0}", message);
}
else
{
MessageBox.Show("File could not be loaded!", message);
}
return;
}
// Read width
lWidth.Text = String.Format("Width: {0}", FreeImage.GetWidth(dib));
// Read height
lHeight.Text = String.Format("Width: {0}", FreeImage.GetWidth(dib));
// Read color depth
lBPP.Text = String.Format("Color Depth: {0}", FreeImage.GetBPP(dib));
// Read red bitmask (16 - 32 bpp)
lRedMask.Text = String.Format("Red Mask: 0x{0:X8}", FreeImage.GetRedMask(dib));
// Read green bitmask (16 - 32 bpp)
lBlueMask.Text = String.Format("Green Mask: 0x{0:X8}", FreeImage.GetGreenMask(dib));
// Read blue bitmask (16 - 32 bpp)
lGreenMask.Text = String.Format("Blue Mask: 0x{0:X8}", FreeImage.GetBlueMask(dib));
// Read image type (FI_BITMAP, FIT_RGB16, FIT_COMPLEX ect)
lImageType.Text = String.Format("Image Type: {0}", FreeImage.GetImageType(dib));
// Read x-axis dpi
lDPIX.Text = String.Format("DPI X: {0}", FreeImage.GetResolutionX(dib));
// Read y-axis dpi
lDPIY.Text = String.Format("DPI Y: {0}", FreeImage.GetResolutionY(dib));
// Read file format
lFormat.Text = String.Format("File Format: {0}", FreeImage.GetFormatFromFIF(format));
}
catch
{
}
// Always unload bitmap
FreeImage.UnloadEx(ref dib);
// Reset the error massage buffer
message = null;
}
// No file was selected
else
{
MessageBox.Show("No file loaded.", "Error");
}
}
}
}

View File

@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ofd.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@@ -0,0 +1,16 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("7c8fdc9a-a8f9-4996-99c8-9df47513edeb")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,102 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{1F4BCDD7-5BD9-4237-8B14-C52B2A9FF52A}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sample04</RootNamespace>
<AssemblyName>Sample04</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="FreeImageNET, Version=3.11.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Bin\FreeImageNET.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="MainForm.resx">
<SubType>Designer</SubType>
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,213 @@
using System;
using FreeImageAPI;
using System.Drawing;
namespace Sample05
{
class Program
{
static void Main(string[] args)
{
// Check if FreeImage.dll is available (can be in %path%).
if (!FreeImage.IsAvailable())
{
Console.WriteLine("FreeImage.dll seems to be missing. Aborting.");
return;
}
Sample sample = new Sample();
// The example will flip the bitmap by manually accessing the
// bitmaps scanlines and swapping them
sample.Example01();
// The example will access each pixel of the bitmap manually
// and change its color intensity to 3/4 of the original value
// which will have a darker bitmap as result.
sample.Example02();
// The example will access and swap the bitmaps palette from
// 'FIC_MINISBLACK' to 'FIC_MINISWHITE'. Then it will swap each pixels
// palette index so that each pixel is assigned to the its old value
// so that the bitmaps "pixeldata" stays the same.
sample.Example03();
}
}
public class Sample
{
FIBITMAP dib = new FIBITMAP();
public void Example01()
{
// Load sample file
dib = FreeImage.LoadEx("Sample.jpg", FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE);
// Check whether loading succeeded
if (dib.IsNull)
{
Console.WriteLine("Sample.jpg could not be loaded. Aborting.");
return;
}
// Check whether the bitmap has 24 bpp color depth to ensure
// using RGBTRIPPLE is correct.
if (FreeImage.GetBPP(dib) != 24)
{
Console.WriteLine("Sample.jpg is no 24 bpp bitmap. Aborting.");
FreeImage.UnloadEx(ref dib);
return;
}
// Store height of the bitmap
int height = (int)FreeImage.GetHeight(dib);
// Iterate over half of the bitmaps scanlines and swap
// line[1] with line[height], line[2] with line[height-1] etc which will
// flip the image.
for (int i = 0; i < (height / 2); i++)
{
// Get scanline from the bottom part of the bitmap
Scanline<RGBTRIPLE> scanlineBottom = new Scanline<RGBTRIPLE>(dib, i);
// Get scanline from the top part of the bitmap
Scanline<RGBTRIPLE> scanlineTop = new Scanline<RGBTRIPLE>(dib, height - 1 - i);
// Get arrays of RGBTRIPPLEs that contain the bitmaps real pixel data
// of the two scanlines.
RGBTRIPLE[] rgbtBottom = scanlineBottom.Data;
RGBTRIPLE[] rgbtTop = scanlineTop.Data;
// Restore the scanline across to switch the bitmaps lines.
scanlineBottom.Data = rgbtTop;
scanlineTop.Data = rgbtBottom;
}
// Store the bitmap to disk
if (!FreeImage.SaveEx(ref dib, "SampleOut01.jpg", FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD, true))
{
Console.WriteLine("Error while saving 'SampleOut01.jpg'");
FreeImage.UnloadEx(ref dib);
}
}
public void Example02()
{
dib = FreeImage.LoadEx("Sample.jpg", FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE);
// Check whether loading succeeded
if (dib.IsNull)
{
Console.WriteLine("Sample.jpg could not be loaded. Aborting.");
return;
}
// Check whether the bitmap has 24 bpp color depth to ensure
// using RGBTRIPPLE is correct.
if (FreeImage.GetBPP(dib) != 24)
{
Console.WriteLine("Sample.jpg is no 24 bpp bitmap. Aborting.");
FreeImage.UnloadEx(ref dib);
return;
}
// Iterate over all scanlines
for (int i = 0; i < FreeImage.GetHeight(dib); i++)
{
// Get scanline
Scanline<RGBTRIPLE> scanline = new Scanline<RGBTRIPLE>(dib, i);
// Get pixeldata from scanline
RGBTRIPLE[] rgbt = scanline.Data;
// Iterate over each pixel reducing the colors intensity to 3/4 which
// will darken the bitmap.
for (int j = 0; j < rgbt.Length; j++)
{
rgbt[j].rgbtBlue = (byte)((int)rgbt[j].rgbtBlue * 3 / 4);
rgbt[j].rgbtGreen = (byte)((int)rgbt[j].rgbtGreen * 3 / 4);
rgbt[j].rgbtRed = (byte)((int)rgbt[j].rgbtRed * 3 / 4);
// In case no direct access to the data is implemented
// the following way is equivalent:
//
// Color color = rgbt[j].color;
// rgbt[j].color = Color.FromArgb(color.R * 3 / 4, color.G * 3 / 4, color.B * 3 / 4);
}
// Write the darkened scanline back to memory
scanline.Data = rgbt;
}
// Store the bitmap to disk
if (!FreeImage.SaveEx(ref dib, "SampleOut02.jpg", FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD, true))
{
Console.WriteLine("Error while saving 'SampleOut02.jpg'");
FreeImage.UnloadEx(ref dib);
}
}
public void Example03()
{
dib = FreeImage.LoadEx("Sample.tif");
// Check whether loading succeeded
if (dib.IsNull)
{
Console.WriteLine("Sample.tif could not be loaded. Aborting.");
return;
}
// Check whether the bitmap has 4 bpp color depth to ensure
// using FI4B is correct.
if (FreeImage.GetBPP(dib) != 4)
{
Console.WriteLine("Sample.tif is no 4 bpp bitmap. Aborting.");
FreeImage.UnloadEx(ref dib);
return;
}
// Get the bitmaps palette
Palette palette = FreeImage.GetPaletteEx(dib);
int size = (int)palette.Length;
// Check whether the palette has a color (is valid)
if (size == 0)
{
Console.WriteLine("Sample.tif has no valid palette. Aborting.");
FreeImage.UnloadEx(ref dib);
return;
}
// Swapping the palette
for (int i = 0; i < size / 2; i++)
{
RGBQUAD temp = palette[i];
palette[i] = palette[size - 1 - i];
palette[size - 1 - i] = temp;
}
// Iterate over each scanline
for (int i = 0; i < FreeImage.GetHeight(dib); i++)
{
// Get scanline
Scanline<FI4BIT> scanline = new Scanline<FI4BIT>(dib, i);
// Iterate over all pixels swapping the palette index
// so that the color will stay the same
for (int j = 0; j < scanline.Length; j++)
{
scanline[j] = (byte)(size - 1 - scanline[j]);
}
}
// Save the bitmap to disk
if (!FreeImage.SaveEx(ref dib, "SampleOut03.tif", FREE_IMAGE_SAVE_FLAGS.TIFF_LZW, true))
{
Console.WriteLine("Error while saving 'SampleOut03.tif'");
FreeImage.UnloadEx(ref dib);
}
}
}
}

View File

@@ -0,0 +1,16 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("fd43331d-5ea4-40f8-86d5-8f820d606912")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,98 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A501F134-8FB6-460B-AFE9-884A696C1C07}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sample05</RootNamespace>
<AssemblyName>Sample05</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="FreeImageNET, Version=3.11.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Bin\FreeImageNET.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<None Include="Sample.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Sample.tif">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@@ -0,0 +1,120 @@
namespace Sample06
{
partial class MainForm
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.picBox = new System.Windows.Forms.PictureBox();
this.bExample01 = new System.Windows.Forms.Button();
this.bOriginal = new System.Windows.Forms.Button();
this.bExample02 = new System.Windows.Forms.Button();
this.bExample03 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.picBox)).BeginInit();
this.SuspendLayout();
//
// picBox
//
this.picBox.BackColor = System.Drawing.Color.White;
this.picBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.picBox.Location = new System.Drawing.Point(12, 12);
this.picBox.Name = "picBox";
this.picBox.Size = new System.Drawing.Size(747, 465);
this.picBox.TabIndex = 0;
this.picBox.TabStop = false;
//
// bExample01
//
this.bExample01.Location = new System.Drawing.Point(93, 483);
this.bExample01.Name = "bExample01";
this.bExample01.Size = new System.Drawing.Size(88, 23);
this.bExample01.TabIndex = 1;
this.bExample01.Text = "Example 01";
this.bExample01.UseVisualStyleBackColor = true;
this.bExample01.Click += new System.EventHandler(this.bExample01_Click);
//
// bOriginal
//
this.bOriginal.Location = new System.Drawing.Point(12, 483);
this.bOriginal.Name = "bOriginal";
this.bOriginal.Size = new System.Drawing.Size(75, 23);
this.bOriginal.TabIndex = 2;
this.bOriginal.Text = "Original";
this.bOriginal.UseVisualStyleBackColor = true;
this.bOriginal.Click += new System.EventHandler(this.bOriginal_Click);
//
// bExample02
//
this.bExample02.Location = new System.Drawing.Point(187, 483);
this.bExample02.Name = "bExample02";
this.bExample02.Size = new System.Drawing.Size(88, 23);
this.bExample02.TabIndex = 3;
this.bExample02.Text = "Example 02";
this.bExample02.UseVisualStyleBackColor = true;
this.bExample02.Click += new System.EventHandler(this.bExample02_Click);
//
// bExample03
//
this.bExample03.Location = new System.Drawing.Point(281, 483);
this.bExample03.Name = "bExample03";
this.bExample03.Size = new System.Drawing.Size(88, 23);
this.bExample03.TabIndex = 4;
this.bExample03.Text = "Example 03";
this.bExample03.UseVisualStyleBackColor = true;
this.bExample03.Click += new System.EventHandler(this.bExample03_Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(771, 518);
this.Controls.Add(this.bExample03);
this.Controls.Add(this.bExample02);
this.Controls.Add(this.bOriginal);
this.Controls.Add(this.bExample01);
this.Controls.Add(this.picBox);
this.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Sample06";
((System.ComponentModel.ISupportInitialize)(this.picBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox picBox;
private System.Windows.Forms.Button bExample01;
private System.Windows.Forms.Button bOriginal;
private System.Windows.Forms.Button bExample02;
private System.Windows.Forms.Button bExample03;
}
}

View File

@@ -0,0 +1,177 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using FreeImageAPI;
using System.Drawing.Imaging;
namespace Sample06
{
public partial class MainForm : Form
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
public MainForm()
{
InitializeComponent();
}
private void bExample01_Click(object sender, EventArgs e)
{
// Load bitmap
FIBITMAP dib = FreeImage.LoadEx("Sample.jpg");
// Check success
if (dib.IsNull)
{
MessageBox.Show("Could not load Sample.jpg", "Error");
return;
}
// Check whether bitmap is 24-bit
if (FreeImage.GetBPP(dib) != 24)
{
MessageBox.Show("Sample.jpg is not 24-bit.", "Error");
FreeImage.UnloadEx(ref dib);
return;
}
// Convert the 24-bit bitmap to 8-bit and forcing the result will be greyscale
dib = FreeImage.ConvertColorDepth(dib, FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP | FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE, true);
if (FreeImage.GetBPP(dib) == 8)
{
// Convert the FreeImage-Bitmap into a .NET bitmap
Bitmap bitmap = FreeImage.GetBitmap(dib);
// Dispose the bitmap of the pictureBox
if (picBox.Image != null)
{
picBox.Image.Dispose();
}
// Assign the bitmap to the picturebox
picBox.Image = bitmap;
}
// Unload source bitmap
FreeImage.UnloadEx(ref dib);
}
private void bOriginal_Click(object sender, EventArgs e)
{
// Load bitmap
FIBITMAP dib = FreeImage.LoadEx("Sample.jpg");
// Check success
if (dib.IsNull)
{
MessageBox.Show("Could not load Sample.jpg", "Error");
return;
}
// Convert the FreeImage-Bitmap into a .NET bitmap
Bitmap bitmap = FreeImage.GetBitmap(dib);
// Check success
if (bitmap != null)
{
// Dispose old bitmap
if (picBox.Image != null)
{
picBox.Image.Dispose();
}
// Assign new bitmap
picBox.Image = bitmap;
}
// Unload bitmap
FreeImage.UnloadEx(ref dib);
}
private void bExample02_Click(object sender, EventArgs e)
{
FIBITMAP dib = FreeImage.LoadEx("Sample.jpg");
// Check success
if (dib.IsNull)
{
MessageBox.Show("Could not load Sample.jpg", "Error");
return;
}
// Convert bitmap to 8 bit
dib = FreeImage.ConvertColorDepth(dib, FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP, true);
// Check whether conversion succeeded
if (FreeImage.GetBPP(dib) != 8)
{
MessageBox.Show("Converting Sample.jpg to 8-bit failed.", "Error");
FreeImage.UnloadEx(ref dib);
return;
}
// Convert the FreeImage-Bitmap into a .NET bitmap
Bitmap bitmap = FreeImage.GetBitmap(dib);
// Dispose old bitmap
if (picBox.Image != null)
{
picBox.Image.Dispose();
}
// Assign new bitmap
picBox.Image = bitmap;
// Unload bitmap
FreeImage.UnloadEx(ref dib);
}
private void bExample03_Click(object sender, EventArgs e)
{
// Load bitmap
Bitmap bitmap = (Bitmap)Bitmap.FromFile("Sample.jpg");
// Convert the .NET bitmap into a FreeImage-Bitmap
FIBITMAP dib = FreeImage.CreateFromBitmap(bitmap);
// Unload bitmap
bitmap.Dispose();
// Rescale the bitmap
FIBITMAP temp = FreeImage.Rescale(dib, 300, 300, FREE_IMAGE_FILTER.FILTER_BICUBIC);
// Unload bitmap
FreeImage.UnloadEx(ref dib);
Random rand = new Random();
// Rotate the bitmap
dib = FreeImage.Rotate(temp, rand.NextDouble() * 360d);
// Unload bitmap
FreeImage.UnloadEx(ref temp);
// Convert the FreeImage-Bitmap into a .NET bitmap
bitmap = FreeImage.GetBitmap(dib);
// Unload bitmap
FreeImage.UnloadEx(ref dib);
// Unload bitmap
if (picBox.Image != null)
{
picBox.Image.Dispose();
}
// Assign new bitmap
picBox.Image = bitmap;
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,16 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("69a8cbdd-43da-49e3-8d0b-2680c4ca2851")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,107 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E2EA945D-E22C-47B3-9DD9-3A0B07FA3F81}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sample06</RootNamespace>
<AssemblyName>Sample06</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="FreeImageNET, Version=3.11.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Bin\FreeImageNET.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="MainForm.resx">
<SubType>Designer</SubType>
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Sample.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

View File

@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using FreeImageAPI;
namespace Sample07
{
class Program
{
static void Main(string[] args)
{
// Check if FreeImage.dll is available (can be in %path%).
if (!FreeImage.IsAvailable())
{
Console.WriteLine("FreeImage.dll seems to be missing. Aborting.");
return;
}
Sample sample = new Sample();
// This example shows how to work with ICC-Profiles.
sample.Example();
}
}
public class Sample
{
public void Example()
{
// Load the sample bitmap.
FIBITMAP dib = FreeImage.LoadEx("Sample.jpg");
// Check success
if (dib.IsNull)
{
Console.WriteLine("Sample.jpg could not be loaded. Aborting.");
return;
}
// Get the bitmaps ICC-Profile.
FIICCPROFILE icc = FreeImage.GetICCProfileEx(dib);
// Print the profiles address.
Console.WriteLine("The profiles memory-address is : 0x{0}", icc.DataPointer.ToString("X"));
// Print the profiles size
Console.WriteLine("The profiles size is : {0} bytes", icc.Size);
// Create data for a new profile.
byte[] data = new byte[256];
for (int i = 0; i < data.Length; i++)
data[i] = (byte)i;
// Create the new profile
icc = new FIICCPROFILE(dib, data);
Console.WriteLine("The profiles memory-address is : 0x{0}", icc.DataPointer.ToString("X"));
Console.WriteLine("The profiles size is : {0} bytes", icc.Size);
// Create the new profile but only use the first 64 bytes
icc = new FIICCPROFILE(dib, data, 64);
Console.WriteLine("The profiles memory-address is : 0x{0}", icc.DataPointer.ToString("X"));
Console.WriteLine("The profiles size is : {0} bytes", icc.Size);
// CreateICCProfileEx(...) does the same as above
icc = FreeImage.CreateICCProfileEx(dib, data, 16);
Console.WriteLine("The profiles memory-address is : 0x{0}", icc.DataPointer.ToString("X"));
Console.WriteLine("The profiles size is : {0} bytes", icc.Size);
FreeImage.UnloadEx(ref dib);
}
}
}

View File

@@ -0,0 +1,16 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("c9991d1d-684a-4736-b088-369a216b35b6")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,94 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{3B1BB976-64A7-41FD-B7E2-59104161AF7E}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sample07</RootNamespace>
<AssemblyName>Sample07</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>
</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="FreeImageNET, Version=3.11.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Bin\FreeImageNET.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Sample.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Some files were not shown because too many files have changed in this diff Show More