1
// ==========================================================
2
// Multipage functions demonstration
4
// Design and implementation by
7
// This file is part of FreeImage 3
9
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
10
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
11
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
12
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
13
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
14
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
15
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
16
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
20
// ==========================================================
22
// This sample shows how to clone a multipage TIFF
24
// Functions used in this sample :
25
// FreeImage_OpenMultiBitmap, FreeImage_GetPageCount, FreeImage_LockPage,
26
// FreeImage_AppendPage, FreeImage_UnlockPage, FreeImage_CloseMultiBitmap;
27
// FreeImage_SetOutputMessage
29
// ==========================================================
35
#include "FreeImage.h"
37
// ----------------------------------------------------------
40
FreeImage error handler
42
void MyMessageFunc(FREE_IMAGE_FORMAT fif, const char *message) {
43
cout << "\n*** " << message << " ***\n";
47
// ----------------------------------------------------------
49
bool CloneMultiPage(FREE_IMAGE_FORMAT fif, char *input, char *output, int output_flag) {
51
BOOL bMemoryCache = TRUE;
53
// Open src file (read-only, use memory cache)
54
FIMULTIBITMAP *src = FreeImage_OpenMultiBitmap(fif, input, FALSE, TRUE, bMemoryCache);
57
// Open dst file (creation, use memory cache)
58
FIMULTIBITMAP *dst = FreeImage_OpenMultiBitmap(fif, output, TRUE, FALSE, bMemoryCache);
61
int count = FreeImage_GetPageCount(src);
64
for(int page = 0; page < count; page++) {
65
// Load the bitmap at position 'page'
66
FIBITMAP *dib = FreeImage_LockPage(src, page);
68
// add a new bitmap to dst
69
FreeImage_AppendPage(dst, dib);
70
// Unload the bitmap (do not apply any change to src)
71
FreeImage_UnlockPage(src, dib, FALSE);
76
FreeImage_CloseMultiBitmap(src, 0);
78
FreeImage_CloseMultiBitmap(dst, output_flag);
88
main(int argc, char *argv[]) {
90
char *input_filename = "images\\input.tif";
91
char *output_filename = "images\\clone.tif";
93
// call this ONLY when linking with FreeImage as a static library
95
FreeImage_Initialise();
96
#endif // FREEIMAGE_LIB
98
// initialize our own FreeImage error handler
100
FreeImage_SetOutputMessage(MyMessageFunc);
102
// Copy 'input.tif' to 'clone.tif'
104
CloneMultiPage(FIF_TIFF, input_filename, output_filename, 0);
106
// call this ONLY when linking with FreeImage as a static library
108
FreeImage_DeInitialise();
109
#endif // FREEIMAGE_LIB