/** * @class vetCodec_IMG * * @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 vetFrameRGB * * @example test_vetCodec_IMG.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_IMG_H__ #define __VETLIB_VETCODEC_IMG_H__ #include "../vetDefs.h" #include "../vetCodec.h" #include "../vetFrameYUV420.h" #include "../vetFrameRGB24.h" #include "../vetFrameT.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_IMGParameters : public vetCodecParameters { protected: int fileNameIndex; char fileNameBase[128]; bool fileNameProgression; bool autoOuput; bool autoInput; bool doBuffering; friend class vetCodec_IMG; public: vetCodec_IMGParameters(); vetCodec_IMGParameters(char* filename); ~vetCodec_IMGParameters() { } 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 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); VETRESULT saveToStreamXML(FILE *fp); VETRESULT loadFromStreamXML(FILE *fp); }; class vetCodec_IMG : public vetCodec { public: protected: vetCodec_IMGParameters* myParams; unsigned int width ; unsigned int height ; void *img ; bool ok ; char fileNameIndexBuffer[16]; char fileNameBuffer[80]; void doFileNameCurrent(); static void* im_load(char *filename, unsigned int &w, unsigned int &h, char* prog_path) ; static void im_get_data(void *image, int *rgb) ; static void im_get_data(void *img, unsigned char *rgb); static void im_get_data_grey(void *image, int *d) ; static void im_free(void *img) ; public: /** * @brief Default constructor, initializa parameters and superclasses. */ vetCodec_IMG(vetCodec_IMGParameters* initParams = NULL); /** * @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_IMG(char* filename); /** * @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. */ VETRESULT 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. */ VETRESULT save(char *filename); /** * @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. */ VETRESULT 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. */ VETRESULT load(char *filename); /** * @brief Set parameters for (de)coding. * * @param[in] initParams Instance of vetCodec_IMGParameters or NULL, * NULL argument make function to create a new * instance with default parameters. * * @return VETRET_OK */ VETRESULT setParameters(vetCodec_IMGParameters* initParams); /** * @brief Get parameters for (de)coding. * * @return pointer to vetCodec_MOVParameters class. */ vetCodec_IMGParameters& getParameters() { return *myParams; }; VETRESULT setFilterParameters (vetFilterParameters* initParams) { return setParameters(static_cast(initParams)); }; vetFilterParameters* getFilterParameters () { return static_cast(myParams); }; /** * @brief Get the state of current data source. * * @return true is there are no more frames to load, false else. */ bool EoF(); /** * @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 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 Reset filename related setup. * * @return VETRET_OK if everything is fine, VETRET_INTERNAL_ERR * or VETRET_ILLEGAL_USE else. */ VETRESULT 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. */ VETRESULT setHeight(unsigned int value) { return VETRET_NOT_IMPLEMENTED; }; /** * @brief Set current canvas' width. * * @return width in pixel. */ VETRESULT setWidth(unsigned int value) { return VETRET_NOT_IMPLEMENTED; }; long getVideoStreamLength(int stream = -1) { return -1; }; long getAudioStreamLength(int stream = -1) { return -1; }; int getAudioStreamCount() { return -1; }; int getVideoStreamCount() { return -1; }; bool hasAudio() { return false; }; bool hasVideo() { return false; }; /** * @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); /** * @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(vetFrameYUV420 &source, const char *filename); /** * @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(vetFrameRGB24 &source, const char *filename); /** * @brief Save given image to a BMP file. * * @param[in] source Greyscale 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); /** * @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(vetFrameYUV420 &source, const char *filename); /** * @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(vetFrameRGB24& source, const char *filename); /** * @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(vetFrameT& source, const char *filename); bool isEncodingAvailable() { return false; }; //{ return true; }; bool isDecodingAvailable() { return true; }; }; #endif //__VETLIB_VETCODEC_IMG_H__