jpeg_loader_abstract.h 4.95 KB
Newer Older
Davis King's avatar
Davis King committed
1
// Copyright (C) 2010  Davis E. King (davis@dlib.net), Nils Labugt
2
3
4
5
6
7
8
9
// License: Boost Software License   See LICENSE.txt for the full license.
#undef DLIB_JPEG_IMPORT_ABSTRACT
#ifdef DLIB_JPEG_IMPORT_ABSTRACT

#include "image_loader_abstract.h"
#include "../algs.h"
#include "../pixel.h"
#include "../dir_nav.h"
10
#include "../image_processing/generic_image.h"
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

namespace dlib
{

    class jpeg_loader : noncopyable
    {
        /*!
            INITIAL VALUE
                Defined by the constructors

            WHAT THIS OBJECT REPRESENTS
                This object represents a class capable of loading JPEG image files.
                Once an instance of it is created to contain a JPEG file from
                disk you can obtain the image stored in it via get_image().
        !*/

    public:

        jpeg_loader( 
            const char* filename 
        );
        /*!
            ensures
                - loads the JPEG file with the given file name into this object
            throws
                - std::bad_alloc
                - image_load_error
                  This exception is thrown if there is some error that prevents
                  us from loading the given JPEG file.
        !*/

        jpeg_loader( 
            const std::string& filename 
        );
        /*!
            ensures
                - loads the JPEG file with the given file name into this object
            throws
                - std::bad_alloc
                - image_load_error
                  This exception is thrown if there is some error that prevents
                  us from loading the given JPEG file.
        !*/

        jpeg_loader( 
            const dlib::file& f 
        );
        /*!
            ensures
                - loads the JPEG file with the given file name into this object
            throws
                - std::bad_alloc
                - image_load_error
                  This exception is thrown if there is some error that prevents
                  us from loading the given JPEG file.
        !*/

68
        jpeg_loader( 
69
            const unsigned char* imgbuffer,
70
71
72
73
74
75
76
77
78
79
80
            size_t buffersize
        );
        /*!
            ensures
                - loads the JPEG from memory imgbuffer of size buffersize into this object
            throws
                - image_load_error
                  This exception is thrown if there is some error that prevents
                  us from loading the given JPEG buffer.
        !*/

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
        ~jpeg_loader(
        );
        /*!
            ensures
                - all resources associated with *this has been released
        !*/

        bool is_gray(
        ) const;
        /*!
            ensures
                - if (this object contains a grayscale image) then
                    - returns true
                - else
                    - returns false
        !*/
        
        bool is_rgb(
        ) const;
        /*!
            ensures
                - if (this object contains a 3 channel RGB image) then
                    - returns true
                - else
                    - returns false
        !*/

        template<
            typename image_type 
            >
        void get_image( 
            image_type& img
        ) const;
        /*!
            requires
116
117
                - image_type == an image object that implements the interface defined in
                  dlib/image_processing/generic_image.h 
118
119
120
121
122
            ensures
                - loads the JPEG image stored in this object into img
        !*/

    };
123
124
125
126
127
128
129
130
131
132
133
134

// ----------------------------------------------------------------------------------------

    template <
        typename image_type
        >
    void load_jpeg (
        image_type& image,
        const std::string& file_name
    );
    /*!
        requires
135
136
            - image_type == an image object that implements the interface defined in
              dlib/image_processing/generic_image.h 
137
138
139
140
        ensures
            - performs: jpeg_loader(file_name).get_image(image);
    !*/

141
142
143
144
145
    template <
        typename image_type
        >
    void load_jpeg (
        image_type& image,
146
        const unsigned char* imgbuff,
147
148
149
150
151
152
153
154
155
156
        size_t imgbuffsize
    );
    /*!
        requires
            - image_type == an image object that implements the interface defined in
              dlib/image_processing/generic_image.h 
        ensures
            - performs: jpeg_loader(imgbuff, imgbuffsize).get_image(image);
    !*/

157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
    template <
        typename image_type
        >
    void load_jpeg (
        image_type& image,
        const char* imgbuff,
        size_t imgbuffsize
    );
    /*!
        requires
            - image_type == an image object that implements the interface defined in
              dlib/image_processing/generic_image.h 
        ensures
            - performs: jpeg_loader((unsigned char*)imgbuff, imgbuffsize).get_image(image);
    !*/

173
174
// ----------------------------------------------------------------------------------------

175
176
177
178
}

#endif // DLIB_JPEG_IMPORT_ABSTRACT