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

📄 rgb2rgb.c

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
            }                                               \
        }                                                   \
    }

/*** Generic RGB 1.5-row converters: ***********************/

/*
 * Generic 1.5-row shrinking converter:
 *  dest_ptr_1  - a previously converted row in destination image
 *  dest_ptr_12 - an area to store half-pixel average row
 *  dest_ptr_2  - an area to store next converted row from source image
 */
#define ROW2X_SHRINK(df,dest_ptr_1,dest_ptr_12,dest_ptr_2,dest_dx,sf,src_ptr,src_dx)   \
    {                                                       \
        /* initialize local variables: */                   \
        register unsigned char *d1 = dest_ptr_1;            \
        register unsigned char *d12 = dest_ptr_12;          \
        register unsigned char *d2 = dest_ptr_2;            \
        register unsigned char *s = src_ptr;                \
        register int count = dest_dx;                       \
        register int limit = src_dx >> 1; /* -1 */          \
        register int step = dest_dx;                        \
        /* check row length: */                             \
        if (count) {                                        \
            do {                                            \
                /* load & convert pixel from second row: */ \
                PIXEL(df,da);                               \
                LOAD_CONVERT(df,da,sf,s);                   \
                STORE(df,d2,da);                            \
                d2+=BPP(df);                                \
                /* average it with pixel from first row: */ \
                LOAD_AVERAGE(df,da,da,d1);                  \
                d1+=BPP(df);                                \
                STORE(df,d12,da);                           \
                d12+=BPP(df);                               \
                /* inverted Bresenham stepping: */          \
                do {                                        \
                    /* skip source pixel: */                \
                    s+=BPP(sf);                             \
                } while ((limit -= step) >= 0);             \
                limit += src_dx;                            \
            } while (--count);                              \
        }                                                   \
    }

/*
 * Generic 1.5-row copy converter:
 */
#define ROW2X_COPY(df,dest_ptr_1,dest_ptr_12,dest_ptr_2,dest_dx,sf,src_ptr,src_dx)     \
    {                                                       \
        /* initialize local variables: */                   \
        register unsigned char *d1 = dest_ptr_1;            \
        register unsigned char *d12 = dest_ptr_12;          \
        register unsigned char *d2 = dest_ptr_2;            \
        register unsigned char *s = src_ptr;                \
        register int count = dest_dx;                       \
        /* convert misaligned pixels first: */              \
        while (((unsigned int)d2 & 3)                       \
            && ((unsigned int)s & 3) && count) {            \
            LOAD_CONVERT_AVERAGE_STORE(df,d1,d12,d2,sf,s);  \
            count --;                                       \
        }                                                   \
        /* the main loop (convert 4 pixels a time): */      \
        while (count >= 4) {                                \
            LOAD_CONVERT_AVERAGE_STORE_4(df,d1,d12,d2,sf,s);\
            count -= 4;                                     \
        }                                                   \
        /* convert the remaining pixels: */                 \
        while (count) {                                     \
            LOAD_CONVERT_AVERAGE_STORE(df,d1,d12,d2,sf,s);  \
            count --;                                       \
        }                                                   \
    }

/*
 * Generic 1.5-row stretching converter:
 *  (shall not be used when dest_dx/2 >= src_dx!!!)
 */
#define ROW2X_STRETCH(df,dest_ptr_1,dest_ptr_12,dest_ptr_2,dest_dx,sf,src_ptr,src_dx)  \
    {                                                       \
        /* initialize local variables: */                   \
        register unsigned char *d1 = dest_ptr_1;            \
        register unsigned char *d12 = dest_ptr_12;          \
        register unsigned char *d2 = dest_ptr_2;            \
        register unsigned char *s = src_ptr;                \
        register int count = dest_dx;                       \
        register int limit = dest_dx >> 1; /* !!! */        \
        register int step = src_dx;                         \
        /* check row length: */                             \
        if (count) {                                        \
            goto start;                                     \
            /* the main loop: */                            \
            do {                                            \
                PIXEL(df,da); PIXEL(df,dc);                 \
                /* Bresenham stepping: */                   \
                if ((limit -= step) < 0) {                  \
                    limit += dest_dx;                       \
                    /* load & convert pixel: */             \
    start:          LOAD_CONVERT(df,da,sf,s);               \
                    s+=BPP(sf);                             \
                    /* calculate a half-pixel above: */     \
                    LOAD_AVERAGE(df,dc,da,d1);              \
                }                                           \
                /* replicate pixels: */                     \
                d1+=BPP(df);                                \
                STORE(df,d2,da);                            \
                d2+=BPP(df);                                \
                STORE(df,d12,dc);                           \
                d12+=BPP(df);                               \
            } while (--count);                              \
        }                                                   \
    }

/*
 * Generic 1.5-row 2x-stretching converter:
 */
#define ROW2X_STRETCH2X(df,dest_ptr_1,dest_ptr_12,dest_ptr_2,dest_dx,sf,src_ptr,src_dx) \
    {                                                       \
        /* initialize local variables: */                   \
        register unsigned char *d1 = dest_ptr_1;            \
        register unsigned char *d12 = dest_ptr_12;          \
        register unsigned char *d2 = dest_ptr_2;            \
        register unsigned char *s = src_ptr;                \
        register int count = src_dx;                        \
        /* check row length: */                             \
        if (count) {                                        \
            /* load and convert first pixel: */             \
            PIXEL(df,da); PIXEL(df,dc);                     \
            LOAD_CONVERT(df,da,sf,s);                       \
            s+=BPP(sf);                                     \
            /* calculate a half-pixel above it: */          \
            LOAD_AVERAGE(df,dc,da,d1);                      \
            d1+=2*BPP(df);                                  \
            count --;                                       \
            /* store both: */                               \
            STORE(df,d2,da);                                \
            d2+=BPP(df);                                    \
            STORE(df,d12,dc);                               \
            d12+=BPP(df);                                   \
            /* main loop (process 2 pixels a time): */      \
            while (count >= 2) {                            \
                /* load & convert second integral pixel: */ \
                PIXEL(df,db); PIXEL(df,dd);                 \
                LOAD_CONVERT(df,db,sf,s);                   \
                /* calculate a half-pixel on the left: */   \
                AVERAGE(df,da,da,db);                       \
                /* store both pixels: */                    \
                STORE(df,d2,da);                            \
                STORE(df,d2+BPP(df),db);                    \
                /* calculate a half-pixel above: */         \
                LOAD_AVERAGE(df,dd,db,d1);                  \
                /* calculate a half-pixel above and left: */\
                AVERAGE(df,dc,dc,dd);                       \
                /* store both: */                           \
                STORE(df,d12,dc);                           \
                STORE(df,d12+BPP(df),dd);                   \
                /* load & convert third integral pixel: */  \
                LOAD_CONVERT(df,da,sf,s+BPP(sf));           \
                /* calculate a half-pixel on the left: */   \
                AVERAGE(df,db,db,da);                       \
                /* store both pixels: */                    \
                STORE(df,d2+2*BPP(df),db);                  \
                STORE(df,d2+3*BPP(df),da);                  \
                /* calculate a half-pixel above: */         \
                LOAD_AVERAGE(df,dc,da,d1+2*BPP(df));        \
                /* calculate a half-pixel above and left: */\
                AVERAGE(df,dd,dd,dc);                       \
                /* store both: */                           \
                STORE(df,d12+2*BPP(df),dd);                 \
                STORE(df,d12+3*BPP(df),dc);                 \
                /* shift pointers: */                       \
                s+=2*BPP(sf);                               \
                d1+=4*BPP(df);                              \
                d2+=4*BPP(df);                              \
                d12+=4*BPP(df);                             \
                count -= 2;                                 \
            }                                               \
            /* is there any more pixels to convert? */      \
            if (count) {                                    \
                /* load & convert last integral pixel: */   \
                PIXEL(df,db); PIXEL(df,dd);                 \
                LOAD_CONVERT(df,db,sf,s);                   \
                /* calculate a half-pixel on the left: */   \
                AVERAGE(df,da,da,db);                       \
                /* store pixels: */                         \
                STORE(df,d2,da);                            \
                STORE(df,d2+BPP(df),db);                    \
                STORE(df,d2+2*BPP(df),db);                  \
                /* calculate a half-pixel above: */         \
                LOAD_AVERAGE(df,dd,db,d1);                  \
                /* calculate a half-pixel above and left: */\
                AVERAGE(df,dc,dc,dd);                       \
                /* store pixels: */                         \
                STORE(df,d12,dc);                           \
                STORE(df,d12+BPP(df),dd);                   \
                STORE(df,d12+2*BPP(df),dd);                 \
            } else {                                        \
                /* replicate last pixels: */                \
                STORE(df,d2,da);                            \
                STORE(df,d12,dc);                           \
            }                                               \
        }                                                   \
    }

/*
 * Generic 1.5-row 2x+ stretching converter:
 */
#define ROW2X_STRETCH2XPLUS(df,dest_ptr_1,dest_ptr_12,dest_ptr_2,dest_dx,sf,src_ptr,src_dx) \
    {                                                       \
        /* initialize local variables: */                   \
        register unsigned char *d1 = dest_ptr_1;            \
        register unsigned char *d12 = dest_ptr_12;          \
        register unsigned char *d2 = dest_ptr_2;            \
        register unsigned char *s = src_ptr;                \
        register int count = dest_dx;                       \
        register int limit = dest_dx >> 1; /* !!! */        \
        register int step = src_dx << 1;  /* !!! */         \
        /* # of pixels mapped outside source image: */      \
        register int remainder = (2*dest_dx - limit) / step;\
        /* check row length: */                             \
        if (count) {                                        \
            /* load & convert first pixel: */               \
            PIXEL(df,da); PIXEL(df,db);                     \
            PIXEL(df,dc); PIXEL(df,dd);                     \
            LOAD_CONVERT(df,da,sf,s);                       \
            s+=BPP(sf);                                     \
            /* update counter: */                           \
            if (!(count -= remainder))                      \
                goto end_of_row;                            \
            /* main loop: */                                \
            while (1) {                                     \
                /* calculate a half-pixel above: */         \
                LOAD_AVERAGE(df,dc,da,d1);                  \
                /* replicate first pair of pixels: */       \
                do {                                        \
                    d1+=BPP(df);                            \
                    STORE(df,d2,da);                        \
                    d2+=BPP(df);                            \
                    STORE(df,d12,dc);                       \
                    d12+=BPP(df);                           \
                    if (!(--count))                         \
                        goto end_of_row;                    \
                } while ((limit -= step) >= 0);             \
                limit += dest_dx;                           \
                /* load & convert second pixel: */          \
                LOAD_CONVERT(df,db,sf,s);                   \
                /* calculate half-pixel on the left: */     \
                AVERAGE(df,da,da,db);                       \
                /* calculate half-pixel above and left: */  \
                LOAD_AVERAGE(df,dc,da,d1);                  \
                /* replicate first pair of half-pixels: */  \
                do {                                        \
                    d1+=BPP(df);                            \
                    STORE(df,d2,da);                        \
                    d2+=BPP(df);                            \
                    STORE(df,d12,dc);                       \
                    d12+=BPP(df);                           \
                    if (!(--count))                         \
                        goto end_of_row;                    \
                } while ((limit -= step) >= 0);             \
                limit += dest_dx;                           \
                /* calculate half-pixel above: */           \
                LOAD_AVERAGE(df,dd,db,d1);                  \
                /* replicate second pair of pixels: */      \
                do {                                        \
                    d1+=BPP(df);                            \
                    STORE(df,d2,db);                        \
                    d2+=BPP(df);                            \
                    STORE(df,d12,dd);                       \
                    d12+=BPP(df);                           \
                    if (!(--count))                         \
                        goto end_of_row_2;                  \
                } while ((limit -= step) >= 0);             \
                limit += dest_dx;                           \
                /* load & convert third pixel: */           \
                LOAD_CONVERT(df,da,sf,s+BPP(sf));           \
                s+=2*BPP(sf);                               \
                /* calculate half-pixel on the left: */     \
                AVERAGE(df,db,db,da);                       \
                /* calculate half-pixel above and left: */  \
                LOAD_AVERAGE(df,dd,db,d1);                  \
                /* replicate second pair of half-pixels: */ \
                do {                                        \
                    d1+=BPP(df);                            \
                    STORE(df,d2,db);                        \
                    d2+=BPP(df);                            \
                    STORE(df,d12,dd);                       \
                    d12+=BPP(df);                           \
                    if (!(--count))                         \
                        goto end_of_row_2;                  \
                } while ((limit -= step) >= 0);             \
                limit += dest_dx;                           \
            }                                               \
            /* replicate the remaining pixels: */           \
end_of_row_2:                                               \
            COPY(df,da,db);                                 \
            COPY(df,dc,dd);                                 \
end_of_row: while (remainder--) {                           \
                STORE(df,d2,da);                            \
                d2+=BPP(df);                                \
                STORE(df,d12,dc);                           \
                d12+=BPP(df);                               \
            }                                               \
        }                                                   \
    }

/***********************************************************/

/*
 * Function names:
 */
#define FN(df,sf)           sf##to##df
#define ROW_FN(df,sf,t)     sf##to##df##_ROW_##t
#define ROW2X_FN(df,sf,t)   sf##to##df##_ROW2X_##t

/*
 * Function replication macros:
 *  (row- and 1.5 row- converters)
 */
#define ROW_FUNC(df,sf,t)   \
    void ROW_FN(df,sf,t) (unsigned char *dest_ptr,          \
        int dest_dx, unsigned char *src_ptr, int src_dx)    \
        ROW_##t(df,dest_ptr,dest_dx,sf,src_ptr,src_dx)

#define ROW2X_FUNC(df,sf,t) \
    void ROW2X_FN(df,sf,t) (unsigned char *dest_ptr_1,      \
        unsigned char *dest_ptr_12, unsigned char *dest_ptr_2,\
        int dest_dx, unsigned char *src_ptr, int src_dx)    \
        ROW2X_##t(df,dest_ptr_1,dest_ptr_12,dest_ptr_2,dest_dx,sf,src_ptr,src_dx)


/***********************************************************/

/*
 * Actual row functions:
 */

ROW_FUNC(RGB32 ,RGB32 ,SHRINK)
ROW_FUNC(RGB32 ,RGB32 ,COPY)
ROW_FUNC(RGB32 ,RGB32 ,STRETCH)
ROW_FUNC(RGB32 ,RGB32 ,STRETCH2X)
ROW_FUNC(RGB32 ,RGB32 ,STRETCH2XPLUS)

ROW_FUNC(RGB32 ,BGR32 ,SHRINK)
ROW_FUNC(RGB32 ,BGR32 ,COPY)
ROW_FUNC(RGB32 ,BGR32 ,STRETCH)
ROW_FUNC(RGB32 ,BGR32 ,STRETCH2X)
ROW_FUNC(RGB32 ,BGR32 ,STRETCH2XPLUS)

ROW_FUNC(RGB32 ,RGB24 ,SHRINK)
ROW_FUNC(RGB32 ,RGB24 ,COPY)
ROW_FUNC(RGB32 ,RGB24 ,STRETCH)
ROW_FUNC(RGB32 ,RGB24 ,STRETCH2X)
ROW_FUNC(RGB32 ,RGB24 ,STRETCH2XPLUS)

ROW_FUNC(RGB32 ,RGB565,SHRINK)
ROW_FUNC(RGB32 ,RGB565,COPY)

⌨️ 快捷键说明

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