Review of image classes interfaces, part 2

This commit is contained in:
heckflosse
2018-11-18 18:09:40 +01:00
parent bfe8465563
commit 512adf5b62
8 changed files with 72 additions and 87 deletions

View File

@@ -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<Coord2D> &red, std::vector<Coord2D> &green, std::vector<Coord2D> &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<T> *dest)
void copyData(PlanarWhateverData<T> *dest) const
{
assert (dest != NULL);
// Make sure that the size is the same, reallocate if necessary
@@ -389,7 +385,7 @@ public:
}
template <class IC>
void resizeImgTo (int nw, int nh, TypeInterpolation interp, PlanarWhateverData<IC> *imgPtr)
void resizeImgTo (int nw, int nh, TypeInterpolation interp, PlanarWhateverData<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) {
@@ -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<T> *dest)
void copyData(PlanarRGBData<T> *dest) const
{
assert (dest != nullptr);
// Make sure that the size is the same, reallocate if necessary
@@ -820,7 +806,7 @@ public:
}
template <class IC>
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<Coord2D> &red, std::vector<Coord2D> &green, std::vector<Coord2D> &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<T> *dest)
void copyData(ChunkyRGBData<T> *dest) const
{
assert (dest != nullptr);
// Make sure that the size is the same, reallocate if necessary
@@ -1421,7 +1407,7 @@ public:
}
template <class IC>
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<Coord2D> &red, std::vector<Coord2D> &green, std::vector<Coord2D> &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);
@@ -1758,24 +1744,24 @@ public:
/** @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, bool 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;

View File

@@ -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);
@@ -295,8 +295,7 @@ void Image16::getStdImage(const ColorTemp &ctemp, int tran, Imagefloat* image, P
#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);

View File

@@ -40,10 +40,10 @@ 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(const ColorTemp &ctemp, int tran, Imagefloat* image, PreviewProps pp) const;
@@ -74,22 +74,22 @@ public:
return 8 * sizeof(unsigned short);
}
virtual int saveToFile(Glib::ustring fname)
virtual int saveToFile(const Glib::ustring &fname) const
{
return save(fname);
}
virtual int saveAsPNG(Glib::ustring fname, int bps = -1)
virtual int saveAsPNG(const Glib::ustring &fname, int bps = -1) const
{
return savePNG(fname, bps);
}
virtual int saveAsJPEG(Glib::ustring fname, int quality = 100, int subSamp = 3)
virtual int saveAsJPEG(const Glib::ustring &fname, int quality = 100, int subSamp = 3) const
{
return saveJPEG(fname, quality, subSamp);
}
virtual int saveAsTIFF(Glib::ustring fname, int bps = -1, bool isFloat = false, bool uncompressed = false)
virtual int saveAsTIFF(const Glib::ustring &fname, int bps = -1, bool isFloat = false, bool uncompressed = false) const
{
return saveTIFF(fname, bps, isFloat, uncompressed);
}

View File

@@ -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);

View File

@@ -38,7 +38,7 @@ public:
Image8 (int width, int height);
~Image8 ();
Image8* copy ();
Image8* copy () const;
virtual void getStdImage (const ColorTemp &ctemp, int tran, Imagefloat* image, PreviewProps pp) const;
@@ -69,22 +69,22 @@ public:
return 8 * sizeof(unsigned char);
}
virtual int saveToFile (Glib::ustring fname)
virtual int saveToFile (const Glib::ustring &fname) const
{
return save (fname);
}
virtual int saveAsPNG (Glib::ustring fname, int bps = -1)
virtual int saveAsPNG (const Glib::ustring &fname, int bps = -1) const
{
return savePNG (fname, bps);
}
virtual int saveAsJPEG (Glib::ustring fname, int quality = 100, int subSamp = 3)
virtual int saveAsJPEG (const Glib::ustring &fname, int quality = 100, int subSamp = 3) const
{
return saveJPEG (fname, quality, subSamp);
}
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, bool isFloat = false, bool uncompressed = false)
virtual int saveAsTIFF (const Glib::ustring &fname, int bps = -1, bool isFloat = false, bool uncompressed = false) const
{
return saveTIFF (fname, bps, isFloat, uncompressed);
}

View File

@@ -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);
@@ -330,7 +330,7 @@ void Imagefloat::getStdImage (const ColorTemp &ctemp, int tran, Imagefloat* imag
}
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

View File

@@ -44,10 +44,10 @@ 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 (const ColorTemp &ctemp, int tran, Imagefloat* image, PreviewProps pp) const;
@@ -75,23 +75,23 @@ public:
{
return 8 * sizeof(float);
}
virtual int saveToFile (Glib::ustring fname)
virtual int saveToFile (const Glib::ustring &fname) const
{
return save (fname);
}
virtual int saveAsPNG (Glib::ustring fname, int bps = -1)
virtual int saveAsPNG (const Glib::ustring &fname, int bps = -1) const
{
return savePNG (fname, bps);
}
virtual int saveAsJPEG (Glib::ustring fname, int quality = 100, int subSamp = 3)
virtual int saveAsJPEG (const Glib::ustring &fname, int quality = 100, int subSamp = 3) const
{
return saveJPEG (fname, quality, subSamp);
}
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, bool isFloat = false, bool uncompressed = false)
virtual int saveAsTIFF (const Glib::ustring &fname, int bps = -1, bool isFloat = false, bool uncompressed = false) const
{
return saveTIFF (fname, bps, isFloat, uncompressed);
}
virtual void setSaveProgressListener (ProgressListener* pl)
virtual void setSaveProgressListener (ProgressListener* pl)
{
setProgressListener (pl);
}

View File

@@ -84,6 +84,7 @@ public:
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;
int load (const Glib::ustring &fname);
int save (const Glib::ustring &fname) const;