Commit e1b66718 authored by Davis King's avatar Davis King
Browse files

Fixed const correctness on the in-memory jpeg loading code.

parent a0af6b7a
...@@ -49,7 +49,7 @@ namespace dlib ...@@ -49,7 +49,7 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
jpeg_loader:: jpeg_loader::
jpeg_loader( unsigned char* imgbuffer, size_t imgbuffersize ) : height_( 0 ), width_( 0 ), output_components_(0) jpeg_loader( const unsigned char* imgbuffer, size_t imgbuffersize ) : height_( 0 ), width_( 0 ), output_components_(0)
{ {
read_image( NULL, imgbuffer, imgbuffersize ); read_image( NULL, imgbuffer, imgbuffersize );
} }
...@@ -113,7 +113,7 @@ namespace dlib ...@@ -113,7 +113,7 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
void jpeg_loader::read_image( FILE * file, unsigned char* imgbuffer, size_t imgbuffersize ) void jpeg_loader::read_image( FILE * file, const unsigned char* imgbuffer, size_t imgbuffersize )
{ {
jpeg_decompress_struct cinfo; jpeg_decompress_struct cinfo;
......
...@@ -21,7 +21,7 @@ namespace dlib ...@@ -21,7 +21,7 @@ namespace dlib
jpeg_loader( const char* filename ); jpeg_loader( const char* filename );
jpeg_loader( const std::string& filename ); jpeg_loader( const std::string& filename );
jpeg_loader( const dlib::file& f ); jpeg_loader( const dlib::file& f );
jpeg_loader( unsigned char* imgbuffer, size_t buffersize ); jpeg_loader( const unsigned char* imgbuffer, size_t buffersize );
bool is_gray() const; bool is_gray() const;
bool is_rgb() const; bool is_rgb() const;
...@@ -78,7 +78,7 @@ namespace dlib ...@@ -78,7 +78,7 @@ namespace dlib
} }
FILE * check_file(const char* filename ); FILE * check_file(const char* filename );
void read_image( FILE *file, unsigned char* imgbuffer, size_t imgbuffersize ); void read_image( FILE *file, const unsigned char* imgbuffer, size_t imgbuffersize );
unsigned long height_; unsigned long height_;
unsigned long width_; unsigned long width_;
unsigned long output_components_; unsigned long output_components_;
...@@ -97,18 +97,31 @@ namespace dlib ...@@ -97,18 +97,31 @@ namespace dlib
{ {
jpeg_loader(file_name).get_image(image); jpeg_loader(file_name).get_image(image);
} }
template < template <
typename image_type typename image_type
> >
void load_jpeg ( void load_jpeg (
image_type& image, image_type& image,
unsigned char* imgbuff, const unsigned char* imgbuff,
size_t imgbuffsize size_t imgbuffsize
) )
{ {
jpeg_loader(imgbuff, imgbuffsize).get_image(image); jpeg_loader(imgbuff, imgbuffsize).get_image(image);
} }
template <
typename image_type
>
void load_jpeg (
image_type& image,
const char* imgbuff,
size_t imgbuffsize
)
{
jpeg_loader(reinterpret_cast<const unsigned char*>(imgbuff), imgbuffsize).get_image(image);
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
...@@ -66,7 +66,7 @@ namespace dlib ...@@ -66,7 +66,7 @@ namespace dlib
!*/ !*/
jpeg_loader( jpeg_loader(
unsigned char* imgbuffer, const unsigned char* imgbuffer,
size_t buffersize size_t buffersize
); );
/*! /*!
...@@ -143,7 +143,7 @@ namespace dlib ...@@ -143,7 +143,7 @@ namespace dlib
> >
void load_jpeg ( void load_jpeg (
image_type& image, image_type& image,
unsigned char* imgbuff, const unsigned char* imgbuff,
size_t imgbuffsize size_t imgbuffsize
); );
/*! /*!
...@@ -154,6 +154,22 @@ namespace dlib ...@@ -154,6 +154,22 @@ namespace dlib
- performs: jpeg_loader(imgbuff, imgbuffsize).get_image(image); - performs: jpeg_loader(imgbuff, imgbuffsize).get_image(image);
!*/ !*/
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);
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment