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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
24
DSTexCompress/FreeImage/Examples/Linux/Makefile
Normal file
24
DSTexCompress/FreeImage/Examples/Linux/Makefile
Normal 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
|
||||
100
DSTexCompress/FreeImage/Examples/Linux/linux-gtk.c
Normal file
100
DSTexCompress/FreeImage/Examples/Linux/linux-gtk.c
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
96
DSTexCompress/FreeImage/Examples/Linux/linux-svgalib.c
Normal file
96
DSTexCompress/FreeImage/Examples/Linux/linux-svgalib.c
Normal 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;
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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
|
||||
@@ -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!
|
||||
253
DSTexCompress/FreeImage/Examples/Plugin/PluginCradle.cpp
Normal file
253
DSTexCompress/FreeImage/Examples/Plugin/PluginCradle.cpp
Normal 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;
|
||||
}
|
||||
45
DSTexCompress/FreeImage/Examples/Plugin/PluginCradle.h
Normal file
45
DSTexCompress/FreeImage/Examples/Plugin/PluginCradle.h
Normal 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
|
||||
Reference in New Issue
Block a user