⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iul_color_convert.h

📁 image codec gemini0816
💻 H
字号:
/*****************************************************************************
 *
 * Filename:
 * ---------
 *   iul_color_convert.h
 *
 * Project:
 * --------
 *   N/A
 *
 * Description:
 * ------------
 *   Image Utility Lirary: APIs for color space conversion
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by ClearCase. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * $Log$
 *
 * removed!
 * removed!
 * Sync. to main trunk.
 *
 * removed!
 * removed!
 * Add YUV422 interleaved -> RGB565 general resizer API.
 *
 * removed!
 * removed!
 * Initial version.
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by ClearCase. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/

#ifndef __IUL_COLOR_CONVERT_H__
#define __IUL_COLOR_CONVERT_H__

typedef int IUL_FIXED;                             ///< Type definition as S15.16 fixed-point

#define IUL_I_TO_X(i)   (i << 16)                  ///< Convert from integer to S15.16 fixed-point
#define IUL_X_TO_I(x)   ((x + (1 << 15)) >> 16)    ///< Convert from S15.16 fixed-point to integer (with rounding)


#define RGB565_R_MASK   0xF800                     ///< mask for R component in RGB565 packed data
#define RGB565_G_MASK   0x07E0                     ///< mask for G component in RGB565 packed data
#define RGB565_B_MASK   0x001F                     ///< mask for B component in RGB565 packed data


/// Convert RGB888 data into RGB565 packed data
#define RGB888_TO_RGB565(R, G, B)   ((unsigned short)(((B) & 0xF8)  >> 3) | (((G) & 0xFC) << 3) | (((R) & 0xF8) << 8))

/// Extract the R component from RGB565 data and extend it to 8 bits
#define RGB565_TO_RGB888_R(VALUE)	((((VALUE) & RGB565_R_MASK) >> 8))

/// Extract the G component from RGB565 data and extend it to 8 bits
#define RGB565_TO_RGB888_G(VALUE)	((((VALUE) & RGB565_G_MASK) >> 3))

/// Extract the B component from RGB565 data and extend it to 8 bits
#define RGB565_TO_RGB888_B(VALUE)   ((((VALUE) & RGB565_B_MASK) << 3))

/// Get the Y value according to the given R, G, B values
#define RGB888_TO_YUV_Y(R, G, B)    ((  306 * (R) + 601 * (G) + 117 * (B)) >> 10)

/// Get the U value according to the given R, G, B values
#define RGB888_TO_YUV_U(R, G, B)    (((-173 * (R) - 339 * (G) + 512 * (B)) >> 10) + 128)

/// Get the V value according to the given R, G, B values
#define RGB888_TO_YUV_V(R, G, B)    ((( 512 * (R) - 429 * (G) -  83 * (B)) >> 10) + 128)


#define YUV_TO_RGB_COEF_0       (256)     /// 1 << 8
#define YUV_TO_RGB_COEF_1       (359)     ///  1.402 * (1 << 8)
#define YUV_TO_RGB_COEF_2       (-88)     /// -0.34414 * (1 << 8)
#define YUV_TO_RGB_COEF_3       (-183)    /// -0.71414 * (1 << 8)
#define YUV_TO_RGB_COEF_4       (454)     ///  1.772 * (1 << 8)


/// Fast saturate-zero macro: ARM compiler will use bic (bit clear) instruction.
#define SATURATE_ZERO(value)     (~((signed int)(value) >> 31) & (value))


/// Macro for range limitation. Notice that lower must be 0.
#define RANGE_LIMIT(lower, upper, x)   \
{                                      \
   if (x > upper)                      \
   {                                   \
      x = upper;                       \
   }                                   \
   else                                \
   {                                   \
      x = SATURATE_ZERO(x);            \
   }                                   \
}





/**
 * Convert RGB565 raw data into graylevel (Y only) raw data.
 *
 * @param srcRGB  pointer to the buffer containing RGB565 raw data
 * @param dstY    pointer to the buffer to contain the output graylevel data
 * @param dstU    dummy, NULL is accepted
 * @param dstV    dummy, NULL is accepted
 * @param width   the width of the source image
 * @param height  the height of the source image
 *
 * @return        If the function succeeds, returns 1; otherwise returns 0.
 *
 * @remarks
 */
int iul_rgb565_to_y_only(unsigned short *srcRGB, 
                         unsigned char *dstY, unsigned char *dstU, unsigned char *dstV, 
                         int width, int height);


/**
 * Convert RGB565 raw data into YUV420 non-interleaved raw data.
 *
 * @param srcRGB  pointer to the buffer containing RGB565 raw data
 * @param dstY    pointer to the buffer to contain the output Y data
 * @param dstU    pointer to the buffer to contain the output U data
 * @param dstV    pointer to the buffer to contain the output V data
 * @param width   the width of the source image
 * @param height  the height of the source image
 *
 * @return        If the function succeeds, returns 1; otherwise returns 0.
 *
 * @remarks       The size of the 3 output buffers must be large enough to avoid memory corruption.
 */
int iul_rgb565_to_yuv420_non_interleave(unsigned short *srcRGB, 
                                        unsigned char *dstY, unsigned char *dstU, unsigned char *dstV, 
                                        int width, int height);


/**
 * Convert RGB888 raw data into YUV422 non-interleaved raw data.
 *
 * @param srcRGB  pointer to the buffer containing RGB565 raw data
 * @param dstY    pointer to the buffer to contain the output Y data
 * @param dstU    pointer to the buffer to contain the output U data
 * @param dstV    pointer to the buffer to contain the output V data
 * @param width   the width of the source image
 * @param height  the height of the source image
 *
 * @return        If the function succeeds, returns 1; otherwise returns 0.
 *
 * @remarks       The size of the 3 output buffers must be large enough to avoid memory corruption.
 */
int iul_rgb888_to_yuv422_non_interleave(unsigned char *srcRGB, 
                                        unsigned char *dstY, unsigned char *dstU, unsigned char *dstV, 
                                        int width, int height);


/**
 * Convert RGB888 raw data into YUV422 interleaved raw data.
 *
 * @param srcRGB  pointer to the buffer containing RGB565 raw data
 * @param dstYUV  pointer to the buffer to contain the output YUV422 interleaved data
 * @param width   the width of the source image
 * @param height  the height of the source image
 *
 * @return        If the function succeeds, returns 1; otherwise returns 0.
 *
 * @remarks       The size of the output buffer must be large enough to avoid memory corruption.
 */
int iul_rgb888_to_yuv422_interleave(unsigned char *srcRGB, unsigned char *dstYUV, int width, int height);


/**
 * Convert RGB888 raw data into YUV420 non-interleaved raw data.
 *
 * @param srcRGB  pointer to the buffer containing RGB565 raw data
 * @param dstY    pointer to the buffer to contain the output Y data
 * @param dstU    pointer to the buffer to contain the output U data
 * @param dstV    pointer to the buffer to contain the output V data
 * @param width   the width of the source image
 * @param height  the height of the source image
 *
 * @return        If the function succeeds, returns 1; otherwise returns 0.
 *
 * @remarks       The size of the 3 output buffers must be large enough to avoid memory corruption.
 */
int iul_rgb888_to_yuv420_non_interleave(
                              unsigned char *srcRGB, 
                              unsigned char *dstY, unsigned char *dstU, unsigned char *dstV, 
                              int width, int height);


/**
 * @brief            Resize RGB565 frame to any size.
 * @param srcRGB     pointer to the buffer containing RGB565 raw data
 * @param srcWidth   width of the source image
 * @param srcHEight  height of the source image
 * @param dstRGB     pointer to the buffer to contain the ourput RGB565 raw data
 * @param dstWidth   width of the destination image
 * @param dstHEight  height of the destination image
 * @return           If the function succeeds, returns 1; otherwise returns 0.
 * @remarks          No interpolation is applied due to the performance concern.
 */
int iul_rgb565_general_resize(unsigned short *srcRGB, int srcWidth, int srcHeight,
                              unsigned short *dstRGB, int dstWidth, int dstHeight);

int iul_yuv422_interleave_to_yuv422_non_interleave(
                              unsigned int *srcYUV, 
                              unsigned char *dstY, unsigned char *dstU, unsigned char *dstV, 
                              int width, int height);

int iul_yuv422_interleave_to_yuv420_non_interleave(
                              unsigned int *srcYUV, 
                              unsigned char *dstY, unsigned char *dstU, unsigned char *dstV, 
                              int width, int height);

int iul_yuv422_interleave_to_rgb565_quarter_size(
                              unsigned int *srcYUV, 
                              unsigned short *dstRGB,
                              int width, int height);

int iul_yuv422_interleave_to_rgb565_general_resize(
                              unsigned int *srcYUV, int srcWidth, int srcHeight,
                              unsigned short *dstRGB, int dstWidth, int dstHeight);

int iul_yuv422_interleave_to_rgb565(
                              unsigned int *srcYUV, 
                              unsigned short *dstRGB,
                              int width, int height);
                              
int iul_yuv420_non_interleave_to_rgb565_general_resize(
                              unsigned char *srcY, unsigned char *srcU, unsigned char *srcV,
                              int srcWidth, int srcHeight,
                              unsigned short *dstRGB,
                              int dstWidth, int dstHeight);

int iul_yuv420_non_interleave_to_rgb565_quarter_size(
                              unsigned char *srcY, unsigned char *srcU, unsigned char *srcV,
                              unsigned short *dstRGB, 
                              int width, int height);

#endif /// __IUL_COLOR_CONVERT_H__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -