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

📄 rgb2rgb.c

📁 symbian 下的helix player源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* ***** BEGIN LICENSE BLOCK *****
 * Source last modified: $Id: rgb2rgb.c,v 1.5.8.1 2004/07/09 02:00:18 hubbe Exp $
 * 
 * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
 * 
 * The contents of this file, and the files included with this file,
 * are subject to the current version of the RealNetworks Public
 * Source License (the "RPSL") available at
 * http://www.helixcommunity.org/content/rpsl unless you have licensed
 * the file under the current version of the RealNetworks Community
 * Source License (the "RCSL") available at
 * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
 * will apply. You may also obtain the license terms directly from
 * RealNetworks.  You may not use this file except in compliance with
 * the RPSL or, if you have a valid RCSL with RealNetworks applicable
 * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
 * the rights, obligations and limitations governing use of the
 * contents of the file.
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU General Public License Version 2 or later (the
 * "GPL") in which case the provisions of the GPL are applicable
 * instead of those above. If you wish to allow use of your version of
 * this file only under the terms of the GPL, and not to allow others
 * to use your version of this file under the terms of either the RPSL
 * or RCSL, indicate your decision by deleting the provisions above
 * and replace them with the notice and other provisions required by
 * the GPL. If you do not delete the provisions above, a recipient may
 * use your version of this file under the terms of any one of the
 * RPSL, the RCSL or the GPL.
 * 
 * This file is part of the Helix DNA Technology. RealNetworks is the
 * developer of the Original Code and owns the copyrights in the
 * portions it created.
 * 
 * This file, and the files included with this file, is distributed
 * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
 * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
 * ENJOYMENT OR NON-INFRINGEMENT.
 * 
 * Technology Compatibility Kit Test Suite(s) Location:
 *    http://www.helixcommunity.org/content/tck
 * 
 * Contributor(s):
 * 
 * ***** END LICENSE BLOCK ***** */

#ifdef _MACINTOSH
#pragma require_prototypes off
#endif

/*** #includes: ********************************************/

#include "env.h"
#include "rgb.h"    /* basic RGB-data definitions & macros */
#include "scale.h"  /* scale algorithms */
#include "colorlib.h" /* ensure that prototypes get extern C'ed */
/*** Additional pixel-level macros: ************************/

/*
 * Generic pixel load-convert-store macro:
 */
#define LOAD_CONVERT_STORE(df,d,sf,s)       \
    {                                       \
        PIXEL(df,da);                       \
        LOAD_CONVERT(df,da,sf,s);           \
        s+=BPP(sf);                         \
        STORE(df,d,da);                     \
        d+=BPP(df);                         \
    }

/*
 * Generic 4-pixels load-convert-store macro
 * (XXX: this is just a lazy implementation of
 *  4-times unrolled load-convert-store;
 *  later, we should rewrite it for better
 *  efficiency !!!)
 */
#define LOAD_CONVERT_STORE_4(df,d,sf,s)     \
    {                                       \
        PIXEL(df,da);                       \
        LOAD_CONVERT(df,da,sf,s);           \
        STORE(df,d,da);                     \
        LOAD_CONVERT(df,da,sf,s+BPP(sf));   \
        STORE(df,d+BPP(df),da);             \
        LOAD_CONVERT(df,da,sf,s+2*BPP(sf)); \
        STORE(df,d+2*BPP(df),da);           \
        LOAD_CONVERT(df,da,sf,s+3*BPP(sf)); \
        STORE(df,d+3*BPP(df),da);           \
        s+=4*BPP(sf);                       \
        d+=4*BPP(df);                       \
    }

/*
 * Generic pixel load-convert-average-store macro:
 * ([d2] = convert([s]); [d12] = ([d1]+[d2])/2)
 */
#define LOAD_CONVERT_AVERAGE_STORE(df,d1,d12,d2,sf,s) \
    {                                       \
        PIXEL(df,da);                       \
        LOAD_CONVERT(df,da,sf,s);           \
        s+=BPP(sf);                         \
        STORE(df,d2,da);                    \
        d2+=BPP(df);                        \
        LOAD_AVERAGE(df,da,da,d1);          \
        d1+=BPP(df);                        \
        STORE(df,d12,da);                   \
        d12+=BPP(df);                       \
    }

/*
 * Generic 4-pixels load-convert-average-store macro:
 * (again, very lazy implementation; ultimately it should
 *  be rewritten for all possible combinations of pixel formats !!)
 */
#define LOAD_CONVERT_AVERAGE_STORE_4(df,d1,d12,d2,sf,s) \
    {                                       \
        PIXEL(df,da);                       \
        /* first column: */                 \
        LOAD_CONVERT(df,da,sf,s);           \
        STORE(df,d2,da);                    \
        LOAD_AVERAGE(df,da,da,d1);          \
        STORE(df,d12,da);                   \
        /* second column: */                \
        LOAD_CONVERT(df,da,sf,s+BPP(sf));   \
        STORE(df,d2+BPP(df),da);            \
        LOAD_AVERAGE(df,da,da,d1+BPP(df));  \
        STORE(df,d12+BPP(df),da);           \
        /* third column: */                 \
        LOAD_CONVERT(df,da,sf,s+2*BPP(sf)); \
        STORE(df,d2+2*BPP(df),da);          \
        LOAD_AVERAGE(df,da,da,d1+2*BPP(df));\
        STORE(df,d12+2*BPP(df),da);         \
        /* fourth column: */                \
        LOAD_CONVERT(df,da,sf,s+3*BPP(sf)); \
        STORE(df,d2+3*BPP(df),da);          \
        LOAD_AVERAGE(df,da,da,d1+3*BPP(df));\
        STORE(df,d12+3*BPP(df),da);         \
        /* update pointers: */              \
        s +=4*BPP(sf);                      \
        d1+=4*BPP(df);                      \
        d2+=4*BPP(df);                      \
        d12+=4*BPP(df);                     \
    }


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

/*
 * Generic row shrinking converter:
 */
#define ROW_SHRINK(df,dest_ptr,dest_dx,sf,src_ptr,src_dx)   \
    {                                                       \
        /* initialize local variables: */                   \
        register unsigned char *d = dest_ptr;               \
        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 {                                            \
                /* convert and copy a nearest pixel: */     \
                PIXEL(df,da);                               \
                LOAD_CONVERT(df,da,sf,s);                   \
                STORE(df,d,da);                             \
                d+=BPP(df);                                 \
                /* inverted Bresenham stepping: */          \
                do {                                        \
                    /* skip source pixel: */                \
                    s+=BPP(sf);                             \
                } while ((limit -= step) >= 0);             \
                limit += src_dx;                            \
            } while (--count);                              \
        }                                                   \
    }

/*
 * Generic row copy converter:
 */
#define ROW_COPY(df,dest_ptr,dest_dx,sf,src_ptr,src_dx)     \
    {                                                       \
        /* do we have the same format? */                   \
        if (ID(df) == ID(sf)) {                             \
            /* just use memcopy: */                         \
            memcpy(dest_ptr, src_ptr, dest_dx*BPP(df)); /* Flawfinder: ignore */    \
        } else {                                            \
            /* initialize local variables: */               \
            register unsigned char *d = dest_ptr;           \
            register unsigned char *s = src_ptr;            \
            register int count = dest_dx;                   \
            /* convert misaligned pixels first: */          \
            while (((unsigned int)d & 3)                    \
                && ((unsigned int)s & 3) && count) {        \
                LOAD_CONVERT_STORE(df,d,sf,s);              \
                count --;                                   \
            }                                               \
            /* the main loop (convert 4 pixels a time): */  \
            while (count >= 4) {                            \
                LOAD_CONVERT_STORE_4(df,d,sf,s);            \
                count -= 4;                                 \
            }                                               \
            /* convert the remaining pixels: */             \
            while (count) {                                 \
                LOAD_CONVERT_STORE(df,d,sf,s);              \
                count --;                                   \
            }                                               \
        }                                                   \
    }

/*
 * Generic row stretching converter:
 *  (shall not be used when dest_dx/2 >= src_dx!!!)
 */
#define ROW_STRETCH(df,dest_ptr,dest_dx,sf,src_ptr,src_dx)  \
    {                                                       \
        /* initialize local variables: */                   \
        register unsigned char *d = dest_ptr;               \
        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);                               \
                /* Bresenham stepping: */                   \
                if ((limit -= step) < 0) {                  \
                    limit += dest_dx;                       \
                    /* load & convert pixel: */             \
    start:          LOAD_CONVERT(df,da,sf,s);               \
                    s+=BPP(sf);                             \
                }                                           \
                /* replicate pixel: */                      \
                STORE(df,d,da);                             \
                d+=BPP(df);                                 \
            } while (--count);                              \
        }                                                   \
    }

/*
 * Generic row 2x-stretching converter:
 */
#define ROW_STRETCH2X(df,dest_ptr,dest_dx,sf,src_ptr,src_dx) \
    {                                                       \
        /* initialize local variables: */                   \
        register unsigned char *d = dest_ptr;               \
        register unsigned char *s = src_ptr;                \
        register int count = src_dx;                        \
        /* check row length: */                             \
        if (count) {                                        \
            /* process first integral pixel: */             \
            PIXEL(df,da);                                   \
            LOAD_CONVERT(df,da,sf,s);                       \
            s+=BPP(sf);                                     \
            count --;                                       \
            STORE(df,d,da);                                 \
            d+=BPP(df);                                     \
            /* main loop (process 2 pixels a time): */      \
            while (count >= 2) {                            \
                /* load & convert second integral pixel: */ \
                PIXEL(df,db);                               \
                LOAD_CONVERT(df,db,sf,s);                   \
                /* calculate first half-pixel: */           \
                AVERAGE(df,da,da,db);                       \
                /* store both pixels: */                    \
                STORE(df,d,da);                             \
                STORE(df,d+BPP(df),db);                     \
                /* load & convert third integral pixel: */  \
                LOAD_CONVERT(df,da,sf,s+BPP(sf));           \
                /* calculate second half-pixel: */          \
                AVERAGE(df,db,db,da);                       \
                /* store both pixels: */                    \
                STORE(df,d+2*BPP(df),db);                   \
                STORE(df,d+3*BPP(df),da);                   \
                /* shift pointers: */                       \
                s+=2*BPP(sf);                               \
                d+=4*BPP(df);                               \
                count -= 2;                                 \
            }                                               \
            /* is there any more pixels to convert? */      \
            if (count) {                                    \
                /* load & convert last integral pixel: */   \
                PIXEL(df,db);                               \
                LOAD_CONVERT(df,db,sf,s);                   \
                /* calculate last half-pixel: */            \
                AVERAGE(df,da,da,db);                       \
                /* store pixels: */                         \
                STORE(df,d,da);                             \
                STORE(df,d+BPP(df),db);                     \
                STORE(df,d+2*BPP(df),db);                   \
            } else {                                        \
                /* replicate last pixel: */                 \
                STORE(df,d,da);                             \
            }                                               \
        }                                                   \
    }

/*
 * Generic row 2x+ stretching converter:
 */
#define ROW_STRETCH2XPLUS(df,dest_ptr,dest_dx,sf,src_ptr,src_dx) \
    {                                                       \
        /* initialize local variables: */                   \
        register unsigned char *d = dest_ptr;               \
        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);                     \
            LOAD_CONVERT(df,da,sf,s);                       \
            s+=BPP(sf);                                     \
            /* update counter: */                           \
            if (!(count -= remainder))                      \
                goto end_of_row;                            \
            /* main loop: */                                \
            while (1) {                                     \
                /* replicate first integral pixel: */       \
                do {                                        \
                    STORE(df,d,da);                         \
                    d+=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);                   \
                /* calc & replicate first half-pixel: */    \
                AVERAGE(df,da,da,db);                       \
                do {                                        \
                    STORE(df,d,da);                         \
                    d+=BPP(df);                             \
                    if (!(--count))                         \
                        goto end_of_row;                    \
                } while ((limit -= step) >= 0);             \
                limit += dest_dx;                           \
                /* replicate second integral pixel: */      \
                do {                                        \
                    STORE(df,d,db);                         \
                    d+=BPP(df);                             \
                    if (!(--count))                         \
                        goto end_of_row_2;                  \
                } while ((limit -= step) >= 0);             \
                limit += dest_dx;                           \
                /* load & convert third pixel: */           \

⌨️ 快捷键说明

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