File: FIFImportExport.cpp

package info (click to toggle)
freeimage 3.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 18,864 kB
  • ctags: 21,425
  • sloc: ansic: 150,658; cpp: 57,288; pascal: 2,899; cs: 786; sh: 574; makefile: 394; asm: 284
file content (149 lines) | stat: -rw-r--r-- 5,016 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// ==========================================================
// Plugin functions demonstration
//
// Design and implementation by 
// - Herv 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;

}