import
This commit is contained in:
214
DSTexCompress/FreeImage/Examples/Generic/BatchLoad.cpp
Normal file
214
DSTexCompress/FreeImage/Examples/Generic/BatchLoad.cpp
Normal 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;
|
||||
}
|
||||
112
DSTexCompress/FreeImage/Examples/Generic/CloneMultiPage.cpp
Normal file
112
DSTexCompress/FreeImage/Examples/Generic/CloneMultiPage.cpp
Normal 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;
|
||||
}
|
||||
181
DSTexCompress/FreeImage/Examples/Generic/CreateAlpha.cpp
Normal file
181
DSTexCompress/FreeImage/Examples/Generic/CreateAlpha.cpp
Normal 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;
|
||||
}
|
||||
149
DSTexCompress/FreeImage/Examples/Generic/FIFImportExport.cpp
Normal file
149
DSTexCompress/FreeImage/Examples/Generic/FIFImportExport.cpp
Normal 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;
|
||||
|
||||
}
|
||||
146
DSTexCompress/FreeImage/Examples/Generic/FIIO_Mem.cpp
Normal file
146
DSTexCompress/FreeImage/Examples/Generic/FIIO_Mem.cpp
Normal 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
|
||||
74
DSTexCompress/FreeImage/Examples/Generic/FIIO_Mem.h
Normal file
74
DSTexCompress/FreeImage/Examples/Generic/FIIO_Mem.h
Normal 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
|
||||
145
DSTexCompress/FreeImage/Examples/Generic/LoadFromHandle.cpp
Normal file
145
DSTexCompress/FreeImage/Examples/Generic/LoadFromHandle.cpp
Normal 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;
|
||||
}
|
||||
@@ -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 );
|
||||
}
|
||||
113
DSTexCompress/FreeImage/Examples/Generic/LoadFromMemory.cpp
Normal file
113
DSTexCompress/FreeImage/Examples/Generic/LoadFromMemory.cpp
Normal 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;
|
||||
}
|
||||
317
DSTexCompress/FreeImage/Examples/Generic/ShowMetadata.cpp
Normal file
317
DSTexCompress/FreeImage/Examples/Generic/ShowMetadata.cpp
Normal 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>" << " " << "</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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user