44 return toRawImp( image_in , image_out , std::max(1,scale) , monochrome_out ) ;
47 bool Gr::ImageConverter::toRawImp(
Image image_in ,
Image & image_out ,
int scale ,
bool monochrome_out )
51 image_out = image_in ;
54 else if( convertible(image_in.
type()) )
59 ImageData image_data_out( *image_out_p , type_out.dx() , type_out.dy() , type_out.channels() ) ;
60 m_decoder.setup( scale , monochrome_out ) ;
61 type_out = m_decoder.decode( image_in.
type() , image_in.
data() , image_data_out ) ;
62 return image_out.
valid() ;
66 G_DEBUG(
"Gr::ImageConverter::toRawImp: invalid input image type: " << image_in.
type() ) ;
73 return toJpegImp( image_in , image_out , std::max(1,scale) , monochrome_out ) ;
76 bool Gr::ImageConverter::toJpegImp(
Image image_in ,
Image & image_out ,
int scale ,
bool monochrome_out )
83 shared_ptr<ImageBuffer> ptr_out = image_out.
recycle() ;
85 m_jpeg_writer.setup( scale , monochrome_out ) ;
86 m_jpeg_writer.encode( data_in , *ptr_out ) ;
87 image_out =
Image( ptr_out , type_out ) ;
90 else if( convertible(image_in.
type()) && image_in.
type().
isJpeg() )
92 if( scale == 1 && !monochrome_out )
94 image_out = image_in ;
100 toRawImp( image_in , m_image_tmp , scale ,
false ) &&
101 toJpegImp( m_image_tmp , image_out , 1 , monochrome_out ) ;
bool isRaw() const
Returns true if a raw image type.
A holder for image data, having eight bits per sample and one or three channels.
bool isJpeg() const
Returns true if a jpeg image type.
int channels() const
Returns the number of channels.
static ImageType jpeg(int dx, int dy, int channels=3)
Factory function for a jpeg image type.
ImageConverter()
Default constructor.
An encapsulation of image type, including width, height and number of channels, with support for a st...
Vectors ImageBuffer
An ImageBuffer is used to hold raw image data, typically in more than one chunk.
bool toRaw(Image image_in, Image &image_out, int scale=1, bool monochrome_out=false)
Converts the image to raw format. Returns a false on error.
static ImageType raw(int dx, int dy, int channels)
Factory function for a raw image type.
A class holding shared read-only image data (Gr::ImageBuffer) and its associated image type (Gr::Imag...
static bool available()
Returns true if a jpeg library is available.
static ImageBuffer * blank(Image &, ImageType raw_type, bool contiguous=false)
Factory function for a not-really-blank raw image that is temporarily writable via the returned image...
bool isPng() const
Returns true if a png image type.
int dy() const
Returns the image height.
bool valid() const
Returns !empty() && type().valid().
ImageType type() const
Returns the image type.
static bool convertible(Gr::ImageType)
Returns true if the image type is convertible.
const ImageBuffer & data() const
Returns the image data.
bool toJpeg(Image image_in, Image &image_out, int scale=1, bool monochrome_out=false)
Converts the image to jpeg format. Returns false on error.
int dx() const
Returns the image width.
shared_ptr< ImageBuffer > recycle()
Creates a new shared pointer that can be deposited into a new Image, but if the current Image is not ...
static bool available()
Returns true if the png library is available.
bool isPnm() const
Returns true if a pnm image type.