~cosme/ubuntu/precise/freeimage/freeimage-3.15.1

« back to all changes in this revision

Viewing changes to Wrapper/FreeImage.NET/cpp/FreeImageIO/FreeImageIO.Net.h

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-07-20 13:42:15 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100720134215-xt1454zaedv3b604
Tags: 3.13.1-0ubuntu1
* New upstream release. Closes: (LP: #607800)
 - Updated debian/freeimage-get-orig-source script.
 - Removing no longer necessary debian/patches/* and
   the patch system in debian/rules.
 - Updated debian/rules to work with the new Makefiles.
 - Drop from -O3 to -O2 and use lzma compression saves
   ~10 MB of free space. 
* lintian stuff
 - fixed debhelper-but-no-misc-depends
 - fixed ldconfig-symlink-missing-for-shlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ==========================================================
 
2
// FreeImageIO.Net 
 
3
//
 
4
// Design and implementation by
 
5
// - Marcos Pernambuco Motta (marcos.pernambuco@gmail.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
#pragma once
 
23
#include <vcclr.h>
 
24
#include "FreeImage.h"
 
25
 
 
26
using namespace System;
 
27
using namespace System::IO;
 
28
using namespace System::Runtime::InteropServices;
 
29
 
 
30
extern "C" {
 
31
        // forward decls
 
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);  
 
36
 
 
37
        #pragma pack(push, 1)
 
38
        __nogc struct UNMANAGED_HANDLER {
 
39
                UNMANAGED_HANDLER() {
 
40
                        read_proc  = &ReadProc;
 
41
                        write_proc = WriteProc;
 
42
                        seek_proc  = SeekProc;
 
43
                        tell_proc  = TellProc;
 
44
                }
 
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;
 
50
        };
 
51
        #pragma pack(pop)
 
52
}
 
53
 
 
54
#define FREEIMAGE_DLL "freeimaged.dll"
 
55
 
 
56
namespace FreeImageIODotNet
 
57
{
 
58
        __gc public class FreeImageStream
 
59
        {       
 
60
        private:
 
61
                struct UNMANAGED_HANDLER* _pUnmanaged;
 
62
        public:                 
 
63
                FreeImageStream(System::IO::Stream* stream)
 
64
                {
 
65
                        FreeImage_SaveToHandle((FREE_IMAGE_FORMAT) 1,0,0,0,0);
 
66
                        _pUnmanaged = new struct UNMANAGED_HANDLER;
 
67
                        _pUnmanaged->_stream = stream;                  
 
68
                }               
 
69
                ~FreeImageStream() 
 
70
                { 
 
71
                        _pUnmanaged->_stream = NULL;
 
72
                        delete _pUnmanaged;
 
73
                }
 
74
 
 
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);
 
77
                }
 
78
 
 
79
                unsigned int LoadImage(FREE_IMAGE_FORMAT fif, int flags) {
 
80
                        return (unsigned int)FreeImage_LoadFromHandle(fif,(FreeImageIO*)_pUnmanaged,(fi_handle)_pUnmanaged,flags);
 
81
                }               
 
82
        };
 
83
}