Review of image classes interfaces

This commit is contained in:
heckflosse
2018-11-18 15:43:15 +01:00
parent 99c8b60615
commit bfe8465563
9 changed files with 158 additions and 132 deletions

View File

@@ -1751,10 +1751,10 @@ public:
/** @brief Returns a mutex that can is useful in many situations. No image operations shuold be performed without locking this mutex.
* @return The mutex */
virtual MyMutex& getMutex () = 0;
virtual cmsHPROFILE getProfile () = 0;
virtual cmsHPROFILE getProfile () const = 0;
/** @brief Returns the bits per pixel of the image.
* @return The bits per pixel of the image */
virtual int getBitsPerPixel () = 0;
virtual int getBitsPerPixel () const = 0;
/** @brief Saves the image to file. It autodetects the format (jpg, tif, png are supported).
* @param fname is the name of the file
@return the error code, 0 if none */
@@ -1775,7 +1775,7 @@ public:
* @param bps can be 8 or 16 depending on the bits per pixels the output file will have
* @param isFloat is true for saving float images. Will be ignored by file format not supporting float data
@return the error code, 0 if none */
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, float isFloat = false, bool uncompressed = false) = 0;
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, bool isFloat = false, bool uncompressed = false) = 0;
/** @brief Sets the progress listener if you want to follow the progress of the image saving operations (optional).
* @param pl is the pointer to the class implementing the ProgressListener interface */
virtual void setSaveProgressListener (ProgressListener* pl) = 0;

View File

@@ -60,7 +60,7 @@ Image16::~Image16()
{
}
void Image16::getScanline(int row, unsigned char* buffer, int bps, bool isFloat)
void Image16::getScanline(int row, unsigned char* buffer, int bps, bool isFloat) const
{
if (data == nullptr) {
@@ -132,7 +132,7 @@ Image16* Image16::copy()
return cp;
}
void Image16::getStdImage(ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp)
void Image16::getStdImage(const ColorTemp &ctemp, int tran, Imagefloat* image, PreviewProps pp) const
{
// compute channel multipliers

View File

@@ -40,62 +40,70 @@ public:
Image16(int width, int height);
~Image16();
Image16* copy();
Image16* copy();
Image8* to8();
Imagefloat* tofloat();
Image8* to8();
Imagefloat* tofloat();
virtual void getStdImage(ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp);
virtual void getStdImage(const ColorTemp &ctemp, int tran, Imagefloat* image, PreviewProps pp) const;
virtual const char* getType() const
virtual const char* getType() const
{
return sImage16;
}
virtual int getBPS()
virtual int getBPS() const
{
return 8 * sizeof(unsigned short);
}
virtual void getScanline(int row, unsigned char* buffer, int bps, bool isFloat = false);
virtual void setScanline(int row, unsigned char* buffer, int bps, unsigned int numSamples);
virtual void getScanline(int row, unsigned char* buffer, int bps, bool isFloat = false) const;
virtual void setScanline(int row, unsigned char* buffer, int bps, unsigned int numSamples);
// functions inherited from IImage16:
virtual MyMutex& getMutex()
virtual MyMutex& getMutex()
{
return mutex();
}
virtual cmsHPROFILE getProfile()
virtual cmsHPROFILE getProfile() const
{
return getEmbeddedProfile();
}
virtual int getBitsPerPixel()
virtual int getBitsPerPixel() const
{
return 8 * sizeof(unsigned short);
}
virtual int saveToFile(Glib::ustring fname)
virtual int saveToFile(Glib::ustring fname)
{
return save(fname);
}
virtual int saveAsPNG(Glib::ustring fname, int bps = -1)
virtual int saveAsPNG(Glib::ustring fname, int bps = -1)
{
return savePNG(fname, bps);
}
virtual int saveAsJPEG(Glib::ustring fname, int quality = 100, int subSamp = 3)
virtual int saveAsJPEG(Glib::ustring fname, int quality = 100, int subSamp = 3)
{
return saveJPEG(fname, quality, subSamp);
}
virtual int saveAsTIFF(Glib::ustring fname, int bps = -1, float isFloat = false, bool uncompressed = false)
virtual int saveAsTIFF(Glib::ustring fname, int bps = -1, bool isFloat = false, bool uncompressed = false)
{
return saveTIFF(fname, bps, isFloat, uncompressed);
}
virtual void setSaveProgressListener(ProgressListener* pl)
virtual void setSaveProgressListener(ProgressListener* pl)
{
setProgressListener(pl);
}
virtual void free()
virtual void free()
{
delete this;
}
void ExecCMSTransform(cmsHTRANSFORM hTransform);
void ExecCMSTransform(cmsHTRANSFORM hTransform);
/* void ExecCMSTransform(cmsHTRANSFORM hTransform, const LabImage &labImage, int cx, int cy); */
};

View File

@@ -37,7 +37,7 @@ Image8::~Image8 ()
{
}
void Image8::getScanline (int row, unsigned char* buffer, int bps, bool isFloat)
void Image8::getScanline (int row, unsigned char* buffer, int bps, bool isFloat) const
{
if (data == nullptr) {
@@ -97,7 +97,7 @@ Image8* Image8::copy ()
return cp;
}
void Image8::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp)
void Image8::getStdImage (const ColorTemp &ctemp, int tran, Imagefloat* image, PreviewProps pp) const
{
// compute channel multipliers
float rm = 1.f, gm = 1.f, bm = 1.f;

View File

@@ -40,53 +40,61 @@ public:
Image8* copy ();
virtual void getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp);
virtual void getStdImage (const ColorTemp &ctemp, int tran, Imagefloat* image, PreviewProps pp) const;
virtual const char* getType () const
virtual const char* getType () const
{
return sImage8;
}
virtual int getBPS ()
virtual int getBPS () const
{
return 8 * sizeof(unsigned char);
}
virtual void getScanline (int row, unsigned char* buffer, int bps, bool isFloat = false);
virtual void setScanline (int row, unsigned char* buffer, int bps, unsigned int numSamples);
virtual void getScanline (int row, unsigned char* buffer, int bps, bool isFloat = false) const;
virtual void setScanline (int row, unsigned char* buffer, int bps, unsigned int numSamples);
// functions inherited from IImage*:
virtual MyMutex& getMutex ()
virtual MyMutex& getMutex ()
{
return mutex ();
}
virtual cmsHPROFILE getProfile ()
virtual cmsHPROFILE getProfile () const
{
return getEmbeddedProfile ();
}
virtual int getBitsPerPixel ()
virtual int getBitsPerPixel () const
{
return 8 * sizeof(unsigned char);
}
virtual int saveToFile (Glib::ustring fname)
virtual int saveToFile (Glib::ustring fname)
{
return save (fname);
}
virtual int saveAsPNG (Glib::ustring fname, int bps = -1)
virtual int saveAsPNG (Glib::ustring fname, int bps = -1)
{
return savePNG (fname, bps);
}
virtual int saveAsJPEG (Glib::ustring fname, int quality = 100, int subSamp = 3)
virtual int saveAsJPEG (Glib::ustring fname, int quality = 100, int subSamp = 3)
{
return saveJPEG (fname, quality, subSamp);
}
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, float isFloat = false, bool uncompressed = false)
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, bool isFloat = false, bool uncompressed = false)
{
return saveTIFF (fname, bps, isFloat, uncompressed);
}
virtual void setSaveProgressListener (ProgressListener* pl)
virtual void setSaveProgressListener (ProgressListener* pl)
{
setProgressListener (pl);
}
virtual void free ()
virtual void free ()
{
delete this;
}

View File

@@ -110,7 +110,7 @@ void Imagefloat::setScanline (int row, unsigned char* buffer, int bps, unsigned
namespace rtengine { extern void filmlike_clip(float *r, float *g, float *b); }
void Imagefloat::getScanline (int row, unsigned char* buffer, int bps, bool isFloat)
void Imagefloat::getScanline (int row, unsigned char* buffer, int bps, bool isFloat) const
{
if (data == nullptr) {
@@ -168,7 +168,7 @@ Imagefloat* Imagefloat::copy ()
}
// This is called by the StdImageSource class. We assume that fp images from StdImageSource don't have to deal with gamma
void Imagefloat::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp)
void Imagefloat::getStdImage (const ColorTemp &ctemp, int tran, Imagefloat* image, PreviewProps pp) const
{
// compute channel multipliers

View File

@@ -49,29 +49,29 @@ public:
Image8* to8();
Image16* to16();
virtual void getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp);
virtual void getStdImage (const ColorTemp &ctemp, int tran, Imagefloat* image, PreviewProps pp) const;
virtual const char* getType () const
virtual const char* getType () const
{
return sImagefloat;
}
virtual int getBPS ()
virtual int getBPS () const
{
return 8 * sizeof(float);
}
virtual void getScanline (int row, unsigned char* buffer, int bps, bool isFloat = false);
virtual void setScanline (int row, unsigned char* buffer, int bps, unsigned int numSamples);
virtual void getScanline (int row, unsigned char* buffer, int bps, bool isFloat = false) const;
virtual void setScanline (int row, unsigned char* buffer, int bps, unsigned int numSamples);
// functions inherited from IImagefloat:
virtual MyMutex& getMutex ()
virtual MyMutex& getMutex ()
{
return mutex ();
}
virtual cmsHPROFILE getProfile ()
virtual cmsHPROFILE getProfile () const
{
return getEmbeddedProfile ();
}
virtual int getBitsPerPixel ()
virtual int getBitsPerPixel () const
{
return 8 * sizeof(float);
}
@@ -87,7 +87,7 @@ public:
{
return saveJPEG (fname, quality, subSamp);
}
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, float isFloat = false, bool uncompressed = false)
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, bool isFloat = false, bool uncompressed = false)
{
return saveTIFF (fname, bps, isFloat, uncompressed);
}
@@ -100,7 +100,7 @@ public:
delete this;
}
inline uint16_t DNG_FloatToHalf(float f)
inline uint16_t DNG_FloatToHalf(float f) const
{
union {
float f;

View File

@@ -201,7 +201,7 @@ void png_read_data(png_struct_def *png_ptr, unsigned char *data, size_t length)
void png_write_data(png_struct_def *png_ptr, unsigned char *data, size_t length);
void png_flush(png_struct_def *png_ptr);
int ImageIO::getPNGSampleFormat (Glib::ustring fname, IIOSampleFormat &sFormat, IIOSampleArrangement &sArrangement)
int ImageIO::getPNGSampleFormat (const Glib::ustring &fname, IIOSampleFormat &sFormat, IIOSampleArrangement &sArrangement)
{
FILE *file = g_fopen (fname.c_str (), "rb");
@@ -273,7 +273,7 @@ int ImageIO::getPNGSampleFormat (Glib::ustring fname, IIOSampleFormat &sFormat,
}
}
int ImageIO::loadPNG (Glib::ustring fname)
int ImageIO::loadPNG (const Glib::ustring &fname)
{
FILE *file = g_fopen (fname.c_str (), "rb");
@@ -543,7 +543,7 @@ int ImageIO::loadJPEGFromMemory (const char* buffer, int bufsize)
return IMIO_SUCCESS;
}
int ImageIO::loadJPEG (Glib::ustring fname)
int ImageIO::loadJPEG (const Glib::ustring &fname)
{
FILE *file = g_fopen(fname.c_str (), "rb");
@@ -629,7 +629,7 @@ int ImageIO::loadJPEG (Glib::ustring fname)
}
}
int ImageIO::getTIFFSampleFormat (Glib::ustring fname, IIOSampleFormat &sFormat, IIOSampleArrangement &sArrangement)
int ImageIO::getTIFFSampleFormat (const Glib::ustring &fname, IIOSampleFormat &sFormat, IIOSampleArrangement &sArrangement)
{
#ifdef WIN32
wchar_t *wfilename = (wchar_t*)g_utf8_to_utf16 (fname.c_str(), -1, NULL, NULL, NULL);
@@ -731,7 +731,7 @@ int ImageIO::getTIFFSampleFormat (Glib::ustring fname, IIOSampleFormat &sFormat,
return IMIO_VARIANTNOTSUPPORTED;
}
int ImageIO::loadTIFF (Glib::ustring fname)
int ImageIO::loadTIFF (const Glib::ustring &fname)
{
static MyMutex thumbMutex;
@@ -972,7 +972,7 @@ void PNGwriteRawProfile(png_struct *ping, png_info *ping_info, const char *profi
} // namespace
int ImageIO::savePNG (Glib::ustring fname, volatile int bps)
int ImageIO::savePNG (const Glib::ustring &fname, int bps) const
{
if (getWidth() < 1 || getHeight() < 1) {
return IMIO_HEADERERROR;
@@ -1111,7 +1111,7 @@ int ImageIO::savePNG (Glib::ustring fname, volatile int bps)
// Quality 0..100, subsampling: 1=low quality, 2=medium, 3=high
int ImageIO::saveJPEG (Glib::ustring fname, int quality, int subSamp)
int ImageIO::saveJPEG (const Glib::ustring &fname, int quality, int subSamp) const
{
if (getWidth() < 1 || getHeight() < 1) {
return IMIO_HEADERERROR;
@@ -1301,7 +1301,7 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality, int subSamp)
return IMIO_SUCCESS;
}
int ImageIO::saveTIFF (Glib::ustring fname, int bps, float isFloat, bool uncompressed)
int ImageIO::saveTIFF (const Glib::ustring &fname, int bps, bool isFloat, bool uncompressed) const
{
if (getWidth() < 1 || getHeight() < 1) {
return IMIO_HEADERERROR;
@@ -1595,7 +1595,7 @@ void png_flush(png_structp png_ptr)
}
}
int ImageIO::load (Glib::ustring fname)
int ImageIO::load (const Glib::ustring &fname)
{
if (hasPngExtension(fname)) {
@@ -1609,7 +1609,7 @@ int ImageIO::load (Glib::ustring fname)
}
}
int ImageIO::save (Glib::ustring fname)
int ImageIO::save (const Glib::ustring &fname) const
{
if (hasPngExtension(fname)) {
return savePNG (fname);
@@ -1621,3 +1621,57 @@ int ImageIO::save (Glib::ustring fname)
return IMIO_FILETYPENOTSUPPORTED;
}
}
void ImageIO::setProgressListener (ProgressListener* l)
{
pl = l;
}
void ImageIO::setSampleFormat(IIOSampleFormat sFormat)
{
sampleFormat = sFormat;
}
IIOSampleFormat ImageIO::getSampleFormat() const
{
return sampleFormat;
}
void ImageIO::setSampleArrangement(IIOSampleArrangement sArrangement)
{
sampleArrangement = sArrangement;
}
IIOSampleArrangement ImageIO::getSampleArrangement() const
{
return sampleArrangement;
}
cmsHPROFILE ImageIO::getEmbeddedProfile () const
{
return embProfile;
}
void ImageIO::getEmbeddedProfileData (int& length, unsigned char*& pdata) const
{
length = loadedProfileLength;
pdata = (unsigned char*)loadedProfileData;
}
MyMutex& ImageIO::mutex ()
{
return imutex;
}
void ImageIO::deleteLoadedProfileData( )
{
if(loadedProfileData) {
if(loadedProfileDataJpg) {
free(loadedProfileData);
} else {
delete[] loadedProfileData;
}
}
loadedProfileData = nullptr;
}

View File

@@ -28,11 +28,11 @@
#define IMIO_FILETYPENOTSUPPORTED 6
#define IMIO_CANNOTWRITEFILE 7
#include <glibmm.h>
#include <libiptcdata/iptc-data.h>
#include "rtengine.h"
#include "imageformat.h"
#include <glibmm.h>
#include "procparams.h"
#include <libiptcdata/iptc-data.h>
#include "../rtexif/rtexif.h"
#include "imagedimensions.h"
#include "iimage.h"
@@ -63,18 +63,8 @@ protected:
IIOSampleArrangement sampleArrangement;
private:
void deleteLoadedProfileData( )
{
if(loadedProfileData) {
if(loadedProfileDataJpg) {
free(loadedProfileData);
} else {
delete[] loadedProfileData;
}
}
void deleteLoadedProfileData( );
loadedProfileData = nullptr;
}
public:
static Glib::ustring errorMsg[6];
@@ -84,75 +74,41 @@ public:
virtual ~ImageIO ();
void setProgressListener (ProgressListener* l)
{
pl = l;
}
void setProgressListener (ProgressListener* l);
void setSampleFormat(IIOSampleFormat sFormat);
IIOSampleFormat getSampleFormat() const;
void setSampleArrangement(IIOSampleArrangement sArrangement);
IIOSampleArrangement getSampleArrangement() const;
void setSampleFormat(IIOSampleFormat sFormat)
{
sampleFormat = sFormat;
}
IIOSampleFormat getSampleFormat()
{
return sampleFormat;
}
void setSampleArrangement(IIOSampleArrangement sArrangement)
{
sampleArrangement = sArrangement;
}
IIOSampleArrangement getSampleArrangement()
{
return sampleArrangement;
}
virtual void getStdImage (const ColorTemp &ctemp, int tran, Imagefloat* image, PreviewProps pp) const = 0;
virtual int getBPS () const = 0;
virtual void getScanline (int row, unsigned char* buffer, int bps, bool isFloat = false) const = 0;
virtual void setScanline (int row, unsigned char* buffer, int bps, unsigned int numSamples = 3) = 0;
virtual void getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp) = 0;
virtual int getBPS () = 0;
virtual void getScanline (int row, unsigned char* buffer, int bps, bool isFloat = false) {}
virtual void setScanline (int row, unsigned char* buffer, int bps, unsigned int numSamples = 3) {}
int load (const Glib::ustring &fname);
int save (const Glib::ustring &fname) const;
virtual bool readImage (Glib::ustring &fname, FILE *fh)
{
return false;
};
virtual bool writeImage (Glib::ustring &fname, FILE *fh)
{
return false;
};
int load (Glib::ustring fname);
int save (Glib::ustring fname);
int loadPNG (Glib::ustring fname);
int loadJPEG (Glib::ustring fname);
int loadTIFF (Glib::ustring fname);
static int getPNGSampleFormat (Glib::ustring fname, IIOSampleFormat &sFormat, IIOSampleArrangement &sArrangement);
static int getTIFFSampleFormat (Glib::ustring fname, IIOSampleFormat &sFormat, IIOSampleArrangement &sArrangement);
int loadPNG (const Glib::ustring &fname);
int loadJPEG (const Glib::ustring &fname);
int loadTIFF (const Glib::ustring &fname);
static int getPNGSampleFormat (const Glib::ustring &fname, IIOSampleFormat &sFormat, IIOSampleArrangement &sArrangement);
static int getTIFFSampleFormat (const Glib::ustring &fname, IIOSampleFormat &sFormat, IIOSampleArrangement &sArrangement);
int loadJPEGFromMemory (const char* buffer, int bufsize);
int loadPPMFromMemory(const char* buffer, int width, int height, bool swap, int bps);
int savePNG (Glib::ustring fname, volatile int bps = -1);
int saveJPEG (Glib::ustring fname, int quality = 100, int subSamp = 3);
int saveTIFF (Glib::ustring fname, int bps = -1, float isFloat = false, bool uncompressed = false);
int savePNG (const Glib::ustring &fname, int bps = -1) const;
int saveJPEG (const Glib::ustring &fname, int quality = 100, int subSamp = 3) const;
int saveTIFF (const Glib::ustring &fname, int bps = -1, bool isFloat = false, bool uncompressed = false) const;
cmsHPROFILE getEmbeddedProfile ()
{
return embProfile;
}
void getEmbeddedProfileData (int& length, unsigned char*& pdata)
{
length = loadedProfileLength;
pdata = (unsigned char*)loadedProfileData;
}
cmsHPROFILE getEmbeddedProfile () const;
void getEmbeddedProfileData (int& length, unsigned char*& pdata) const;
void setMetadata (const rtexif::TagDirectory* eroot);
void setMetadata (const rtexif::TagDirectory* eroot, const rtengine::procparams::ExifPairs& exif, const rtengine::procparams::IPTCPairs& iptcc);
void setOutputProfile (const char* pdata, int plen);
MyMutex& mutex ()
{
return imutex;
}
void setOutputProfile (const char* pdata, int plen);
MyMutex& mutex ();
};
}