/[projet1]/public/pc/shared_libraries/freeimage/v3.12.0/Examples/Generic/LoadFromMemory-classified.cpp
Defence Force logotype

Contents of /public/pc/shared_libraries/freeimage/v3.12.0/Examples/Generic/LoadFromMemory-classified.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 126 - (show annotations)
Mon Jul 13 12:20:10 2009 UTC (10 years, 10 months ago) by dbug
File size: 2966 byte(s)
Added some shared libraries (UnitTest++, and FreeImage) to avoid having every single project brings its own libraries.
Ideally people should add them in a way we can upgrade versions without breaking things:
-> public/pc/shared_libraries/library_name/library_version/actuall_content
1 // ==========================================================
2 // Classified FreeImageIO handler
3 //
4 // Design and implementation by
5 // - schickb (schickb@hotmail.com)
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 your own risk!
20 // ==========================================================
21
22 class MemIO : public FreeImageIO {
23 public :
24 MemIO( BYTE *data ) : _start(data), _cp(data) {
25 read_proc = _ReadProc;
26 write_proc = _WriteProc;
27 tell_proc = _TellProc;
28 seek_proc = _SeekProc;
29 }
30
31 void Reset() {
32 _cp = _start;
33 }
34
35 static unsigned _ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle);
36 static unsigned _WriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle);
37 static int _SeekProc(fi_handle handle, long offset, int origin);
38 static long _TellProc(fi_handle handle);
39
40 private:
41 BYTE * const _start;
42 BYTE *_cp;
43 };
44
45
46 unsigned
47 MemIO::_ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) {
48 MemIO *memIO = (MemIO*)handle;
49
50 BYTE *tmp = (BYTE *)buffer;
51
52 for (unsigned c = 0; c < count; c++) {
53 memcpy(tmp, memIO->_cp, size);
54
55 memIO->_cp = memIO->_cp + size;
56
57 tmp += size;
58 }
59
60 return count;
61 }
62
63 unsigned
64 MemIO::_WriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) {
65 ASSERT( false );
66 return size;
67 }
68
69 int
70 MemIO::_SeekProc(fi_handle handle, long offset, int origin) {
71 ASSERT(origin != SEEK_END);
72
73 MemIO *memIO = (MemIO*)handle;
74
75 if (origin == SEEK_SET)
76 memIO->_cp = memIO->_start + offset;
77 else
78 memIO->_cp = memIO->_cp + offset;
79
80 return 0;
81 }
82
83 long
84 MemIO::_TellProc(fi_handle handle) {
85 MemIO *memIO = (MemIO*)handle;
86
87 return memIO->_cp - memIO->_start;
88 }
89
90 // ----------------------------------------------------------
91 // PSEUDOCODE... HELPS TO UNDERSTAND HOW THE MEMIO CLASS WORKS
92 // ----------------------------------------------------------
93
94 int
95 main(int argc, char *argv[]) {
96 BYTE *data = loadimagesomehow();
97
98 MemIO memIO(data);
99
100 FIBITMAP *fbmp = FreeImage_LoadFromHandle( fif, &memIO, (fi_handle)&memIO );
101 }

  ViewVC Help
Powered by ViewVC 1.1.26