Docs updated, added InputArray, fixes for makePtr,...

This commit is contained in:
Fedor Morozov
2013-09-23 23:40:06 +04:00
committed by Alexander Shishkov
parent f99be6bda6
commit c9ace38897
22 changed files with 651 additions and 1076 deletions

View File

@@ -49,10 +49,10 @@ namespace cv
HdrDecoder::HdrDecoder()
{
m_signature = "#?RGBE";
m_signature_alt = "#?RADIANCE";
file = NULL;
m_type = CV_32FC3;
m_signature = "#?RGBE";
m_signature_alt = "#?RADIANCE";
file = NULL;
m_type = CV_32FC3;
}
HdrDecoder::~HdrDecoder()
@@ -61,61 +61,61 @@ HdrDecoder::~HdrDecoder()
size_t HdrDecoder::signatureLength() const
{
return m_signature.size() > m_signature_alt.size() ?
m_signature.size() : m_signature_alt.size();
return m_signature.size() > m_signature_alt.size() ?
m_signature.size() : m_signature_alt.size();
}
bool HdrDecoder::readHeader()
{
file = fopen(m_filename.c_str(), "rb");
if(!file) {
return false;
}
RGBE_ReadHeader(file, &m_width, &m_height, NULL);
if(m_width <= 0 || m_height <= 0) {
fclose(file);
file = NULL;
return false;
}
return true;
file = fopen(m_filename.c_str(), "rb");
if(!file) {
return false;
}
RGBE_ReadHeader(file, &m_width, &m_height, NULL);
if(m_width <= 0 || m_height <= 0) {
fclose(file);
file = NULL;
return false;
}
return true;
}
bool HdrDecoder::readData(Mat& _img)
{
Mat img(m_height, m_width, CV_32FC3);
if(!file) {
if(!readHeader()) {
return false;
}
}
RGBE_ReadPixels_RLE(file, const_cast<float*>(img.ptr<float>()), img.cols, img.rows);
fclose(file); file = NULL;
if(_img.depth() == img.depth()) {
img.convertTo(_img, _img.type());
} else {
img.convertTo(_img, _img.type(), 255);
}
return true;
Mat img(m_height, m_width, CV_32FC3);
if(!file) {
if(!readHeader()) {
return false;
}
}
RGBE_ReadPixels_RLE(file, const_cast<float*>(img.ptr<float>()), img.cols, img.rows);
fclose(file); file = NULL;
if(_img.depth() == img.depth()) {
img.convertTo(_img, _img.type());
} else {
img.convertTo(_img, _img.type(), 255);
}
return true;
}
bool HdrDecoder::checkSignature( const String& signature ) const
{
if(signature.size() >= m_signature.size() &&
(!memcmp(signature.c_str(), m_signature.c_str(), m_signature.size()) ||
!memcmp(signature.c_str(), m_signature_alt.c_str(), m_signature_alt.size())))
return true;
return false;
if(signature.size() >= m_signature.size() &&
(!memcmp(signature.c_str(), m_signature.c_str(), m_signature.size()) ||
!memcmp(signature.c_str(), m_signature_alt.c_str(), m_signature_alt.size())))
return true;
return false;
}
ImageDecoder HdrDecoder::newDecoder() const
{
return new HdrDecoder;
return makePtr<HdrDecoder>();
}
HdrEncoder::HdrEncoder()
{
m_description = "Radiance HDR (*.hdr;*.pic)";
m_description = "Radiance HDR (*.hdr;*.pic)";
}
HdrEncoder::~HdrEncoder()
@@ -124,41 +124,41 @@ HdrEncoder::~HdrEncoder()
bool HdrEncoder::write( const Mat& input_img, const std::vector<int>& params )
{
Mat img;
CV_Assert(input_img.channels() == 3 || input_img.channels() == 1);
if(input_img.channels() == 1) {
std::vector<Mat> splitted(3, input_img);
merge(splitted, img);
} else {
input_img.copyTo(img);
}
if(img.depth() != CV_32F) {
img.convertTo(img, CV_32FC3, 1/255.0f);
}
CV_Assert(params.empty() || params[0] == HDR_NONE || params[0] == HDR_RLE);
FILE *fout = fopen(m_filename.c_str(), "wb");
if(!fout) {
return false;
}
Mat img;
CV_Assert(input_img.channels() == 3 || input_img.channels() == 1);
if(input_img.channels() == 1) {
std::vector<Mat> splitted(3, input_img);
merge(splitted, img);
} else {
input_img.copyTo(img);
}
if(img.depth() != CV_32F) {
img.convertTo(img, CV_32FC3, 1/255.0f);
}
CV_Assert(params.empty() || params[0] == HDR_NONE || params[0] == HDR_RLE);
FILE *fout = fopen(m_filename.c_str(), "wb");
if(!fout) {
return false;
}
RGBE_WriteHeader(fout, img.cols, img.rows, NULL);
if(params.empty() || params[0] == HDR_RLE) {
RGBE_WritePixels_RLE(fout, const_cast<float*>(img.ptr<float>()), img.cols, img.rows);
} else {
RGBE_WritePixels(fout, const_cast<float*>(img.ptr<float>()), img.cols * img.rows);
}
RGBE_WriteHeader(fout, img.cols, img.rows, NULL);
if(params.empty() || params[0] == HDR_RLE) {
RGBE_WritePixels_RLE(fout, const_cast<float*>(img.ptr<float>()), img.cols, img.rows);
} else {
RGBE_WritePixels(fout, const_cast<float*>(img.ptr<float>()), img.cols * img.rows);
}
fclose(fout);
return true;
fclose(fout);
return true;
}
ImageEncoder HdrEncoder::newEncoder() const
{
return new HdrEncoder;
return makePtr<HdrEncoder>();
}
bool HdrEncoder::isFormatSupported( int depth ) const {
return depth != CV_64F;
return depth != CV_64F;
}
}

View File

@@ -58,29 +58,29 @@ enum HdrCompression
class HdrDecoder : public BaseImageDecoder
{
public:
HdrDecoder();
~HdrDecoder();
bool readHeader();
bool readData( Mat& img );
bool checkSignature( const String& signature ) const;
ImageDecoder newDecoder() const;
size_t signatureLength() const;
HdrDecoder();
~HdrDecoder();
bool readHeader();
bool readData( Mat& img );
bool checkSignature( const String& signature ) const;
ImageDecoder newDecoder() const;
size_t signatureLength() const;
protected:
String m_signature_alt;
FILE *file;
String m_signature_alt;
FILE *file;
};
// ... writer
class HdrEncoder : public BaseImageEncoder
{
public:
HdrEncoder();
~HdrEncoder();
bool write( const Mat& img, const std::vector<int>& params );
ImageEncoder newEncoder() const;
bool isFormatSupported( int depth ) const;
HdrEncoder();
~HdrEncoder();
bool write( const Mat& img, const std::vector<int>& params );
ImageEncoder newEncoder() const;
bool isFormatSupported( int depth ) const;
protected:
};
}

View File

@@ -72,7 +72,7 @@ TiffDecoder::TiffDecoder()
TIFFSetErrorHandler( GrFmtSilentTIFFErrorHandler );
TIFFSetWarningHandler( GrFmtSilentTIFFErrorHandler );
}
m_hdr = false;
m_hdr = false;
}
@@ -135,13 +135,13 @@ bool TiffDecoder::readHeader()
m_width = wdth;
m_height = hght;
if((bpp == 32 && ncn == 3) || photometric == PHOTOMETRIC_LOGLUV)
{
m_type = CV_32FC3;
m_hdr = true;
return true;
}
m_hdr = false;
if((bpp == 32 && ncn == 3) || photometric == PHOTOMETRIC_LOGLUV)
{
m_type = CV_32FC3;
m_hdr = true;
return true;
}
m_hdr = false;
if( bpp > 8 &&
((photometric != 2 && photometric != 1) ||
@@ -181,10 +181,10 @@ bool TiffDecoder::readHeader()
bool TiffDecoder::readData( Mat& img )
{
if(m_hdr && img.type() == CV_32FC3)
{
return readHdrData(img);
}
if(m_hdr && img.type() == CV_32FC3)
{
return readHdrData(img);
}
bool result = false;
bool color = img.channels() > 1;
uchar* data = img.data;
@@ -394,35 +394,35 @@ bool TiffDecoder::readData( Mat& img )
return result;
}
bool TiffDecoder::readHdrData(Mat& img)
bool TiffDecoder::readHdrData(Mat& img)
{
int rows_per_strip = 0, photometric = 0;
if(!m_tif)
{
return false;
}
TIFF *tif = static_cast<TIFF*>(m_tif);
TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rows_per_strip);
int rows_per_strip = 0, photometric = 0;
if(!m_tif)
{
return false;
}
TIFF *tif = static_cast<TIFF*>(m_tif);
TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rows_per_strip);
TIFFGetField( tif, TIFFTAG_PHOTOMETRIC, &photometric );
TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_FLOAT);
int size = 3 * m_width * m_height * sizeof (float);
int strip_size = 3 * m_width * rows_per_strip;
float *ptr = img.ptr<float>();
for (size_t i = 0; i < TIFFNumberOfStrips(tif); i++, ptr += strip_size)
{
TIFFReadEncodedStrip(tif, i, ptr, size);
size -= strip_size * sizeof(float);
}
close();
if(photometric == PHOTOMETRIC_LOGLUV)
{
cvtColor(img, img, COLOR_XYZ2BGR);
}
else
{
cvtColor(img, img, COLOR_RGB2BGR);
}
return true;
TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_FLOAT);
int size = 3 * m_width * m_height * sizeof (float);
int strip_size = 3 * m_width * rows_per_strip;
float *ptr = img.ptr<float>();
for (size_t i = 0; i < TIFFNumberOfStrips(tif); i++, ptr += strip_size)
{
TIFFReadEncodedStrip(tif, i, ptr, size);
size -= strip_size * sizeof(float);
}
close();
if(photometric == PHOTOMETRIC_LOGLUV)
{
cvtColor(img, img, COLOR_XYZ2BGR);
}
else
{
cvtColor(img, img, COLOR_RGB2BGR);
}
return true;
}
#endif
@@ -452,8 +452,8 @@ bool TiffEncoder::isFormatSupported( int depth ) const
{
#ifdef HAVE_TIFF
return depth == CV_8U || depth == CV_16U || depth == CV_32F;
#else
return depth == CV_8U || depth == CV_16U;
#else
return depth == CV_8U || depth == CV_16U;
#endif
}
@@ -608,29 +608,29 @@ bool TiffEncoder::writeLibTiff( const Mat& img, const std::vector<int>& params)
bool TiffEncoder::writeHdr(const Mat& _img)
{
Mat img;
cvtColor(_img, img, COLOR_BGR2XYZ);
TIFF* tif = TIFFOpen(m_filename.c_str(), "w");
if (!tif)
{
Mat img;
cvtColor(_img, img, COLOR_BGR2XYZ);
TIFF* tif = TIFFOpen(m_filename.c_str(), "w");
if (!tif)
{
return false;
}
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, img.cols);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, img.rows);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_SGILOG);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_LOGLUV);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_FLOAT);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1);
int strip_size = 3 * img.cols;
float *ptr = const_cast<float*>(img.ptr<float>());
for (int i = 0; i < img.rows; i++, ptr += strip_size)
{
TIFFWriteEncodedStrip(tif, i, ptr, strip_size * sizeof(float));
}
TIFFClose(tif);
return true;
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, img.cols);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, img.rows);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_SGILOG);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_LOGLUV);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_FLOAT);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1);
int strip_size = 3 * img.cols;
float *ptr = const_cast<float*>(img.ptr<float>());
for (int i = 0; i < img.rows; i++, ptr += strip_size)
{
TIFFWriteEncodedStrip(tif, i, ptr, strip_size * sizeof(float));
}
TIFFClose(tif);
return true;
}
#endif
@@ -645,10 +645,10 @@ bool TiffEncoder::write( const Mat& img, const std::vector<int>& /*params*/)
int width = img.cols, height = img.rows;
int depth = img.depth();
#ifdef HAVE_TIFF
if(img.type() == CV_32FC3)
{
return writeHdr(img);
}
if(img.type() == CV_32FC3)
{
return writeHdr(img);
}
#endif
if (depth != CV_8U && depth != CV_16U)

View File

@@ -108,8 +108,8 @@ public:
protected:
void* m_tif;
int normalizeChannelsNumber(int channels) const;
bool readHdrData(Mat& img);
bool m_hdr;
bool readHdrData(Mat& img);
bool m_hdr;
};
#endif
@@ -132,7 +132,7 @@ protected:
int count, int value );
bool writeLibTiff( const Mat& img, const std::vector<int>& params );
bool writeHdr( const Mat& img );
bool writeHdr( const Mat& img );
};
}

View File

@@ -59,15 +59,10 @@ struct ImageCodecInitializer
{
ImageCodecInitializer()
{
<<<<<<< HEAD
decoders.push_back( new BmpDecoder );
encoders.push_back( new BmpEncoder );
decoders.push_back( new HdrDecoder );
encoders.push_back( new HdrEncoder );
=======
decoders.push_back( makePtr<BmpDecoder>() );
encoders.push_back( makePtr<BmpEncoder>() );
>>>>>>> 99a43257d5912ff215016e1cf5f4e0c2a934b72f
decoders.push_back( makePtr<HdrDecoder>() );
encoders.push_back( makePtr<HdrEncoder>() );
#ifdef HAVE_JPEG
decoders.push_back( makePtr<JpegDecoder>() );
encoders.push_back( makePtr<JpegEncoder>() );

View File

@@ -53,7 +53,7 @@
// developed by Greg Ward. It handles the conversions between rgbe and
// pixels consisting of floats. The data is assumed to be an array of floats.
// By default there are three floats per pixel in the order red, green, blue.
// (RGBE_DATA_??? values control this.) Only the mimimal header reading and
// (RGBE_DATA_??? values control this.) Only the mimimal header reading and
// writing is implemented. Each routine does error checking and will return
// a status value as defined below. This code is intended as a skeleton so
// feel free to modify it to suit your needs.
@@ -83,7 +83,7 @@ enum rgbe_error_codes {
};
/* default error routine. change this to change error handling */
static int rgbe_error(int rgbe_error_code, char *msg)
static int rgbe_error(int rgbe_error_code, const char *msg)
{
switch (rgbe_error_code) {
case rgbe_read_error:
@@ -93,20 +93,20 @@ static int rgbe_error(int rgbe_error_code, char *msg)
CV_Error(cv::Error::StsError, "RGBE write error");
break;
case rgbe_format_error:
CV_Error(cv::Error::StsError, cv::String("RGBE bad file format: ") +
cv::String(msg));
CV_Error(cv::Error::StsError, cv::String("RGBE bad file format: ") +
cv::String(msg));
break;
default:
case rgbe_memory_error:
CV_Error(cv::Error::StsError, cv::String("RGBE error: \n") +
cv::String(msg));
CV_Error(cv::Error::StsError, cv::String("RGBE error: \n") +
cv::String(msg));
}
return RGBE_RETURN_FAILURE;
}
/* standard conversion from float pixels to rgbe pixels */
/* note: you can remove the "inline"s if your compiler complains about it */
static INLINE void
static INLINE void
float2rgbe(unsigned char rgbe[4], float red, float green, float blue)
{
float v;
@@ -119,7 +119,7 @@ float2rgbe(unsigned char rgbe[4], float red, float green, float blue)
rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0;
}
else {
v = frexp(v,&e) * 256.0/v;
v = static_cast<float>(frexp(v,&e) * 256.0/v);
rgbe[0] = (unsigned char) (red * v);
rgbe[1] = (unsigned char) (green * v);
rgbe[2] = (unsigned char) (blue * v);
@@ -130,13 +130,13 @@ float2rgbe(unsigned char rgbe[4], float red, float green, float blue)
/* standard conversion from rgbe to float pixels */
/* note: Ward uses ldexp(col+0.5,exp-(128+8)). However we wanted pixels */
/* in the range [0,1] to map back into the range [0,1]. */
static INLINE void
static INLINE void
rgbe2float(float *red, float *green, float *blue, unsigned char rgbe[4])
{
float f;
if (rgbe[3]) { /*nonzero pixel*/
f = ldexp(1.0,rgbe[3]-(int)(128+8));
f = static_cast<float>(ldexp(1.0,rgbe[3]-(int)(128+8)));
*red = rgbe[0] * f;
*green = rgbe[1] * f;
*blue = rgbe[2] * f;
@@ -148,7 +148,7 @@ rgbe2float(float *red, float *green, float *blue, unsigned char rgbe[4])
/* default minimal header. modify if you want more information in header */
int RGBE_WriteHeader(FILE *fp, int width, int height, rgbe_header_info *info)
{
char *programtype = "RGBE";
const char *programtype = "RGBE";
if (info && (info->valid & RGBE_VALID_PROGRAMTYPE))
programtype = info->programtype;
@@ -174,11 +174,9 @@ int RGBE_WriteHeader(FILE *fp, int width, int height, rgbe_header_info *info)
int RGBE_ReadHeader(FILE *fp, int *width, int *height, rgbe_header_info *info)
{
char buf[128];
int found_format;
float tempf;
int i;
found_format = 0;
if (info) {
info->valid = 0;
info->programtype[0] = 0;
@@ -194,7 +192,7 @@ int RGBE_ReadHeader(FILE *fp, int *width, int *height, rgbe_header_info *info)
info->valid |= RGBE_VALID_PROGRAMTYPE;
for(i=0;i<static_cast<int>(sizeof(info->programtype)-1);i++) {
if ((buf[i+2] == 0) || isspace(buf[i+2]))
break;
break;
info->programtype[i] = buf[i+2];
}
info->programtype[i] = 0;
@@ -221,7 +219,7 @@ int RGBE_ReadHeader(FILE *fp, int *width, int *height, rgbe_header_info *info)
return rgbe_error(rgbe_read_error,NULL);
if (strcmp(buf,"\n") != 0)
return rgbe_error(rgbe_format_error,
"missing blank line after FORMAT specifier");
"missing blank line after FORMAT specifier");
if (fgets(buf,sizeof(buf)/sizeof(buf[0]),fp) == 0)
return rgbe_error(rgbe_read_error,NULL);
if (sscanf(buf,"-Y %d +X %d",height,width) < 2)
@@ -238,7 +236,7 @@ int RGBE_WritePixels(FILE *fp, float *data, int numpixels)
while (numpixels-- > 0) {
float2rgbe(rgbe,data[RGBE_DATA_RED],
data[RGBE_DATA_GREEN],data[RGBE_DATA_BLUE]);
data[RGBE_DATA_GREEN],data[RGBE_DATA_BLUE]);
data += RGBE_DATA_SIZE;
if (fwrite(rgbe, sizeof(rgbe), 1, fp) < 1)
return rgbe_error(rgbe_write_error,NULL);
@@ -255,7 +253,7 @@ int RGBE_ReadPixels(FILE *fp, float *data, int numpixels)
if (fread(rgbe, sizeof(rgbe), 1, fp) < 1)
return rgbe_error(rgbe_read_error,NULL);
rgbe2float(&data[RGBE_DATA_RED],&data[RGBE_DATA_GREEN],
&data[RGBE_DATA_BLUE],rgbe);
&data[RGBE_DATA_BLUE],rgbe);
data += RGBE_DATA_SIZE;
}
return RGBE_RETURN_SUCCESS;
@@ -283,34 +281,34 @@ static int RGBE_WriteBytes_RLE(FILE *fp, unsigned char *data, int numbytes)
run_count = 1;
while( (beg_run + run_count < numbytes) && (run_count < 127)
&& (data[beg_run] == data[beg_run + run_count]))
run_count++;
run_count++;
}
/* if data before next big run is a short run then write it as such */
if ((old_run_count > 1)&&(old_run_count == beg_run - cur)) {
buf[0] = 128 + old_run_count; /*write short run*/
buf[0] = static_cast<unsigned char>(128 + old_run_count); /*write short run*/
buf[1] = data[cur];
if (fwrite(buf,sizeof(buf[0])*2,1,fp) < 1)
return rgbe_error(rgbe_write_error,NULL);
return rgbe_error(rgbe_write_error,NULL);
cur = beg_run;
}
/* write out bytes until we reach the start of the next run */
while(cur < beg_run) {
nonrun_count = beg_run - cur;
if (nonrun_count > 128)
nonrun_count = 128;
buf[0] = nonrun_count;
if (nonrun_count > 128)
nonrun_count = 128;
buf[0] = static_cast<unsigned char>(nonrun_count);
if (fwrite(buf,sizeof(buf[0]),1,fp) < 1)
return rgbe_error(rgbe_write_error,NULL);
return rgbe_error(rgbe_write_error,NULL);
if (fwrite(&data[cur],sizeof(data[0])*nonrun_count,1,fp) < 1)
return rgbe_error(rgbe_write_error,NULL);
return rgbe_error(rgbe_write_error,NULL);
cur += nonrun_count;
}
/* write out next run if one was found */
if (run_count >= MINRUNLENGTH) {
buf[0] = 128 + run_count;
buf[0] = static_cast<unsigned char>(128 + run_count);
buf[1] = data[beg_run];
if (fwrite(buf,sizeof(buf[0])*2,1,fp) < 1)
return rgbe_error(rgbe_write_error,NULL);
return rgbe_error(rgbe_write_error,NULL);
cur += run_count;
}
}
@@ -319,7 +317,7 @@ static int RGBE_WriteBytes_RLE(FILE *fp, unsigned char *data, int numbytes)
}
int RGBE_WritePixels_RLE(FILE *fp, float *data, int scanline_width,
int num_scanlines)
int num_scanlines)
{
unsigned char rgbe[4];
unsigned char *buffer;
@@ -329,13 +327,13 @@ int RGBE_WritePixels_RLE(FILE *fp, float *data, int scanline_width,
/* run length encoding is not allowed so write flat*/
return RGBE_WritePixels(fp,data,scanline_width*num_scanlines);
buffer = (unsigned char *)malloc(sizeof(unsigned char)*4*scanline_width);
if (buffer == NULL)
if (buffer == NULL)
/* no buffer space so write flat */
return RGBE_WritePixels(fp,data,scanline_width*num_scanlines);
while(num_scanlines-- > 0) {
rgbe[0] = 2;
rgbe[1] = 2;
rgbe[2] = scanline_width >> 8;
rgbe[2] = static_cast<unsigned char>(scanline_width >> 8);
rgbe[3] = scanline_width & 0xFF;
if (fwrite(rgbe, sizeof(rgbe), 1, fp) < 1) {
free(buffer);
@@ -343,7 +341,7 @@ int RGBE_WritePixels_RLE(FILE *fp, float *data, int scanline_width,
}
for(i=0;i<scanline_width;i++) {
float2rgbe(rgbe,data[RGBE_DATA_RED],
data[RGBE_DATA_GREEN],data[RGBE_DATA_BLUE]);
data[RGBE_DATA_GREEN],data[RGBE_DATA_BLUE]);
buffer[i] = rgbe[0];
buffer[i+scanline_width] = rgbe[1];
buffer[i+2*scanline_width] = rgbe[2];
@@ -354,18 +352,18 @@ int RGBE_WritePixels_RLE(FILE *fp, float *data, int scanline_width,
/* first red, then green, then blue, then exponent */
for(i=0;i<4;i++) {
if ((err = RGBE_WriteBytes_RLE(fp,&buffer[i*scanline_width],
scanline_width)) != RGBE_RETURN_SUCCESS) {
free(buffer);
return err;
scanline_width)) != RGBE_RETURN_SUCCESS) {
free(buffer);
return err;
}
}
}
free(buffer);
return RGBE_RETURN_SUCCESS;
}
int RGBE_ReadPixels_RLE(FILE *fp, float *data, int scanline_width,
int num_scanlines)
int num_scanlines)
{
unsigned char rgbe[4], *scanline_buffer, *ptr, *ptr_end;
int i, count;
@@ -394,45 +392,45 @@ int RGBE_ReadPixels_RLE(FILE *fp, float *data, int scanline_width,
}
if (scanline_buffer == NULL)
scanline_buffer = (unsigned char *)
malloc(sizeof(unsigned char)*4*scanline_width);
if (scanline_buffer == NULL)
malloc(sizeof(unsigned char)*4*scanline_width);
if (scanline_buffer == NULL)
return rgbe_error(rgbe_memory_error,"unable to allocate buffer space");
ptr = &scanline_buffer[0];
/* read each of the four channels for the scanline into the buffer */
for(i=0;i<4;i++) {
ptr_end = &scanline_buffer[(i+1)*scanline_width];
while(ptr < ptr_end) {
if (fread(buf,sizeof(buf[0])*2,1,fp) < 1) {
free(scanline_buffer);
return rgbe_error(rgbe_read_error,NULL);
}
if (buf[0] > 128) {
/* a run of the same value */
count = buf[0]-128;
if ((count == 0)||(count > ptr_end - ptr)) {
free(scanline_buffer);
return rgbe_error(rgbe_format_error,"bad scanline data");
}
while(count-- > 0)
*ptr++ = buf[1];
}
else {
/* a non-run */
count = buf[0];
if ((count == 0)||(count > ptr_end - ptr)) {
free(scanline_buffer);
return rgbe_error(rgbe_format_error,"bad scanline data");
}
*ptr++ = buf[1];
if (--count > 0) {
if (fread(ptr,sizeof(*ptr)*count,1,fp) < 1) {
free(scanline_buffer);
return rgbe_error(rgbe_read_error,NULL);
}
ptr += count;
}
}
if (fread(buf,sizeof(buf[0])*2,1,fp) < 1) {
free(scanline_buffer);
return rgbe_error(rgbe_read_error,NULL);
}
if (buf[0] > 128) {
/* a run of the same value */
count = buf[0]-128;
if ((count == 0)||(count > ptr_end - ptr)) {
free(scanline_buffer);
return rgbe_error(rgbe_format_error,"bad scanline data");
}
while(count-- > 0)
*ptr++ = buf[1];
}
else {
/* a non-run */
count = buf[0];
if ((count == 0)||(count > ptr_end - ptr)) {
free(scanline_buffer);
return rgbe_error(rgbe_format_error,"bad scanline data");
}
*ptr++ = buf[1];
if (--count > 0) {
if (fread(ptr,sizeof(*ptr)*count,1,fp) < 1) {
free(scanline_buffer);
return rgbe_error(rgbe_read_error,NULL);
}
ptr += count;
}
}
}
}
/* now convert data from buffer into floats */
@@ -442,7 +440,7 @@ int RGBE_ReadPixels_RLE(FILE *fp, float *data, int scanline_width,
rgbe[2] = scanline_buffer[i+2*scanline_width];
rgbe[3] = scanline_buffer[i+3*scanline_width];
rgbe2float(&data[RGBE_DATA_RED],&data[RGBE_DATA_GREEN],
&data[RGBE_DATA_BLUE],rgbe);
&data[RGBE_DATA_BLUE],rgbe);
data += RGBE_DATA_SIZE;
}
num_scanlines--;
@@ -450,4 +448,3 @@ int RGBE_ReadPixels_RLE(FILE *fp, float *data, int scanline_width,
free(scanline_buffer);
return RGBE_RETURN_SUCCESS;
}

View File

@@ -51,13 +51,13 @@
typedef struct {
int valid; /* indicate which fields are valid */
char programtype[16]; /* listed at beginning of file to identify it
* after "#?". defaults to "RGBE" */
float gamma; /* image has already been gamma corrected with
char programtype[16]; /* listed at beginning of file to identify it
* after "#?". defaults to "RGBE" */
float gamma; /* image has already been gamma corrected with
* given gamma. defaults to 1.0 (no correction) */
float exposure; /* a value of 1.0 in an image corresponds to
* <exposure> watts/steradian/m^2.
* defaults to 1.0 */
* <exposure> watts/steradian/m^2.
* defaults to 1.0 */
} rgbe_header_info;
/* flags indicating which fields in an rgbe_header_info are valid */
@@ -82,11 +82,8 @@ int RGBE_ReadPixels(FILE *fp, float *data, int numpixels);
/* read or write run length encoded files */
/* must be called to read or write whole scanlines */
int RGBE_WritePixels_RLE(FILE *fp, float *data, int scanline_width,
int num_scanlines);
int num_scanlines);
int RGBE_ReadPixels_RLE(FILE *fp, float *data, int scanline_width,
int num_scanlines);
int num_scanlines);
#endif/*_RGBE_HDR_H_*/

View File

@@ -479,11 +479,7 @@ TEST(Highgui_WebP, encode_decode_lossless_webp)
TEST(Highgui_WebP, encode_decode_lossy_webp)
{
cvtest::TS& ts = *cvtest::TS::ptr();
<<<<<<< HEAD
string input = string(ts.get_data_path()) + "/../cv/shared/lena.png";
=======
std::string input = std::string(ts.get_data_path()) + "../cv/shared/lena.png";
>>>>>>> 99a43257d5912ff215016e1cf5f4e0c2a934b72f
cv::Mat img = cv::imread(input);
ASSERT_FALSE(img.empty());
@@ -533,24 +529,24 @@ TEST(Highgui_WebP, encode_decode_with_alpha_webp)
TEST(Highgui_Hdr, regression)
{
string folder = string(cvtest::TS::ptr()->get_data_path()) + "/readwrite/";
string name_rle = folder + "rle.hdr";
string name_no_rle = folder + "no_rle.hdr";
Mat img_rle = imread(name_rle, -1);
ASSERT_FALSE(img_rle.empty()) << "Could not open " << name_rle;
Mat img_no_rle = imread(name_no_rle, -1);
ASSERT_FALSE(img_no_rle.empty()) << "Could not open " << name_no_rle;
string name_rle = folder + "rle.hdr";
string name_no_rle = folder + "no_rle.hdr";
Mat img_rle = imread(name_rle, -1);
ASSERT_FALSE(img_rle.empty()) << "Could not open " << name_rle;
Mat img_no_rle = imread(name_no_rle, -1);
ASSERT_FALSE(img_no_rle.empty()) << "Could not open " << name_no_rle;
double min = 0.0, max = 1.0;
minMaxLoc(abs(img_rle - img_no_rle), &min, &max);
double min = 0.0, max = 1.0;
minMaxLoc(abs(img_rle - img_no_rle), &min, &max);
ASSERT_FALSE(max > DBL_EPSILON);
string tmp_file_name = tempfile(".hdr");
vector<int>param(1);
for(int i = 0; i < 2; i++) {
param[0] = i;
imwrite(tmp_file_name, img_rle, param);
Mat written_img = imread(tmp_file_name, -1);
ASSERT_FALSE(written_img.empty()) << "Could not open " << tmp_file_name;
minMaxLoc(abs(img_rle - written_img), &min, &max);
string tmp_file_name = tempfile(".hdr");
vector<int>param(1);
for(int i = 0; i < 2; i++) {
param[0] = i;
imwrite(tmp_file_name, img_rle, param);
Mat written_img = imread(tmp_file_name, -1);
ASSERT_FALSE(written_img.empty()) << "Could not open " << tmp_file_name;
minMaxLoc(abs(img_rle - written_img), &min, &max);
ASSERT_FALSE(max > DBL_EPSILON);
}
}
}