diff --git a/rtengine/iimage.h b/rtengine/iimage.h index af2969581..2def35e06 100644 --- a/rtengine/iimage.h +++ b/rtengine/iimage.h @@ -82,22 +82,18 @@ public: // Read the raw dump of the data void readData (FILE *fh) {} // Write a raw dump of the data - void writeData (FILE *fh) {} + void writeData (FILE *fh) const {} virtual void normalizeInt (int srcMinVal, int srcMaxVal) {}; virtual void normalizeFloat (float srcMinVal, float srcMaxVal) {}; - virtual void computeHistogramAutoWB (double &avg_r, double &avg_g, double &avg_b, int &n, LUTu &histogram, int compression) {} + virtual void computeHistogramAutoWB (double &avg_r, double &avg_g, double &avg_b, int &n, LUTu &histogram, int compression) const {} virtual void getSpotWBData (double &reds, double &greens, double &blues, int &rn, int &gn, int &bn, std::vector &red, std::vector &green, std::vector &blue, - int tran) {} - virtual void getAutoWBMultipliers (double &rm, double &gm, double &bm) + int tran) const {} + virtual void getAutoWBMultipliers (double &rm, double &gm, double &bm) const { rm = gm = bm = 1.0; } - virtual const char* getType () const - { - return "unknown"; - } }; @@ -232,7 +228,7 @@ public: } // Send back the row stride. WARNING: unit = byte, not element! - int getRowStride () + int getRowStride () const { return rowstride; } @@ -316,7 +312,7 @@ public: } /** Copy the data to another PlanarWhateverData */ - void copyData(PlanarWhateverData *dest) + void copyData(PlanarWhateverData *dest) const { assert (dest != NULL); // Make sure that the size is the same, reallocate if necessary @@ -389,7 +385,7 @@ public: } template - void resizeImgTo (int nw, int nh, TypeInterpolation interp, PlanarWhateverData *imgPtr) + void resizeImgTo (int nw, int nh, TypeInterpolation interp, PlanarWhateverData *imgPtr) const { //printf("resizeImgTo: resizing %s image data (%d x %d) to %s (%d x %d)\n", getType(), width, height, imgPtr->getType(), imgPtr->width, imgPtr->height); if (width == nw && height == nh) { @@ -499,17 +495,7 @@ public: #endif } - void calcHist(unsigned int *hist16) - { - for (int row = 0; row < height; row++) - for (int col = 0; col < width; col++) { - unsigned short idx; - convertTo(v(row, col), idx); - hist16[idx]++; - } - } - - void transformPixel (int x, int y, int tran, int& tx, int& ty) + void transformPixel (int x, int y, int tran, int& tx, int& ty) const { if (!tran) { @@ -552,7 +538,7 @@ public: } } - void getPipetteData (T &value, int posX, int posY, int squareSize, int tran) + void getPipetteData (T &value, int posX, int posY, int squareSize, int tran) const { int x; int y; @@ -573,14 +559,14 @@ public: value = n ? T(accumulator / float(n)) : T(0); } - void readData (FILE *f) + void readData (FILE *f) { for (int i = 0; i < height; i++) { fread (v(i), sizeof(T), width, f); } } - void writeData (FILE *f) + void writeData (FILE *f) const { for (int i = 0; i < height; i++) { fwrite (v(i), sizeof(T), width, f); @@ -622,12 +608,12 @@ public: } // Send back the row stride. WARNING: unit = byte, not element! - int getRowStride () + int getRowStride () const { return rowstride; } // Send back the plane stride. WARNING: unit = byte, not element! - int getPlaneStride () + int getPlaneStride () const { return planestride; } @@ -732,7 +718,7 @@ public: } /** Copy the data to another PlanarRGBData */ - void copyData(PlanarRGBData *dest) + void copyData(PlanarRGBData *dest) const { assert (dest != nullptr); // Make sure that the size is the same, reallocate if necessary @@ -820,7 +806,7 @@ public: } template - void resizeImgTo (int nw, int nh, TypeInterpolation interp, IC *imgPtr) + void resizeImgTo (int nw, int nh, TypeInterpolation interp, IC *imgPtr) const { //printf("resizeImgTo: resizing %s image data (%d x %d) to %s (%d x %d)\n", getType(), width, height, imgPtr->getType(), imgPtr->width, imgPtr->height); if (width == nw && height == nh) { @@ -869,9 +855,9 @@ public: // This case should never occur! for (int i = 0; i < nh; i++) { for (int j = 0; j < nw; j++) { - r(i, j) = 0; - g(i, j) = 0; - b(i, j) = 0; + imgPtr->r(i, j) = 0; + imgPtr->g(i, j) = 0; + imgPtr->b(i, j) = 0; } } } @@ -942,7 +928,7 @@ public: #endif } - void calcGrayscaleHist(unsigned int *hist16) + void calcGrayscaleHist(unsigned int *hist16) const { for (int row = 0; row < height; row++) for (int col = 0; col < width; col++) { @@ -956,7 +942,7 @@ public: } } - void computeAutoHistogram (LUTu & histogram, int& histcompr) + void computeAutoHistogram (LUTu & histogram, int& histcompr) const { histcompr = 3; @@ -975,7 +961,7 @@ public: } } - void computeHistogramAutoWB (double &avg_r, double &avg_g, double &avg_b, int &n, LUTu &histogram, const int compression) + void computeHistogramAutoWB (double &avg_r, double &avg_g, double &avg_b, int &n, LUTu &histogram, const int compression) const { histogram.clear(); avg_r = avg_g = avg_b = 0.; @@ -1007,7 +993,7 @@ public: } } - void getAutoWBMultipliers (double &rm, double &gm, double &bm) + void getAutoWBMultipliers (double &rm, double &gm, double &bm) const { double avg_r = 0.; @@ -1038,7 +1024,7 @@ public: bm = avg_b / double(n); } - void transformPixel (int x, int y, int tran, int& tx, int& ty) + void transformPixel (int x, int y, int tran, int& tx, int& ty) const { if (!tran) { @@ -1083,7 +1069,7 @@ public: virtual void getSpotWBData (double &reds, double &greens, double &blues, int &rn, int &gn, int &bn, std::vector &red, std::vector &green, std::vector &blue, - int tran) + int tran) const { int x; int y; @@ -1120,7 +1106,7 @@ public: } } - void getPipetteData (T &valueR, T &valueG, T &valueB, int posX, int posY, int squareSize, int tran) + void getPipetteData (T &valueR, T &valueG, T &valueB, int posX, int posY, int squareSize, int tran) const { int x; int y; @@ -1147,7 +1133,7 @@ public: valueB = n ? T(accumulatorB / float(n)) : T(0); } - void readData (FILE *f) + void readData (FILE *f) { for (int i = 0; i < height; i++) { fread (r(i), sizeof(T), width, f); @@ -1162,7 +1148,7 @@ public: } } - void writeData (FILE *f) + void writeData (FILE *f) const { for (int i = 0; i < height; i++) { fwrite (r(i), sizeof(T), width, f); @@ -1345,7 +1331,7 @@ public: } /** Copy the data to another ChunkyRGBData */ - void copyData(ChunkyRGBData *dest) + void copyData(ChunkyRGBData *dest) const { assert (dest != nullptr); // Make sure that the size is the same, reallocate if necessary @@ -1421,7 +1407,7 @@ public: } template - void resizeImgTo (int nw, int nh, TypeInterpolation interp, IC *imgPtr) + void resizeImgTo (int nw, int nh, TypeInterpolation interp, IC *imgPtr) const { //printf("resizeImgTo: resizing %s image data (%d x %d) to %s (%d x %d)\n", getType(), width, height, imgPtr->getType(), imgPtr->width, imgPtr->height); if (width == nw && height == nh) { @@ -1485,9 +1471,9 @@ public: // This case should never occur! for (int i = 0; i < nh; i++) { for (int j = 0; j < nw; j++) { - r(i, j) = 0; - g(i, j) = 0; - b(i, j) = 0; + imgPtr->r(i, j) = 0; + imgPtr->g(i, j) = 0; + imgPtr->b(i, j) = 0; } } } @@ -1545,7 +1531,7 @@ public: } } - void calcGrayscaleHist(unsigned int *hist16) + void calcGrayscaleHist(unsigned int *hist16) const { for (int row = 0; row < height; row++) for (int col = 0; col < width; col++) { @@ -1559,7 +1545,7 @@ public: } } - void computeAutoHistogram (LUTu & histogram, int& histcompr) + void computeAutoHistogram (LUTu & histogram, int& histcompr) const { histcompr = 3; @@ -1578,7 +1564,7 @@ public: } } - void computeHistogramAutoWB (double &avg_r, double &avg_g, double &avg_b, int &n, LUTu &histogram, const int compression) + void computeHistogramAutoWB (double &avg_r, double &avg_g, double &avg_b, int &n, LUTu &histogram, const int compression) const { histogram.clear(); avg_r = avg_g = avg_b = 0.; @@ -1610,7 +1596,7 @@ public: } } - void getAutoWBMultipliers (double &rm, double &gm, double &bm) + void getAutoWBMultipliers (double &rm, double &gm, double &bm) const { double avg_r = 0.; @@ -1641,7 +1627,7 @@ public: bm = avg_b / double(n); } - void transformPixel (int x, int y, int tran, int& tx, int& ty) + void transformPixel (int x, int y, int tran, int& tx, int& ty) const { if (!tran) { @@ -1686,7 +1672,7 @@ public: virtual void getSpotWBData (double &reds, double &greens, double &blues, int &rn, int &gn, int &bn, std::vector &red, std::vector &green, std::vector &blue, - int tran) + int tran) const { int x; int y; @@ -1723,14 +1709,14 @@ public: } } - void readData (FILE *f) + void readData (FILE *f) { for (int i = 0; i < height; i++) { fread (r(i), sizeof(T), 3 * width, f); } } - void writeData (FILE *f) + void writeData (FILE *f) const { for (int i = 0; i < height; i++) { fwrite (r(i), sizeof(T), 3 * width, f); @@ -1751,31 +1737,31 @@ 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 */ - virtual int saveToFile (Glib::ustring fname) = 0; + virtual int saveToFile (const Glib::ustring &fname) const = 0; /** @brief Saves the image to file in a png format. * @param fname is the name of the file * @param compression is the amount of compression (0-6), -1 corresponds to the default * @param bps can be 8 or 16 depending on the bits per pixels the output file will have @return the error code, 0 if none */ - virtual int saveAsPNG (Glib::ustring fname, int bps = -1) = 0; + virtual int saveAsPNG (const Glib::ustring &fname, int bps = -1) const = 0; /** @brief Saves the image to file in a jpg format. * @param fname is the name of the file * @param quality is the quality of the jpeg (0...100), set it to -1 to use default @return the error code, 0 if none */ - virtual int saveAsJPEG (Glib::ustring fname, int quality = 100, int subSamp = 3 ) = 0; + virtual int saveAsJPEG (const Glib::ustring &fname, int quality = 100, int subSamp = 3 ) const = 0; /** @brief Saves the image to file in a tif format. * @param fname is the name of the file * @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 (const Glib::ustring &fname, int bps = -1, bool isFloat = false, bool uncompressed = false) const = 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; diff --git a/rtengine/image16.cc b/rtengine/image16.cc index 5ceb4f804..618d31641 100644 --- a/rtengine/image16.cc +++ b/rtengine/image16.cc @@ -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) { @@ -124,7 +124,7 @@ void Image16::setScanline(int row, unsigned char* buffer, int bps, unsigned int */ } -Image16* Image16::copy() +Image16* Image16::copy() const { Image16* cp = new Image16(width, height); @@ -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 @@ -295,8 +295,7 @@ void Image16::getStdImage(ColorTemp ctemp, int tran, Imagefloat* image, PreviewP #undef GCLIP } -Image8* -Image16::to8() +Image8* Image16::to8() const { Image8* img8 = new Image8(width, height); @@ -311,8 +310,7 @@ Image16::to8() return img8; } -Imagefloat* -Image16::tofloat() +Imagefloat* Image16::tofloat() const { Imagefloat* imgfloat = new Imagefloat(width, height); diff --git a/rtengine/image16.h b/rtengine/image16.h index 804f8cc72..3431d8afd 100644 --- a/rtengine/image16.h +++ b/rtengine/image16.h @@ -40,62 +40,71 @@ public: Image16(int width, int height); ~Image16(); - Image16* copy(); + Image16* copy() const; - Image8* to8(); - Imagefloat* tofloat(); + Image8* to8() const; + Imagefloat* tofloat() const; - virtual void getStdImage(ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp); + void getStdImage(const ColorTemp &ctemp, int tran, Imagefloat* image, PreviewProps pp) const override; - virtual const char* getType() const + const char* getType() const override { return sImage16; } - virtual int getBPS() + int getBPS() const override { 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); + + void getScanline(int row, unsigned char* buffer, int bps, bool isFloat = false) const override; + void setScanline(int row, unsigned char* buffer, int bps, unsigned int numSamples) override; // functions inherited from IImage16: - virtual MyMutex& getMutex() + MyMutex& getMutex() override { return mutex(); } - virtual cmsHPROFILE getProfile() + + cmsHPROFILE getProfile() const override { return getEmbeddedProfile(); } - virtual int getBitsPerPixel() + + int getBitsPerPixel() const override { return 8 * sizeof(unsigned short); } - virtual int saveToFile(Glib::ustring fname) + + int saveToFile(const Glib::ustring &fname) const override { return save(fname); } - virtual int saveAsPNG(Glib::ustring fname, int bps = -1) + + saveAsPNG(const Glib::ustring &fname, int bps = -1) const override { return savePNG(fname, bps); } - virtual int saveAsJPEG(Glib::ustring fname, int quality = 100, int subSamp = 3) + + int saveAsJPEG(const Glib::ustring &fname, int quality = 100, int subSamp = 3) const override { return saveJPEG(fname, quality, subSamp); } - virtual int saveAsTIFF(Glib::ustring fname, int bps = -1, float isFloat = false, bool uncompressed = false) + + int saveAsTIFF(const Glib::ustring &fname, int bps = -1, bool isFloat = false, bool uncompressed = false) const override { return saveTIFF(fname, bps, isFloat, uncompressed); } - virtual void setSaveProgressListener(ProgressListener* pl) + + void setSaveProgressListener(ProgressListener* pl) override { setProgressListener(pl); } - virtual void free() + + void free() override { delete this; } - void ExecCMSTransform(cmsHTRANSFORM hTransform); + void ExecCMSTransform(cmsHTRANSFORM hTransform); /* void ExecCMSTransform(cmsHTRANSFORM hTransform, const LabImage &labImage, int cx, int cy); */ }; diff --git a/rtengine/image8.cc b/rtengine/image8.cc index 15a6d9acc..edced2fe5 100644 --- a/rtengine/image8.cc +++ b/rtengine/image8.cc @@ -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) { @@ -89,7 +89,7 @@ void Image8::setScanline (int row, unsigned char* buffer, int bps, unsigned int } } -Image8* Image8::copy () +Image8* Image8::copy () const { Image8* cp = new Image8 (width, height); @@ -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; diff --git a/rtengine/image8.h b/rtengine/image8.h index 9bb5d51e3..2cc670a4a 100644 --- a/rtengine/image8.h +++ b/rtengine/image8.h @@ -38,55 +38,65 @@ public: Image8 (int width, int height); ~Image8 (); - Image8* copy (); + Image8* copy () const; - virtual void getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp); + void getStdImage (const ColorTemp &ctemp, int tran, Imagefloat* image, PreviewProps pp) const override; - virtual const char* getType () const + const char* getType () const override { return sImage8; } - virtual int getBPS () + + int getBPS () const override { 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); + + void getScanline (int row, unsigned char* buffer, int bps, bool isFloat = false) const override; + void setScanline (int row, unsigned char* buffer, int bps, unsigned int numSamples) override; // functions inherited from IImage*: - virtual MyMutex& getMutex () + MyMutex& getMutex () override { return mutex (); } - virtual cmsHPROFILE getProfile () + + cmsHPROFILE getProfile () const override { return getEmbeddedProfile (); } - virtual int getBitsPerPixel () + + int getBitsPerPixel () const override { return 8 * sizeof(unsigned char); } - virtual int saveToFile (Glib::ustring fname) + + int saveToFile (const Glib::ustring &fname) const override { return save (fname); } - virtual int saveAsPNG (Glib::ustring fname, int bps = -1) + + int saveAsPNG (const Glib::ustring &fname, int bps = -1) const override { return savePNG (fname, bps); } - virtual int saveAsJPEG (Glib::ustring fname, int quality = 100, int subSamp = 3) + + int saveAsJPEG (const Glib::ustring &fname, int quality = 100, int subSamp = 3) const override { return saveJPEG (fname, quality, subSamp); } - virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, float isFloat = false, bool uncompressed = false) + + int saveAsTIFF (const Glib::ustring &fname, int bps = -1, bool isFloat = false, bool uncompressed = false) const override { return saveTIFF (fname, bps, isFloat, uncompressed); } - virtual void setSaveProgressListener (ProgressListener* pl) + + void setSaveProgressListener (ProgressListener* pl) override { setProgressListener (pl); } - virtual void free () + + void free () override { delete this; } diff --git a/rtengine/imagefloat.cc b/rtengine/imagefloat.cc index fd6bc1c75..63c521040 100644 --- a/rtengine/imagefloat.cc +++ b/rtengine/imagefloat.cc @@ -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) { @@ -159,7 +159,7 @@ void Imagefloat::getScanline (int row, unsigned char* buffer, int bps, bool isFl } } -Imagefloat* Imagefloat::copy () +Imagefloat* Imagefloat::copy () const { Imagefloat* cp = new Imagefloat (width, height); @@ -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 @@ -330,7 +330,7 @@ void Imagefloat::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, Prev } Image8* -Imagefloat::to8() +Imagefloat::to8() const { Image8* img8 = new Image8(width, height); #ifdef _OPENMP @@ -349,7 +349,7 @@ Imagefloat::to8() } Image16* -Imagefloat::to16() +Imagefloat::to16() const { Image16* img16 = new Image16(width, height); #ifdef _OPENMP diff --git a/rtengine/imagefloat.h b/rtengine/imagefloat.h index d84e742ce..bd7ae2a46 100644 --- a/rtengine/imagefloat.h +++ b/rtengine/imagefloat.h @@ -44,63 +44,65 @@ public: Imagefloat (int width, int height); ~Imagefloat (); - Imagefloat* copy (); + Imagefloat* copy () const; - Image8* to8(); - Image16* to16(); + Image8* to8() const; + Image16* to16() const; - virtual void getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp); + void getStdImage (const ColorTemp &ctemp, int tran, Imagefloat* image, PreviewProps pp) const override; - virtual const char* getType () const + const char* getType () const override { return sImagefloat; } - virtual int getBPS () + + int getBPS () const override { 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); + + void getScanline (int row, unsigned char* buffer, int bps, bool isFloat = false) const override; + void setScanline (int row, unsigned char* buffer, int bps, unsigned int numSamples) override; // functions inherited from IImagefloat: - virtual MyMutex& getMutex () + MyMutex& getMutex () override { return mutex (); } - virtual cmsHPROFILE getProfile () + cmsHPROFILE getProfile () const override { return getEmbeddedProfile (); } - virtual int getBitsPerPixel () + int getBitsPerPixel () const override { return 8 * sizeof(float); } - virtual int saveToFile (Glib::ustring fname) + int saveToFile (const Glib::ustring &fname) const override { return save (fname); } - virtual int saveAsPNG (Glib::ustring fname, int bps = -1) + int saveAsPNG (const Glib::ustring &fname, int bps = -1) const override { return savePNG (fname, bps); } - virtual int saveAsJPEG (Glib::ustring fname, int quality = 100, int subSamp = 3) + int saveAsJPEG (const Glib::ustring &fname, int quality = 100, int subSamp = 3) const override { return saveJPEG (fname, quality, subSamp); } - virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, float isFloat = false, bool uncompressed = false) + int saveAsTIFF (const Glib::ustring &fname, int bps = -1, bool isFloat = false, bool uncompressed = false) const override { return saveTIFF (fname, bps, isFloat, uncompressed); } - virtual void setSaveProgressListener (ProgressListener* pl) + void setSaveProgressListener (ProgressListener* pl) override { setProgressListener (pl); } - virtual void free () + void free () override { delete this; } - inline uint16_t DNG_FloatToHalf(float f) + inline uint16_t DNG_FloatToHalf(float f) const { union { float f; diff --git a/rtengine/imageio.cc b/rtengine/imageio.cc index 9ac72be58..76a6417ff 100644 --- a/rtengine/imageio.cc +++ b/rtengine/imageio.cc @@ -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; +} diff --git a/rtengine/imageio.h b/rtengine/imageio.h index bb9fbc5f4..5970866f0 100644 --- a/rtengine/imageio.h +++ b/rtengine/imageio.h @@ -28,11 +28,11 @@ #define IMIO_FILETYPENOTSUPPORTED 6 #define IMIO_CANNOTWRITEFILE 7 +#include +#include #include "rtengine.h" #include "imageformat.h" -#include #include "procparams.h" -#include #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,42 @@ 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 const char* getType () const = 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 (); }; }