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

📄 icptest.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的外部设备的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
 * Copyright (c) 1995-2000 by TriMedia Technologies. 
 *
 * +------------------------------------------------------------------+
 * | This software is furnished under a license and may only be used  |
 * | and copied in accordance with the terms and conditions of  such  |
 * | a license and with the inclusion of this copyright notice. This  |
 * | software or any other copies of this software may not be provided|
 * | or otherwise made available to any other person.  The ownership  |
 * | and title of this software is not transferred.                   |
 * |                                                                  |
 * | The information in this software is subject  to change without   |
 * | any  prior notice and should not be construed as a commitment by |
 * | TriMedia Technologies.                                           |
 * |                                                                  |
 * | This code and information is provided "as is" without any        |
 * | warranty of any kind, either expressed or implied, including but |
 * | not limited to the implied warranties of merchantability and/or  |
 * | fitness for any particular purpose.                              |
 * +------------------------------------------------------------------+
 *
 *
 *  Module name              : icptest.c    1.53
 *
 *  Last update              : 17:22:52 - 00/11/09
 *
 *
 *  Description              :
 *
 *    This is an ICP example program.
 *
 *    To see usage type: icptest.out -h.
 *
 *    This program demostrates some of the ICP functionality. In particular,
 *    it does:
 *        1. YUV422 to several RGB conversions with arbitrary scale factor.
 *        2. YUV422 to several RGB conversions with an RGB24+alpha overlay.
 *        3. Bit mask an RGB image.
 *        4. Chroma keying.
 *
 *    Program flow is as follows:
 *        1. Load background image files: tv.y, tv.u, and tv.v
 *        2. Load the overlay files: clown.y, clown.u, clown.v
 *        3. Create a black image for bitmasking purposes
 *        4. Get user input
 *        5. Execute desired functionality
 *        6. goto 4
 *
 *    Throughout the program ICP is used in level triggered Interrupt mode.
 *    ICP uses default set of coeffcients provided in the library.
 *
 *
 */

/*-----------------------------includes-------------------------------------*/

#include <tm1/tmICP.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <tm1/mmio.h>
#include <tmlib/tmtypes.h>
#include <ops/custom_defs.h>
#include <tmlib/tmlibc.h>
#include <tm1/tmHelp.h>

/*------------------------------defines---------------------------------------*/

#define PIX_OFFSET 0             /* OutPixOffset = 0 for vertical and 
                                  * horizontal filters 
                                  */
#define FILENAME  "tv"
#define HEIGHT    288
#define WIDTH     350
#define STRIDE    384

#define O_FILENAME "clown120x100"
#define O_HEIGHT   100
#define O_WIDTH    120
#define O_STRIDE   O_WIDTH

/*-------------------------------types----------------------------------------*/

static volatile Int interrupt_done;

/*----------------------------Function prototypes-----------------------------*/
extern void icpISR(void);

int 
readYUVFile(char *baseName,
            int hsize, int vsize,
            UInt8 ** bufY, UInt8 ** bufU, UInt8 ** bufV,
            int yuv422or420 );

extern Int 
imageView(UInt8 * srcAddr,
          Int width, Int height,
          Int bytesPerPixel, Int srcStride, UInt8 * destAddr,
          Int destStride, Int adjustSize );

void 
get_parameters(Int argc, Char * argv[], UInt32 * disp_addr,
               Int * stride, Int * bpp, Int * not555a);

extern Int  get_input(Int * filter_type);

extern int  CreateBlackImage(int hsize, int vsize,
                             UInt8 ** bufY, UInt8 ** bufU, UInt8 ** bufV );

Int CreateImage(UInt8 * bitMask, Int srcHeight, Int srcWidth, Int visible );

int icpGetChromaKey(UInt8 * destImage, Int ostride, Int owidth, 
                   Int oheight, Float a, Float b );


main(Int argc, Char * argv[])
{

    Int         i, j, k;    /* General purpose counters */
    Int         size;       /* Image size: height*stride */
    Int         instance;   /* instance number for the ICP */
    Float       a;          /* Used in chroma keying demo */
    Float       tmpalpha;
    UInt32      dispAddr;
    Int         dispStride;
    Int         bpp;
    Int         not555a;
    Int         filterType;
    Int8        fn[32];
    Int         destHeight;
    Int         destWidth;
    UInt8      *destImage;
    UInt8      *yBlack;
    UInt8      *uBlack;
    UInt8      *vBlack;
    UInt8      *ytemp;
    UInt8      *utemp;
    UInt8      *vtemp;
    UInt8      *bitimage;
    UInt8      *yBase;
    UInt8      *uBase;
    UInt8      *vBase;
    UInt8      *overlay_y;
    UInt8      *overlay_u;
    UInt8      *overlay_v;
    icpInstanceSetup_t icb;
    icpImageHorzVert_t hvImage;
    icpOverlaySetup_t overlay;
    icpBitMaskSetup_t bitmask;
    icpCapabilities_t *icpCapabilities;
    icpImageColorConversion_t ccImage;

    /************* Get the command line parameters ******************/

    not555a = 0;

    printf("Running on "); tmHelpReportSystem(stdout);

    get_parameters(argc, argv, &dispAddr, &dispStride, &bpp, &not555a);
    printf("  Display address  0x%x, Stride: %d, Bytes per pixel: %d\n",
           dispAddr, dispStride, bpp);

    /************************ Initializations **********************/

    printf("\n");
    if (icpGetCapabilities(&icpCapabilities))
        printf("Error in icpGetCapabilities ... \n");
    printf("ICP version: %d%d%d \n", icpCapabilities->version.majorVersion,
           icpCapabilities->version.minorVersion, 
           icpCapabilities->version.buildVersion);

    icb.reset = 1;
    icb.interruptPriority = intPRIO_5;    /* Priority 5 Interrupt */
    icb.isr = &icpISR;    /* User Interrupt service routine */

    printf("\n");

    if (i = icpOpen(&instance))
        printf("Open failed ... %d \n", i);
    printf("instance: %d \n\n", instance);

    if (i = icpInstanceSetup(instance, &icb))
        printf("instance setup failed: %x \n", i);

    /*
     * Load coefficients. Only in polling mode. Done automatically. Load
     * standard set of coefficients
     */
    interrupt_done = 0;
    if (i = icpLoadCoeff(instance, (Int16 *) NULL))
        printf("Error in loading coefficient ... \n");
    while (!interrupt_done);

    /* Load input file and assign memory to Y, U, and V image addresses. */
    strcpy(fn, FILENAME);
    if (readYUVFile(fn, STRIDE, HEIGHT,
            &yBase, &uBase, &vBase, vdfYUV422Planar)) {
        printf("Error in reading file: %s \n", fn);
        exit(0);
    }

    size = HEIGHT * STRIDE;
    destImage = (UInt8 *) _cache_malloc(4 * size + 1024, -1);
    ytemp = (UInt8 *) _cache_malloc(3 * size + 1024, -1);
    utemp = (UInt8 *) _cache_malloc(3 * size / 2 + 1024, -1);
    vtemp = (UInt8 *) _cache_malloc(3 * size / 2 + 1024, -1);
    bitimage = (UInt8 *) _cache_malloc(size + 1024, -1);

    /***************************  Overlays  ********************************/

    /* Load input file and assign memory to Y, U, and V image addresses. */
    strcpy(fn, O_FILENAME);
    if (readYUVFile(fn, O_STRIDE, O_HEIGHT,
             &overlay_y, &overlay_u, &overlay_v, vdfYUV422Planar)) {
        printf("Error in reading file: %s \n", fn);
        exit(0);
    }

    /* We can use destImage for overlay format storage. */

    /*************************** Bit masks  ********************************/

    if (CreateBlackImage(STRIDE, HEIGHT, &yBlack, &uBlack, &vBlack))
        printf("Error in CreateBlackImage \n");

    filterType = 1;
    while (filterType < 5) {

        while (get_input(&filterType) == -1);

        if (filterType == 1) {

            for (k = -100; k < 190; k++) {

                destHeight = HEIGHT + k;
                destWidth = WIDTH + k;

                /* Reset the image width */
                hvImage.inputStride = STRIDE / 2;
                hvImage.inputWidth = WIDTH / 2;
                hvImage.inputHeight = HEIGHT;
                hvImage.outputStride = STRIDE / 2;
                hvImage.outputWidth = WIDTH / 2;
                hvImage.outputHeight = destHeight;
                hvImage.filterBypass = icpFILTER;
                hvImage.outputPixelOffset = PIX_OFFSET;
                hvImage.outputImage = utemp;
                hvImage.imageBase = uBase;

                interrupt_done = 0;
                if (i = icpVertFilter(instance, &hvImage)) {
                    printf("Error in icpVertFilter: %x \n", i);
                    exit(0);
                }
                while (!interrupt_done);

                hvImage.imageBase = vBase;
                hvImage.outputImage = vtemp;

                interrupt_done = 0;
                if (i = icpVertFilter(instance, &hvImage)) {
                    printf("Error in icpVertFilter: %x \n", i);
                    exit(0);
                }
                while (!interrupt_done);

                hvImage.inputStride = STRIDE;
                hvImage.inputWidth = WIDTH;
                hvImage.outputStride = STRIDE;
                hvImage.outputWidth = WIDTH;
                hvImage.outputImage = ytemp;
                hvImage.imageBase = yBase;

                interrupt_done = 0;
                if (i = icpVertFilter(instance, &hvImage)) {
                    printf("Error in icpVertFilter: %x \n", i);
                    exit(0);
                }
                while (!interrupt_done);

                ccImage.yBase = ytemp;
                ccImage.uBase = utemp;
                ccImage.vBase = vtemp;
                ccImage.yInputStride = STRIDE;
                ccImage.uvInputStride = STRIDE / 2;
                ccImage.inputWidth = WIDTH;
                ccImage.inputHeight = destHeight;
                ccImage.outputWidth = destWidth;
                ccImage.outputHeight = destHeight;
                ccImage.outputStride = dispStride;
                ccImage.outputImage = (UInt8 *) dispAddr;
                ccImage.inType = vtfYUV;    /* We know the input
                                     * image format */
                ccImage.inu.inYUVFormat = vdfYUV422Planar;    /* We know the input
                                     * image format */
                ccImage.outputDestination = icpPCI;

#ifdef __LITTLE_ENDIAN__
                ccImage.littleEndian = True;
#else
#if defined(__BIG_ENDIAN__) && defined(__TCS_WinNT__)
                ccImage.littleEndian = True;
#else
                ccImage.littleEndian = False;
#endif
#endif

                ccImage.overlayEnable = 0;
                ccImage.bitMaskEnable = 0;
                ccImage.outType = vtfRGB; 

                if (bpp == 1)
                    ccImage.outu.outRGBFormat = vcfRGB8A_233;
                else if (bpp == 2 && not555a)
                    ccImage.outu.outRGBFormat = vcfRGB16;
                else if (bpp == 2 && (!not555a))
                    ccImage.outu.outRGBFormat = vcfRGB15Alpha;
                else if (bpp == 3)
                    ccImage.outu.outRGBFormat = vcfRGB24;
                else if (bpp == 4)
                    ccImage.outu.outRGBFormat = vcfRGB24Alpha;

                interrupt_done = 0;
                if (i = icpColorConversion(instance, &ccImage)) {
                    printf("Error in icpColorConversion: %x \n", i);
                    exit(0);
                }
                while (!interrupt_done);
            }

        }

        /****************** Overlays *********************************/

        else if (filterType == 2) {
            for (tmpalpha = 0; tmpalpha <= 1.0; tmpalpha += 0.002) {
                /* Get the overlay image */
                ccImage.yBase = overlay_y;
                ccImage.uBase = overlay_u;
                ccImage.vBase = overlay_v;
                ccImage.yInputStride = O_STRIDE;
                ccImage.uvInputStride = O_STRIDE / 2;
                ccImage.inputWidth = O_WIDTH;
                ccImage.inputHeight = O_HEIGHT;
                ccImage.outputWidth = O_WIDTH;
                ccImage.outputHeight = O_HEIGHT;
                ccImage.filterBypass = icpFILTER;
                ccImage.outputPixelOffset = PIX_OFFSET;
                ccImage.outputStride = 2 * O_STRIDE;
                ccImage.outputImage = (UInt8 *) destImage;
                ccImage.outType = vtfYUV;
                ccImage.inu.inYUVFormat = vdfYUV422Planar;    /* We know the input
                                     * image format */
                ccImage.outType = vtfRGB;
                ccImage.outu.outRGBFormat = vcfRGB15Alpha;
                ccImage.outputDestination = icpSDRAM;

#ifdef __LITTLE_ENDIAN__
                ccImage.littleEndian = True;
#else
#if defined(__BIG_ENDIAN__) && defined(__TCS_WinNT__)
                ccImage.littleEndian = True;
#else
                ccImage.littleEndian = False;
#endif
#endif

                ccImage.overlayEnable = 0;
                ccImage.bitMaskEnable = 0;
                ccImage.alpha0 = tmpalpha;
                ccImage.alpha1 = tmpalpha;

                interrupt_done = 0;
                if (i = icpColorConversion(instance, &ccImage))
                    printf("Error: icpColorConversion: %x \n", i);
                while (!interrupt_done);

                /*
                 * Overlay image is stored in the SDRAM.
                 * Setup the overlay paramets
                 */
                overlay.overlayBase = (UInt8 *) destImage;
                overlay.stride = 2 * O_STRIDE;
                overlay.height = O_HEIGHT;
                overlay.width = O_WIDTH;
                overlay.startX = 1;
                overlay.startY = 1;
                overlay.videoType = vtfRGB;
                overlay.u.RGBformat = vcfRGB15Alpha;

#ifdef __LITTLE_ENDIAN__
                overlay.littleEndian = True;
#else
#if defined(__BIG_ENDIAN__) && defined(__TCS_WinNT__)
                overlay.littleEndian = True;
#else
                overlay.littleEndian = False;
#endif
#endif

                if (i = icpOverlaySetup(instance, &overlay))
                    printf("Error: icpOverlaySetup: %x \n", i);

                /*
                 * Now we can put this ccImage as overlay
                 * over the tv image
                 */
                ccImage.yBase = yBase;
                ccImage.uBase = uBase;
                ccImage.vBase = vBase;
                ccImage.yInputStride = STRIDE;
                ccImage.uvInputStride = STRIDE / 2;
                ccImage.inputWidth = WIDTH;
                ccImage.inputHeight = HEIGHT;
                ccImage.outputWidth = WIDTH;
                ccImage.outputHeight = HEIGHT;
                ccImage.filterBypass = icpFILTER;
                ccImage.outputPixelOffset = PIX_OFFSET;
                ccImage.outputStride = dispStride;
                ccImage.outputImage = (UInt8 *) dispAddr;
                ccImage.inType = vtfYUV;
                ccImage.inu.inYUVFormat = vdfYUV422Planar;    /* We know the input
                                     * image format */

⌨️ 快捷键说明

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