/** * @class vetCodec_BMP * * @brief A class for encoding (writing) and decoding (reading) * Bitmap Format (BMP) images, implements vetFilter. * * - load from BMP image data file to memory; * - save from memory to BMP image; * * It's Able also to output multiple images with filename * (index) progression. * * @bug * @warning * @todo * * @see vetCodec * @see vetFrameRGB96 * * @example test_vetCodec_BMP.cpp * @example test_vetMultiplexer.cpp * * @version 1.0 * @date 12/07/2005 - //2005 * @author Alessandro Polo * * **************************************************************************** * VETLib Framework 1.0.2 * Copyright (C) Alessandro Polo 2006 * http://www.ewgate.net/vetlib * ****************************************************************************/ #ifndef __VETLIB_VETCODEC_BMP_H__ #define __VETLIB_VETCODEC_BMP_H__ #include "../vetDefs.h" #include "../vetCodec.h" #include "../vetFrameYUV420.h" #include "../vetFrameRGB24.h" #include "../vetFrameT.h" #include "../vetFrameRGB96.h" #include "../vetFrameRGBA32.h" #include "../vetFrameHSV.h" #define VETRET_CODER_FILEOUT_ER 1010 /* */ #define VETRET_CODER_SIZE_ER 1011 /* */ #define VETRET_CODER_WRITE_ER 1012 /* */ #define VETRET_CODER_PALETTE_ER 1013 /* */ class vetCodec_BMPParameters; class vetCodec_BMP : protected vetFrameRGB96, public vetCodec { public: enum FileFormat{ FORMAT_BMP_24, FORMAT_BMP_RC, FORMAT_BMP_MONO, FORMAT_BMP_ANY }; protected: vetCodec_BMPParameters* myParams; char fileNameIndexBuffer[16]; char fileNameBuffer[80]; void doFileNameCurrent(); public: /** * @brief Default constructor, initializa parameters and superclasses. */ vetCodec_BMP(vetCodec_BMPParameters* initParams = NULL); /** * @brief Copy constructor from vetFrameCache image, call superclass * vetFrameRGB copy constructor. * * @param[in] img source VETLib Cache Frame. */ vetCodec_BMP(vetFrameRGB96& img) : vetFrameRGB96(img), vetCodec() { reset(); } /** * @brief Copy constructor from vetFrameRGB image, call superclass * vetFrameRGB copy constructor. * * @param[in] img source Color VETLib Frame. */ vetCodec_BMP(vetFrameRGB24& img) : vetFrameRGB96(img), vetCodec() { reset(); } /** * @brief Creates a new frame from given dimensions, call superclass * vetFrameRGB constructor. * * @param[in] x width of the new frame. * @param[in] y height of the new frame. */ vetCodec_BMP(unsigned int x, unsigned int y) : vetFrameRGB96(x, y), vetCodec() { reset(); } /** * @brief Creates a new frame from given dimensions, call superclass * vetFrameRGB constructor. * * @param[in] filename Input BMP filename. * @param[in] format BMP Encoding Format, default auto-selection. */ vetCodec_BMP(const char* filename, FileFormat format = vetCodec_BMP::FORMAT_BMP_ANY); /** * @brief Save current buffered image to current filename, first * setup current filename and format then call this function. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. */ int save(); /** * @brief Save current buffered image to given filename and format. * * @param[in] filename Output BMP filename. * @param[in] format BMP Encoding Format. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. */ int save(const char *filename, FileFormat format = vetCodec_BMP::FORMAT_BMP_24); /** * @brief Load a BMP format image into current buffer (vetFrameRGB), first * setup current filename and format then call this function. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. */ int load(); /** * @brief Load a BMP format image into current buffer (vetFrameRGB). * * @param[in] filename Input BMP filename. * @param[in] format BMP Encoding Format. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. */ int load(const char *filename, FileFormat format = vetCodec_BMP::FORMAT_BMP_24); /** * @brief Get the state of current data source. * * @return true is there are no more frames to load, false else. */ bool EoF(); /** * @brief Set parameters for (de)coding. * * @param[in] initParams Instance of vetCodec_BMPParameters or NULL, * NULL argument make function to create a new * instance with default parameters. * * @return VETRET_OK */ int setParameters(vetCodec_BMPParameters* initParams); /** * @brief Get parameters for (de)coding. * * @return pointer to vetCodec_MOVParameters class. */ vetCodec_BMPParameters& getParameters() { return *myParams; }; /** * @brief Enable or disable filename progression, for example: * basefile name is "output", index is 13 so filename is output13.bmp, * if filename progression is enabled, when an operation is done * onto file, idex is incremented (output14.bmp). * * @param[in] value true to enable file name progression. */ void setFileNameProgression(bool value); /** * @brief Enable or disable auto input feature, * * * @param[in] * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ void setAutoOutputEnabled(bool value = true); /** * @brief * * * @param[in] * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ void setAutoInputEnabled(bool value = true); /** * @brief * * * @param[in] * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ void setDoBuffering(bool value = true); /** * @brief * * * @param[in] * * @note * @see */ void setFileName(const char *filename); /** * @brief Set current BMP format. * * @param[in] format BMP format enumaration. * * @see FileFormat */ void setFileFormat(FileFormat format = vetCodec_BMP::FORMAT_BMP_24); /** * @brief Read current file name index, used in file name progression * routines. * * @return VETRET_OK if everything is fine, * VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ int getFileNameIndex(); /** * @brief * * * @return true if filename progression is enabled. * * @see fileNameProgression */ bool isFileNameProgressionEnabled(); /** * @brief * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ bool isAutoInputEnabled(); /** * @brief * * * @param[in] * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ bool isAutoOutputEnabled(); /** * @brief * * * @param[in] * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ bool isBufferingEnabled(); /** * @brief Read base filename, if progression is enabled it's the base fixed * name. * * @param[in] * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ void getFileName(char *filename); /** * @brief Read current filename, if progression is enabled it's the base fixed * name + current index + bmp extension. * * @param[out] Char Array to store current filename [Max size 64 chars] * * @see fileNameBase */ void getFileNameCurrent(char *filename); /** * @brief Read current bitmap encoding/decoding format. * * @return Current I/O BMP format. * * @see FileFormat * @see fileFormat */ FileFormat getFileFormat(void); /** * @brief Reset filename related setup. * * @return VETRET_OK if everything is fine, VETRET_INTERNAL_ERR * or VETRET_ILLEGAL_USE else. */ int reset(); /** * @brief read current image's width. * * @return Width in pixel. */ // unsigned int getWidth() const { return width; }; /** * @brief read current image's height. * * @return Height in pixel. */ // unsigned int getHeight() const { return height; }; /** * @brief Set current canvas' height. * * @return height in pixel. */ int setHeight(unsigned int value) { return VETRET_NOT_IMPLEMENTED; }; /** * @brief Set current canvas' width. * * @return width in pixel. */ int setWidth(unsigned int value) { return VETRET_NOT_IMPLEMENTED; }; int getAudioStreamCount() { return -1; }; int getVideoStreamCount() { return -1; }; bool hasAudio() { return false; }; bool hasVideo() { return false; }; long getVideoStreamLength(int stream = -1) { return -1; }; long getAudioStreamLength(int stream = -1) { return -1; }; /** * @brief Load bmp data into image parameter, if AutoInput is enabled * try to load next filename, else just copy current data to img. * * @param[out] img VETLib Cache Frame to store data. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note Ouput operator (>>) call directly this function. * @see operator >> (vetFrameYUV420&) * @see AutoInput */ VETRESULT extractTo(vetFrameYUV420& img); /** * @brief Load bmp data into image parameter, if AutoInput is enabled * try to load next filename, else just copy current data to img. * * @param[out] img VETLib Cache24 Frame to store data. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note Ouput operator (>>) call directly this function. * @see operator >> (vetFrameRGB24&) * @see AutoInput */ VETRESULT extractTo(vetFrameRGB24& img); /** * @brief Load bmp data into image parameter, if AutoInput is enabled * try to load next filename, else just copy current data to img. * * @param[out] img Greyscale VETLib Frame to store data. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note Ouput operator (>>) call directly this function. * @see operator >> (vetFrameT&) * @see AutoInput */ VETRESULT extractTo(vetFrameT& img); /** * @brief Load given image into memory, if AutoOutput is enabled * image data will be saved as a BMP format file. * * @param[in] img VETLib Cache Frame to be processed (encoded for example) * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note Input operator (<<) call directly this function. * @see operator << (vetFrameYUV420&) */ VETRESULT importFrom(vetFrameYUV420& img ); /** * @brief Load given image into memory, if AutoOutput is enabled * image data will be saved as a BMP format file. * * @param[in] img VETLib Cache24 Frame to be processed (encoded for example) * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note Input operator (<<) call directly this function. * @see operator << (vetFrameRGB24&) */ VETRESULT importFrom(vetFrameRGB24& img); /** * @brief Load given image into memory, if AutoOutput is enabled * image data will be saved as a BMP format file. * * @param[in] img Greyscale VETLib Frame to be processed (encoded for example) * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note Input operator (<<) call directly this function. * @see operator << (vetFrameT&) */ VETRESULT importFrom(vetFrameT& img); // call importFrom, so filename index is managed /** * @brief Input operator, import standard VETLib frame formats, * current implementation calls directly importFrom() method. * * @param[in] img VETLib Cache Frame to be processed (encoded for example) * * @see importFrom(vetFrameYUV420&) */ void operator << (vetFrameYUV420& img) { vetOutput::operator << (img); } void operator << (vetFrameRGB24& img) { vetOutput::operator << (img); } void operator << (vetFrameT& img) { vetOutput::operator << (img); } // call extractTo, so filename index and frame rate are managed /** * @brief Ouput operator, export to standard VETLib frame formats, * current implementation calls directly extractTo() method * and if framerate isn't zero waits untill clock is syncronized, * if elaboration time is greater than sleeptime, no delay is applied. * * @param[out] img VETLib Cache Frame to store data. * * @return Address of current instance. * * @see importFrom(vetFrameYUV420&) * @see vetsleep() * @see setElaborationStart() * @see getElaborationTime() */ vetInput& operator >> (vetFrameYUV420& img) { vetInput::operator >> (img); return *this; } vetInput& operator >> (vetFrameRGB24& img) { vetInput::operator >> (img); return *this; } vetInput& operator >> (vetFrameT& img) { vetInput::operator >>( img); return *this; } /** * @brief Save given image to a BMP file. * * @param[in] source VETLib Cache Frame to store data. * @param[in] filename Output BMP filename. * @param[in] format BMP Encoding Format. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. */ static VETRESULT save(vetFrameRGB24 &source, const char *filename,FileFormat format); /** * @brief Save given image to a BMP file. * * @param[in] source VETLib Cache24 Frame to store data. * @param[in] filename Output BMP filename. * @param[in] format BMP Encoding Format. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. */ static VETRESULT save(vetFrameYUV420 &source, const char *filename,FileFormat format); /** * @brief Save given image to a BMP file. * * @param[in] source Color VETLib Frame to store data. * @param[in] filename Output BMP filename. * @param[in] format BMP Encoding Format. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. */ static VETRESULT save(vetFrameT &source, const char *filename, FileFormat format); /** * @brief Save given image to a BMP file. * * @param[in] source VETLib Cache Frame to store data. * @param[in] filename Output BMP filename. * @param[in] format BMP Encoding Format. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. */ static VETRESULT save(vetFrameRGB96 &source, const char *filename,FileFormat format); /** * @brief Load a BMP format image into given image. * * @param[out] source VETLib Cache Frame to store data. * @param[in] filename Input BMP filename. * @param[in] format BMP Encoding Format. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. */ static VETRESULT load(vetFrameRGB24 &source, const char *filename,FileFormat format); /** * @brief Load a BMP format image into given image. * * @param[out] source VETLib Cache24 Frame to store data. * @param[in] filename Input BMP filename. * @param[in] format BMP Encoding Format. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. */ static VETRESULT load(vetFrameYUV420 &source, const char *filename,FileFormat format); /** * @brief Load a BMP format image into given image. * * @param[out] source Color VETLib Frame to store data. * @param[in] filename Input BMP filename. * @param[in] format BMP Encoding Format. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. */ static VETRESULT load(vetFrameT &source, const char *filename, FileFormat format); /** * @brief Load a BMP format image into given image. * * @param[out] source GreyScale VETLib Frame to store data. * @param[in] filename Input BMP filename. * @param[in] format BMP Encoding Format. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. */ static VETRESULT load(vetFrameRGB96 &source, const char *filename, FileFormat format); bool isEncodingAvailable() { return true; }; bool isDecodingAvailable() { return true; }; }; class vetCodec_BMPParameters : public vetCodecParameters { protected: int fileNameIndex; char fileNameBase[128]; bool fileNameProgression; bool autoOuput; bool autoInput; bool doBuffering; vetCodec_BMP::FileFormat fileFormat; friend class vetCodec_BMP; public: vetCodec_BMPParameters(); vetCodec_BMPParameters(const char* filename, vetCodec_BMP::FileFormat format = vetCodec_BMP::FORMAT_BMP_ANY); ~vetCodec_BMPParameters() { } void reset(); /** * @brief Set current index for filename progression, for example: * basefile name is "output", index is 13 so filename is output13.bmp, * if filename progression is enabled, when an operation is done * onto file, idex is incremented. * * @param[in] base current filename index as integer value. * * @return VETRET_OK if everything is fine, * VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * @see */ void setFileNameIndex(int base = -1) { fileNameIndex = base; }; /** * @brief Enable or disable filename progression, for example: * basefile name is "output", index is 13 so filename is output13.bmp, * if filename progression is enabled, when an operation is done * onto file, idex is incremented (output14.bmp). * * @param[in] value true to enable file name progression. */ void setFileNameProgression(bool value = true) { fileNameProgression = value; }; /** * @brief Enable or disable auto input feature, * * * @param[in] * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ void setAutoOutputEnabled(bool value = true) { autoOuput = value; }; /** * @brief * * * @param[in] * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ void setAutoInputEnabled(bool value = true) { autoInput = value; }; /** * @brief * * * @param[in] * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ void setDoBuffering(bool value = true) { doBuffering = value; }; /** * @brief * * * @param[in] * * @note * @see */ void setFileName(const char *filename); /** * @brief Set current BMP format. * * @param[in] format BMP format enumaration. * * @see FileFormat */ void setFileFormat(vetCodec_BMP::FileFormat format = vetCodec_BMP::FORMAT_BMP_24) { fileFormat = format; }; /** * @brief Read current file name index, used in file name progression * routines. * * @return VETRET_OK if everything is fine, * VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ int getFileNameIndex() { return fileNameIndex;}; /** * @brief * * * @return true if filename progression is enabled. * * @see fileNameProgression */ bool isFileNameProgressionEnabled() { return fileNameProgression; }; /** * @brief * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ bool isAutoInputEnabled() { return autoInput;}; /** * @brief * * * @param[in] * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ bool isAutoOutputEnabled() { return autoOuput;}; /** * @brief * * * @param[in] * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ bool isBufferingEnabled() { return doBuffering;}; /** * @brief Read base filename, if progression is enabled it's the base fixed * name. * * @param[in] * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note * @see */ void getFileName(char *filename); /** * @brief Read current filename, if progression is enabled it's the base fixed * name + current index + bmp extension. * * @param[out] Char Array to store current filename [Max size 64 chars] * * @see fileNameBase */ void getFileNameCurrent(char *filename); /** * @brief Read current bitmap encoding/decoding format. * * @return Current I/O BMP format. * * @see FileFormat * @see fileFormat */ vetCodec_BMP::FileFormat getFileFormat() { return fileFormat; }; int saveToStreamXML(FILE *fp); int loadFromStreamXML(FILE *fp); }; #endif //__VETLIB_VETCODER_BMP_H__