~ubuntu-branches/ubuntu/gutsy/freeimage/gutsy

« back to all changes in this revision

Viewing changes to FreeImage/Examples/Generic/CloneMultiPage.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Federico Di Gregorio
  • Date: 2007-05-07 15:35:21 UTC
  • Revision ID: james.westby@ubuntu.com-20070507153521-m4lx765bzxxug9qf
Tags: upstream-3.9.3
Import upstream version 3.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ==========================================================
 
2
// Multipage functions demonstration
 
3
//
 
4
// Design and implementation by 
 
5
// - Herv� Drolon
 
6
//
 
7
// This file is part of FreeImage 3
 
8
//
 
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
 
17
// THIS DISCLAIMER.
 
18
//
 
19
// Use at own risk!
 
20
// ==========================================================
 
21
 
 
22
// This sample shows how to clone a multipage TIFF
 
23
//
 
24
// Functions used in this sample : 
 
25
// FreeImage_OpenMultiBitmap, FreeImage_GetPageCount, FreeImage_LockPage, 
 
26
// FreeImage_AppendPage, FreeImage_UnlockPage, FreeImage_CloseMultiBitmap; 
 
27
// FreeImage_SetOutputMessage
 
28
//
 
29
// ==========================================================
 
30
 
 
31
#include <iostream.h>
 
32
#include <stdio.h>
 
33
#include <string.h>
 
34
 
 
35
#include "FreeImage.h"
 
36
 
 
37
// ----------------------------------------------------------
 
38
 
 
39
/**
 
40
        FreeImage error handler
 
41
*/
 
42
void MyMessageFunc(FREE_IMAGE_FORMAT fif, const char *message) {
 
43
        cout << "\n*** " << message << " ***\n";
 
44
        cout.flush();
 
45
}
 
46
 
 
47
// ----------------------------------------------------------
 
48
 
 
49
bool CloneMultiPage(FREE_IMAGE_FORMAT fif, char *input, char *output, int output_flag) {
 
50
 
 
51
        BOOL bMemoryCache = TRUE;
 
52
 
 
53
        // Open src file (read-only, use memory cache)
 
54
        FIMULTIBITMAP *src = FreeImage_OpenMultiBitmap(fif, input, FALSE, TRUE, bMemoryCache);
 
55
 
 
56
        if(src) {
 
57
                // Open dst file (creation, use memory cache)
 
58
                FIMULTIBITMAP *dst = FreeImage_OpenMultiBitmap(fif, output, TRUE, FALSE, bMemoryCache);
 
59
 
 
60
                // Get src page count
 
61
                int count = FreeImage_GetPageCount(src);
 
62
 
 
63
                // Clone src to dst
 
64
                for(int page = 0; page < count; page++) {
 
65
                        // Load the bitmap at position 'page'
 
66
                        FIBITMAP *dib = FreeImage_LockPage(src, page);
 
67
                        if(dib) {
 
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);
 
72
                        }
 
73
                }
 
74
 
 
75
                // Close src
 
76
                FreeImage_CloseMultiBitmap(src, 0);
 
77
                // Save and close dst
 
78
                FreeImage_CloseMultiBitmap(dst, output_flag);
 
79
 
 
80
                return true;
 
81
        }
 
82
 
 
83
        return false;
 
84
}
 
85
 
 
86
 
 
87
int 
 
88
main(int argc, char *argv[]) {
 
89
 
 
90
        char *input_filename = "images\\input.tif";
 
91
        char *output_filename = "images\\clone.tif";
 
92
 
 
93
        // call this ONLY when linking with FreeImage as a static library
 
94
#ifdef FREEIMAGE_LIB
 
95
        FreeImage_Initialise();
 
96
#endif // FREEIMAGE_LIB
 
97
 
 
98
        // initialize our own FreeImage error handler
 
99
 
 
100
        FreeImage_SetOutputMessage(MyMessageFunc);
 
101
 
 
102
        // Copy 'input.tif' to 'clone.tif'
 
103
 
 
104
        CloneMultiPage(FIF_TIFF, input_filename, output_filename, 0);
 
105
 
 
106
        // call this ONLY when linking with FreeImage as a static library
 
107
#ifdef FREEIMAGE_LIB
 
108
        FreeImage_DeInitialise();
 
109
#endif // FREEIMAGE_LIB
 
110
 
 
111
        return 0;
 
112
}