mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 03:00:14 +08:00
Merge pull request #26152 from sturkmen72:m_buf_supported
Documentation update for imagecodecs #26152 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
parent
e043d5d9d6
commit
f503890c2b
@ -222,9 +222,9 @@ enum ImwriteHDRCompressionFlags {
|
|||||||
|
|
||||||
@anchor imread
|
@anchor imread
|
||||||
|
|
||||||
The function imread loads an image from the specified file and returns it. If the image cannot be
|
The `imread` function loads an image from the specified file and returns OpenCV matrix. If the image cannot be
|
||||||
read (because of missing file, improper permissions, unsupported or invalid format), the function
|
read (because of a missing file, improper permissions, or unsupported/invalid format), the function
|
||||||
returns an empty matrix ( Mat::data==NULL ).
|
returns an empty matrix.
|
||||||
|
|
||||||
Currently, the following file formats are supported:
|
Currently, the following file formats are supported:
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ Currently, the following file formats are supported:
|
|||||||
- Portable Network Graphics - \*.png (see the *Note* section)
|
- Portable Network Graphics - \*.png (see the *Note* section)
|
||||||
- WebP - \*.webp (see the *Note* section)
|
- WebP - \*.webp (see the *Note* section)
|
||||||
- AVIF - \*.avif (see the *Note* section)
|
- AVIF - \*.avif (see the *Note* section)
|
||||||
- Portable image format - \*.pbm, \*.pgm, \*.ppm \*.pxm, \*.pnm (always supported)
|
- Portable image format - \*.pbm, \*.pgm, \*.ppm, \*.pxm, \*.pnm (always supported)
|
||||||
- PFM files - \*.pfm (see the *Note* section)
|
- PFM files - \*.pfm (see the *Note* section)
|
||||||
- Sun rasters - \*.sr, \*.ras (always supported)
|
- Sun rasters - \*.sr, \*.ras (always supported)
|
||||||
- TIFF files - \*.tiff, \*.tif (see the *Note* section)
|
- TIFF files - \*.tiff, \*.tif (see the *Note* section)
|
||||||
@ -243,32 +243,31 @@ Currently, the following file formats are supported:
|
|||||||
- Raster and Vector geospatial data supported by GDAL (see the *Note* section)
|
- Raster and Vector geospatial data supported by GDAL (see the *Note* section)
|
||||||
|
|
||||||
@note
|
@note
|
||||||
- The function determines the type of an image by the content, not by the file extension.
|
- The function determines the type of an image by its content, not by the file extension.
|
||||||
- In the case of color images, the decoded images will have the channels stored in **B G R** order.
|
- In the case of color images, the decoded images will have the channels stored in **B G R** order.
|
||||||
- When using IMREAD_GRAYSCALE, the codec's internal grayscale conversion will be used, if available.
|
- When using IMREAD_GRAYSCALE, the codec's internal grayscale conversion will be used, if available.
|
||||||
Results may differ to the output of cvtColor()
|
Results may differ from the output of cvtColor().
|
||||||
- On Microsoft Windows\* OS and MacOSX\*, the codecs shipped with an OpenCV image (libjpeg,
|
- On Microsoft Windows\* and Mac OS\*, the codecs shipped with OpenCV (libjpeg, libpng, libtiff,
|
||||||
libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs,
|
and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, and TIFFs. On Mac OS,
|
||||||
and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware
|
there is also an option to use native Mac OS image readers. However, beware that currently these
|
||||||
that currently these native image loaders give images with different pixel values because of
|
native image loaders give images with different pixel values because of the color management embedded
|
||||||
the color management embedded into MacOSX.
|
into Mac OS.
|
||||||
- On Linux\*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for
|
- On Linux\*, BSD flavors, and other Unix-like open-source operating systems, OpenCV looks for
|
||||||
codecs supplied with an OS image. Install the relevant packages (do not forget the development
|
codecs supplied with the OS. Ensure the relevant packages are installed (including development
|
||||||
files, for example, "libjpeg-dev", in Debian\* and Ubuntu\*) to get the codec support or turn
|
files, such as "libjpeg-dev" in Debian\* and Ubuntu\*) to get codec support, or turn
|
||||||
on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake.
|
on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake.
|
||||||
- In the case you set *WITH_GDAL* flag to true in CMake and @ref IMREAD_LOAD_GDAL to load the image,
|
- If the *WITH_GDAL* flag is set to true in CMake and @ref IMREAD_LOAD_GDAL is used to load the image,
|
||||||
then the [GDAL](http://www.gdal.org) driver will be used in order to decode the image, supporting
|
the [GDAL](http://www.gdal.org) driver will be used to decode the image, supporting
|
||||||
the following formats: [Raster](http://www.gdal.org/formats_list.html),
|
[Raster](http://www.gdal.org/formats_list.html) and [Vector](http://www.gdal.org/ogr_formats.html) formats.
|
||||||
[Vector](http://www.gdal.org/ogr_formats.html).
|
- If EXIF information is embedded in the image file, the EXIF orientation will be taken into account,
|
||||||
- If EXIF information is embedded in the image file, the EXIF orientation will be taken into account
|
and thus the image will be rotated accordingly unless the flags @ref IMREAD_IGNORE_ORIENTATION
|
||||||
and thus the image will be rotated accordingly except if the flags @ref IMREAD_IGNORE_ORIENTATION
|
|
||||||
or @ref IMREAD_UNCHANGED are passed.
|
or @ref IMREAD_UNCHANGED are passed.
|
||||||
- Use the IMREAD_UNCHANGED flag to keep the floating point values from PFM image.
|
- Use the IMREAD_UNCHANGED flag to preserve the floating-point values from PFM images.
|
||||||
- By default number of pixels must be less than 2^30. Limit can be set using system
|
- By default, the number of pixels must be less than 2^30. This limit can be changed by setting
|
||||||
variable OPENCV_IO_MAX_IMAGE_PIXELS
|
the environment variable `OPENCV_IO_MAX_IMAGE_PIXELS`. See @ref tutorial_env_reference.
|
||||||
|
|
||||||
@param filename Name of file to be loaded.
|
@param filename Name of the file to be loaded.
|
||||||
@param flags Flag that can take values of cv::ImreadModes
|
@param flags Flag that can take values of `cv::ImreadModes`.
|
||||||
*/
|
*/
|
||||||
CV_EXPORTS_W Mat imread( const String& filename, int flags = IMREAD_COLOR_BGR );
|
CV_EXPORTS_W Mat imread( const String& filename, int flags = IMREAD_COLOR_BGR );
|
||||||
|
|
||||||
|
@ -1,44 +1,6 @@
|
|||||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
// This file is part of OpenCV project.
|
||||||
//
|
// It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
// directory of this distribution and at http://opencv.org/license.html
|
||||||
//
|
|
||||||
// By downloading, copying, installing or using the software you agree to this license.
|
|
||||||
// If you do not agree to this license, do not download, install,
|
|
||||||
// copy or use the software.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// License Agreement
|
|
||||||
// For Open Source Computer Vision Library
|
|
||||||
//
|
|
||||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
|
||||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
|
||||||
// Third party copyrights are property of their respective owners.
|
|
||||||
//
|
|
||||||
// Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
// are permitted provided that the following conditions are met:
|
|
||||||
//
|
|
||||||
// * Redistribution's of source code must retain the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer.
|
|
||||||
//
|
|
||||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
|
||||||
// and/or other materials provided with the distribution.
|
|
||||||
//
|
|
||||||
// * The name of the copyright holders may not be used to endorse or promote products
|
|
||||||
// derived from this software without specific prior written permission.
|
|
||||||
//
|
|
||||||
// This software is provided by the copyright holders and contributors "as is" and
|
|
||||||
// any express or implied warranties, including, but not limited to, the implied
|
|
||||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
||||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
||||||
// indirect, incidental, special, exemplary, or consequential damages
|
|
||||||
// (including, but not limited to, procurement of substitute goods or services;
|
|
||||||
// loss of use, data, or profits; or business interruption) however caused
|
|
||||||
// and on any theory of liability, whether in contract, strict liability,
|
|
||||||
// or tort (including negligence or otherwise) arising in any way out of
|
|
||||||
// the use of this software, even if advised of the possibility of such damage.
|
|
||||||
//
|
|
||||||
//M*/
|
|
||||||
|
|
||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
#include "bitstrm.hpp"
|
#include "bitstrm.hpp"
|
||||||
@ -49,11 +11,6 @@ namespace cv
|
|||||||
|
|
||||||
const int BS_DEF_BLOCK_SIZE = 1<<15;
|
const int BS_DEF_BLOCK_SIZE = 1<<15;
|
||||||
|
|
||||||
bool bsIsBigEndian( void )
|
|
||||||
{
|
|
||||||
return (((const int*)"\0\x1\x2\x3\x4\x5\x6\x7")[0] & 255) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////// RBaseStream ////////////////////////////
|
///////////////////////// RBaseStream ////////////////////////////
|
||||||
|
|
||||||
bool RBaseStream::isOpened()
|
bool RBaseStream::isOpened()
|
||||||
|
@ -1,44 +1,6 @@
|
|||||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
// This file is part of OpenCV project.
|
||||||
//
|
// It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
// directory of this distribution and at http://opencv.org/license.html
|
||||||
//
|
|
||||||
// By downloading, copying, installing or using the software you agree to this license.
|
|
||||||
// If you do not agree to this license, do not download, install,
|
|
||||||
// copy or use the software.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// License Agreement
|
|
||||||
// For Open Source Computer Vision Library
|
|
||||||
//
|
|
||||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
|
||||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
|
||||||
// Third party copyrights are property of their respective owners.
|
|
||||||
//
|
|
||||||
// Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
// are permitted provided that the following conditions are met:
|
|
||||||
//
|
|
||||||
// * Redistribution's of source code must retain the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer.
|
|
||||||
//
|
|
||||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
|
||||||
// and/or other materials provided with the distribution.
|
|
||||||
//
|
|
||||||
// * The name of the copyright holders may not be used to endorse or promote products
|
|
||||||
// derived from this software without specific prior written permission.
|
|
||||||
//
|
|
||||||
// This software is provided by the copyright holders and contributors "as is" and
|
|
||||||
// any express or implied warranties, including, but not limited to, the implied
|
|
||||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
||||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
||||||
// indirect, incidental, special, exemplary, or consequential damages
|
|
||||||
// (including, but not limited to, procurement of substitute goods or services;
|
|
||||||
// loss of use, data, or profits; or business interruption) however caused
|
|
||||||
// and on any theory of liability, whether in contract, strict liability,
|
|
||||||
// or tort (including negligence or otherwise) arising in any way out of
|
|
||||||
// the use of this software, even if advised of the possibility of such damage.
|
|
||||||
//
|
|
||||||
//M*/
|
|
||||||
|
|
||||||
#ifndef _BITSTRM_H_
|
#ifndef _BITSTRM_H_
|
||||||
#define _BITSTRM_H_
|
#define _BITSTRM_H_
|
||||||
@ -183,13 +145,6 @@ public:
|
|||||||
bool putDWord( int val );
|
bool putDWord( int val );
|
||||||
};
|
};
|
||||||
|
|
||||||
inline unsigned BSWAP(unsigned v)
|
|
||||||
{
|
|
||||||
return (v<<24)|((v&0xff00)<<8)|((v>>8)&0xff00)|((unsigned)v>>24);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bsIsBigEndian( void );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif/*_BITSTRM_H_*/
|
#endif/*_BITSTRM_H_*/
|
||||||
|
@ -1,44 +1,6 @@
|
|||||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
// This file is part of OpenCV project.
|
||||||
//
|
// It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
// directory of this distribution and at http://opencv.org/license.html
|
||||||
//
|
|
||||||
// By downloading, copying, installing or using the software you agree to this license.
|
|
||||||
// If you do not agree to this license, do not download, install,
|
|
||||||
// copy or use the software.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// License Agreement
|
|
||||||
// For Open Source Computer Vision Library
|
|
||||||
//
|
|
||||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
|
||||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
|
||||||
// Third party copyrights are property of their respective owners.
|
|
||||||
//
|
|
||||||
// Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
// are permitted provided that the following conditions are met:
|
|
||||||
//
|
|
||||||
// * Redistribution's of source code must retain the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer.
|
|
||||||
//
|
|
||||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
|
||||||
// and/or other materials provided with the distribution.
|
|
||||||
//
|
|
||||||
// * The name of the copyright holders may not be used to endorse or promote products
|
|
||||||
// derived from this software without specific prior written permission.
|
|
||||||
//
|
|
||||||
// This software is provided by the copyright holders and contributors "as is" and
|
|
||||||
// any express or implied warranties, including, but not limited to, the implied
|
|
||||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
||||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
||||||
// indirect, incidental, special, exemplary, or consequential damages
|
|
||||||
// (including, but not limited to, procurement of substitute goods or services;
|
|
||||||
// loss of use, data, or profits; or business interruption) however caused
|
|
||||||
// and on any theory of liability, whether in contract, strict liability,
|
|
||||||
// or tort (including negligence or otherwise) arising in any way out of
|
|
||||||
// the use of this software, even if advised of the possibility of such damage.
|
|
||||||
//
|
|
||||||
//M*/
|
|
||||||
|
|
||||||
#ifndef _GRFMT_BASE_H_
|
#ifndef _GRFMT_BASE_H_
|
||||||
#define _GRFMT_BASE_H_
|
#define _GRFMT_BASE_H_
|
||||||
@ -55,75 +17,228 @@ class BaseImageEncoder;
|
|||||||
typedef Ptr<BaseImageEncoder> ImageEncoder;
|
typedef Ptr<BaseImageEncoder> ImageEncoder;
|
||||||
typedef Ptr<BaseImageDecoder> ImageDecoder;
|
typedef Ptr<BaseImageDecoder> ImageDecoder;
|
||||||
|
|
||||||
///////////////////////////////// base class for decoders ////////////////////////
|
/**
|
||||||
class BaseImageDecoder
|
* @brief Base class for image decoders.
|
||||||
{
|
*
|
||||||
|
* The BaseImageDecoder class provides an abstract interface for decoding various image formats.
|
||||||
|
* It defines common functionality like setting the image source, reading image headers,
|
||||||
|
* and handling EXIF metadata. Derived classes must implement methods for reading image headers
|
||||||
|
* and image data to handle format-specific decoding logic.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class BaseImageDecoder {
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Constructor for BaseImageDecoder.
|
||||||
|
* Initializes the object and sets default values for member variables.
|
||||||
|
*/
|
||||||
BaseImageDecoder();
|
BaseImageDecoder();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Virtual destructor for BaseImageDecoder.
|
||||||
|
* Ensures proper cleanup of derived classes when deleted via a pointer to BaseImageDecoder.
|
||||||
|
*/
|
||||||
virtual ~BaseImageDecoder() {}
|
virtual ~BaseImageDecoder() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the width of the image.
|
||||||
|
* @return The width of the image (in pixels).
|
||||||
|
*/
|
||||||
int width() const { return m_width; }
|
int width() const { return m_width; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the height of the image.
|
||||||
|
* @return The height of the image (in pixels).
|
||||||
|
*/
|
||||||
int height() const { return m_height; }
|
int height() const { return m_height; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the number of frames in the image or animation.
|
||||||
|
* @return The number of frames in the image.
|
||||||
|
*/
|
||||||
size_t getFrameCount() const { return m_frame_count; }
|
size_t getFrameCount() const { return m_frame_count; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the type of the image (e.g., color format, depth).
|
||||||
|
* @return The type of the image.
|
||||||
|
*/
|
||||||
virtual int type() const { return m_type; }
|
virtual int type() const { return m_type; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Fetch a specific EXIF tag from the image's metadata.
|
||||||
|
* @param tag The EXIF tag to retrieve.
|
||||||
|
* @return The EXIF entry corresponding to the tag.
|
||||||
|
*/
|
||||||
ExifEntry_t getExifTag(const ExifTagName tag) const;
|
ExifEntry_t getExifTag(const ExifTagName tag) const;
|
||||||
virtual bool setSource( const String& filename );
|
|
||||||
virtual bool setSource( const Mat& buf );
|
|
||||||
virtual int setScale( const int& scale_denom );
|
|
||||||
virtual bool readHeader() = 0;
|
|
||||||
virtual bool readData( Mat& img ) = 0;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the image source from a file.
|
||||||
|
* @param filename The name of the file to load the image from.
|
||||||
|
* @return true if the source was successfully set, false otherwise.
|
||||||
|
*/
|
||||||
|
virtual bool setSource(const String& filename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the image source from a memory buffer.
|
||||||
|
* @param buf The buffer containing the image data.
|
||||||
|
* @return true if the source was successfully set, false otherwise.
|
||||||
|
*/
|
||||||
|
virtual bool setSource(const Mat& buf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the scale factor for the image.
|
||||||
|
* @param scale_denom The denominator of the scale factor (image is scaled down by 1/scale_denom).
|
||||||
|
* @return The scale factor that was set.
|
||||||
|
*/
|
||||||
|
virtual int setScale(const int& scale_denom);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read the image header to extract basic properties (width, height, type).
|
||||||
|
* This is a pure virtual function that must be implemented by derived classes.
|
||||||
|
* @return true if the header was successfully read, false otherwise.
|
||||||
|
*/
|
||||||
|
virtual bool readHeader() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read the image data into a Mat object.
|
||||||
|
* This is a pure virtual function that must be implemented by derived classes.
|
||||||
|
* @param img The Mat object where the image data will be stored.
|
||||||
|
* @return true if the data was successfully read, false otherwise.
|
||||||
|
*/
|
||||||
|
virtual bool readData(Mat& img) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set whether to decode the image in RGB order instead of the default BGR.
|
||||||
|
* @param useRGB If true, the image will be decoded in RGB order.
|
||||||
|
*/
|
||||||
virtual void setRGB(bool useRGB);
|
virtual void setRGB(bool useRGB);
|
||||||
|
|
||||||
/// Called after readData to advance to the next page, if any.
|
/**
|
||||||
|
* @brief Advance to the next page or frame of the image, if applicable.
|
||||||
|
* The default implementation does nothing and returns false.
|
||||||
|
* @return true if there is another page/frame, false otherwise.
|
||||||
|
*/
|
||||||
virtual bool nextPage() { return false; }
|
virtual bool nextPage() { return false; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the length of the format signature used to identify the image format.
|
||||||
|
* @return The length of the signature.
|
||||||
|
*/
|
||||||
virtual size_t signatureLength() const;
|
virtual size_t signatureLength() const;
|
||||||
virtual bool checkSignature( const String& signature ) const;
|
|
||||||
|
/**
|
||||||
|
* @brief Check if the provided signature matches the expected format signature.
|
||||||
|
* @param signature The signature to check.
|
||||||
|
* @return true if the signature matches, false otherwise.
|
||||||
|
*/
|
||||||
|
virtual bool checkSignature(const String& signature) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create and return a new instance of the derived image decoder.
|
||||||
|
* @return A new ImageDecoder object.
|
||||||
|
*/
|
||||||
virtual ImageDecoder newDecoder() const;
|
virtual ImageDecoder newDecoder() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int m_width; // width of the image ( filled by readHeader )
|
int m_width; ///< Width of the image (set by readHeader).
|
||||||
int m_height; // height of the image ( filled by readHeader )
|
int m_height; ///< Height of the image (set by readHeader).
|
||||||
int m_type;
|
int m_type; ///< Image type (e.g., color depth, channel order).
|
||||||
int m_scale_denom;
|
int m_scale_denom; ///< Scale factor denominator for resizing the image.
|
||||||
String m_filename;
|
String m_filename; ///< Name of the file that is being decoded.
|
||||||
String m_signature;
|
String m_signature; ///< Signature for identifying the image format.
|
||||||
Mat m_buf;
|
Mat m_buf; ///< Buffer holding the image data when loaded from memory.
|
||||||
bool m_buf_supported;
|
bool m_buf_supported; ///< Flag indicating whether buffer-based loading is supported.
|
||||||
bool m_use_rgb; // flag of decode image as RGB order instead of BGR.
|
bool m_use_rgb; ///< Flag indicating whether to decode the image in RGB order.
|
||||||
ExifReader m_exif;
|
ExifReader m_exif; ///< Object for reading EXIF metadata from the image.
|
||||||
size_t m_frame_count;
|
size_t m_frame_count; ///< Number of frames in the image (for animations and multi-page images).
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////// base class for encoders ////////////////////////////
|
/**
|
||||||
class BaseImageEncoder
|
* @brief Base class for image encoders.
|
||||||
{
|
*
|
||||||
|
* The BaseImageEncoder class provides an abstract interface for encoding images in various formats.
|
||||||
|
* It defines common functionality like setting the destination (file or memory buffer), checking if
|
||||||
|
* the format supports a specific image depth, and writing image data. Derived classes must implement
|
||||||
|
* methods like writing the image data to handle format-specific encoding logic.
|
||||||
|
*/
|
||||||
|
class BaseImageEncoder {
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Constructor for BaseImageEncoder.
|
||||||
|
* Initializes the object and sets default values for member variables.
|
||||||
|
*/
|
||||||
BaseImageEncoder();
|
BaseImageEncoder();
|
||||||
virtual ~BaseImageEncoder() {}
|
|
||||||
virtual bool isFormatSupported( int depth ) const;
|
|
||||||
|
|
||||||
virtual bool setDestination( const String& filename );
|
/**
|
||||||
virtual bool setDestination( std::vector<uchar>& buf );
|
* @brief Virtual destructor for BaseImageEncoder.
|
||||||
virtual bool write( const Mat& img, const std::vector<int>& params ) = 0;
|
* Ensures proper cleanup of derived classes when deleted via a pointer to BaseImageEncoder.
|
||||||
|
*/
|
||||||
|
virtual ~BaseImageEncoder() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if the image format supports a specific image depth.
|
||||||
|
* @param depth The depth (bit depth) of the image.
|
||||||
|
* @return true if the format supports the specified depth, false otherwise.
|
||||||
|
*/
|
||||||
|
virtual bool isFormatSupported(int depth) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the destination for encoding as a file.
|
||||||
|
* @param filename The name of the file to which the image will be written.
|
||||||
|
* @return true if the destination was successfully set, false otherwise.
|
||||||
|
*/
|
||||||
|
virtual bool setDestination(const String& filename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the destination for encoding as a memory buffer.
|
||||||
|
* @param buf A reference to the buffer where the encoded image data will be stored.
|
||||||
|
* @return true if the destination was successfully set, false otherwise.
|
||||||
|
*/
|
||||||
|
virtual bool setDestination(std::vector<uchar>& buf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Encode and write the image data.
|
||||||
|
* This is a pure virtual function that must be implemented by derived classes.
|
||||||
|
* @param img The Mat object containing the image data to be encoded.
|
||||||
|
* @param params A vector of parameters controlling the encoding process (e.g., compression level).
|
||||||
|
* @return true if the image was successfully written, false otherwise.
|
||||||
|
*/
|
||||||
|
virtual bool write(const Mat& img, const std::vector<int>& params) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Encode and write multiple images (e.g., for animated formats).
|
||||||
|
* By default, this method returns false, indicating that the format does not support multi-image encoding.
|
||||||
|
* @param img_vec A vector of Mat objects containing the images to be encoded.
|
||||||
|
* @param params A vector of parameters controlling the encoding process.
|
||||||
|
* @return true if multiple images were successfully written, false otherwise.
|
||||||
|
*/
|
||||||
virtual bool writemulti(const std::vector<Mat>& img_vec, const std::vector<int>& params);
|
virtual bool writemulti(const std::vector<Mat>& img_vec, const std::vector<int>& params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get a description of the image encoder (e.g., the format it supports).
|
||||||
|
* @return A string describing the encoder.
|
||||||
|
*/
|
||||||
virtual String getDescription() const;
|
virtual String getDescription() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create and return a new instance of the derived image encoder.
|
||||||
|
* @return A new ImageEncoder object.
|
||||||
|
*/
|
||||||
virtual ImageEncoder newEncoder() const;
|
virtual ImageEncoder newEncoder() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Throw an exception based on the last error encountered during encoding.
|
||||||
|
* This method can be used to propagate error conditions back to the caller.
|
||||||
|
*/
|
||||||
virtual void throwOnEror() const;
|
virtual void throwOnEror() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
String m_description;
|
String m_description; ///< Description of the encoder (e.g., format name, capabilities).
|
||||||
|
String m_filename; ///< Destination file name for encoded data.
|
||||||
String m_filename;
|
std::vector<uchar>* m_buf; ///< Pointer to the buffer for encoded data if using memory-based destination.
|
||||||
std::vector<uchar>* m_buf;
|
bool m_buf_supported; ///< Flag indicating whether buffer-based encoding is supported.
|
||||||
bool m_buf_supported;
|
String m_last_error; ///< Stores the last error message encountered during encoding.
|
||||||
|
|
||||||
String m_last_error;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -81,20 +81,17 @@ PFMDecoder::~PFMDecoder()
|
|||||||
|
|
||||||
PFMDecoder::PFMDecoder() : m_scale_factor(0), m_swap_byte_order(false)
|
PFMDecoder::PFMDecoder() : m_scale_factor(0), m_swap_byte_order(false)
|
||||||
{
|
{
|
||||||
m_strm.close();
|
m_buf_supported = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PFMDecoder::readHeader()
|
bool PFMDecoder::readHeader()
|
||||||
{
|
{
|
||||||
if (m_buf.empty()) {
|
if (!m_buf.empty())
|
||||||
if (!m_strm.open(m_filename)) {
|
m_strm.open(m_buf);
|
||||||
return false;
|
else
|
||||||
}
|
m_strm.open(m_filename);
|
||||||
} else {
|
|
||||||
if (!m_strm.open(m_buf)) {
|
if( !m_strm.isOpened()) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_strm.getByte() != 'P') {
|
if (m_strm.getByte() != 'P') {
|
||||||
CV_Error(Error::StsError, "Unexpected file type (expected P)");
|
CV_Error(Error::StsError, "Unexpected file type (expected P)");
|
||||||
@ -177,6 +174,7 @@ void PFMDecoder::close()
|
|||||||
PFMEncoder::PFMEncoder()
|
PFMEncoder::PFMEncoder()
|
||||||
{
|
{
|
||||||
m_description = "Portable image format - float (*.pfm)";
|
m_description = "Portable image format - float (*.pfm)";
|
||||||
|
m_buf_supported = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
PFMEncoder::~PFMEncoder()
|
PFMEncoder::~PFMEncoder()
|
||||||
|
@ -1,44 +1,6 @@
|
|||||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
// This file is part of OpenCV project.
|
||||||
//
|
// It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
// directory of this distribution and at http://opencv.org/license.html
|
||||||
//
|
|
||||||
// By downloading, copying, installing or using the software you agree to this license.
|
|
||||||
// If you do not agree to this license, do not download, install,
|
|
||||||
// copy or use the software.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// License Agreement
|
|
||||||
// For Open Source Computer Vision Library
|
|
||||||
//
|
|
||||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
|
||||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
|
||||||
// Third party copyrights are property of their respective owners.
|
|
||||||
//
|
|
||||||
// Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
// are permitted provided that the following conditions are met:
|
|
||||||
//
|
|
||||||
// * Redistribution's of source code must retain the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer.
|
|
||||||
//
|
|
||||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
|
||||||
// and/or other materials provided with the distribution.
|
|
||||||
//
|
|
||||||
// * The name of the copyright holders may not be used to endorse or promote products
|
|
||||||
// derived from this software without specific prior written permission.
|
|
||||||
//
|
|
||||||
// This software is provided by the copyright holders and contributors "as is" and
|
|
||||||
// any express or implied warranties, including, but not limited to, the implied
|
|
||||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
||||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
||||||
// indirect, incidental, special, exemplary, or consequential damages
|
|
||||||
// (including, but not limited to, procurement of substitute goods or services;
|
|
||||||
// loss of use, data, or profits; or business interruption) however caused
|
|
||||||
// and on any theory of liability, whether in contract, strict liability,
|
|
||||||
// or tort (including negligence or otherwise) arising in any way out of
|
|
||||||
// the use of this software, even if advised of the possibility of such damage.
|
|
||||||
//
|
|
||||||
//M*/
|
|
||||||
|
|
||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
#include "grfmt_sunras.hpp"
|
#include "grfmt_sunras.hpp"
|
||||||
@ -60,6 +22,7 @@ SunRasterDecoder::SunRasterDecoder()
|
|||||||
m_encoding = RAS_STANDARD;
|
m_encoding = RAS_STANDARD;
|
||||||
m_maptype = RMT_NONE;
|
m_maptype = RMT_NONE;
|
||||||
m_maplength = 0;
|
m_maplength = 0;
|
||||||
|
m_buf_supported = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -82,7 +45,12 @@ bool SunRasterDecoder::readHeader()
|
|||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if( !m_strm.open( m_filename )) return false;
|
if (!m_buf.empty())
|
||||||
|
m_strm.open(m_buf);
|
||||||
|
else
|
||||||
|
m_strm.open(m_filename);
|
||||||
|
|
||||||
|
if( !m_strm.isOpened()) return false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -389,6 +357,7 @@ bad_decoding_end:
|
|||||||
SunRasterEncoder::SunRasterEncoder()
|
SunRasterEncoder::SunRasterEncoder()
|
||||||
{
|
{
|
||||||
m_description = "Sun raster files (*.sr;*.ras)";
|
m_description = "Sun raster files (*.sr;*.ras)";
|
||||||
|
m_buf_supported = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -408,7 +377,18 @@ bool SunRasterEncoder::write( const Mat& img, const std::vector<int>& )
|
|||||||
int fileStep = (width*channels + 1) & -2;
|
int fileStep = (width*channels + 1) & -2;
|
||||||
WMByteStream strm;
|
WMByteStream strm;
|
||||||
|
|
||||||
if( strm.open(m_filename) )
|
if (m_buf) {
|
||||||
|
if (!strm.open(*m_buf)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_buf->reserve(height * fileStep + 32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
strm.open(m_filename);
|
||||||
|
|
||||||
|
if( strm.isOpened() )
|
||||||
{
|
{
|
||||||
CHECK_WRITE(strm.putBytes( fmtSignSunRas, (int)strlen(fmtSignSunRas) ));
|
CHECK_WRITE(strm.putBytes( fmtSignSunRas, (int)strlen(fmtSignSunRas) ));
|
||||||
CHECK_WRITE(strm.putDWord( width ));
|
CHECK_WRITE(strm.putDWord( width ));
|
||||||
|
@ -336,6 +336,7 @@ TEST_P(Imgcodecs_Avif_Animation_WriteDecodeSuite, encode_decode) {
|
|||||||
file.seekg(0, std::ios::beg);
|
file.seekg(0, std::ios::beg);
|
||||||
std::vector<unsigned char> buf(size);
|
std::vector<unsigned char> buf(size);
|
||||||
EXPECT_TRUE(file.read(reinterpret_cast<char*>(buf.data()), size));
|
EXPECT_TRUE(file.read(reinterpret_cast<char*>(buf.data()), size));
|
||||||
|
file.close();
|
||||||
EXPECT_EQ(0, remove(output.c_str()));
|
EXPECT_EQ(0, remove(output.c_str()));
|
||||||
std::vector<cv::Mat> anim;
|
std::vector<cv::Mat> anim;
|
||||||
ASSERT_TRUE(cv::imdecodemulti(buf, imread_mode_, anim));
|
ASSERT_TRUE(cv::imdecodemulti(buf, imread_mode_, anim));
|
||||||
|
Loading…
Reference in New Issue
Block a user