1
// ==========================================================
4
// Design and implementation by
5
// - Marcos Pernambuco Motta (marcos.pernambuco@gmail.com)
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
19
// Use at your own risk!
20
// ==========================================================
24
#include "FreeImage.h"
26
using namespace System;
27
using namespace System::IO;
28
using namespace System::Runtime::InteropServices;
32
unsigned __stdcall ReadProc (void *buffer, unsigned size, unsigned count, fi_handle handle);
33
unsigned __stdcall WriteProc (void *buffer, unsigned size, unsigned count, fi_handle handle);
34
int __stdcall SeekProc (fi_handle handle, long offset, int origin);
35
long __stdcall TellProc(fi_handle handle);
38
__nogc struct UNMANAGED_HANDLER {
40
read_proc = &ReadProc;
41
write_proc = WriteProc;
45
FI_ReadProc read_proc; // pointer to the function used to read data
46
FI_WriteProc write_proc; // pointer to the function used to write data
47
FI_SeekProc seek_proc; // pointer to the function used to seek
48
FI_TellProc tell_proc; // pointer to the function used to aquire the current position
49
gcroot<System::IO::Stream*> _stream;
54
#define FREEIMAGE_DLL "freeimaged.dll"
56
namespace FreeImageIODotNet
58
__gc public class FreeImageStream
61
struct UNMANAGED_HANDLER* _pUnmanaged;
63
FreeImageStream(System::IO::Stream* stream)
65
FreeImage_SaveToHandle((FREE_IMAGE_FORMAT) 1,0,0,0,0);
66
_pUnmanaged = new struct UNMANAGED_HANDLER;
67
_pUnmanaged->_stream = stream;
71
_pUnmanaged->_stream = NULL;
75
bool SaveImage(FREE_IMAGE_FORMAT fif, unsigned int dib, int flags) {
76
return (bool)FreeImage_SaveToHandle(fif,(FIBITMAP*) dib,(FreeImageIO*)_pUnmanaged,(fi_handle)_pUnmanaged,flags);
79
unsigned int LoadImage(FREE_IMAGE_FORMAT fif, int flags) {
80
return (unsigned int)FreeImage_LoadFromHandle(fif,(FreeImageIO*)_pUnmanaged,(fi_handle)_pUnmanaged,flags);