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

📄 icptest.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的外部设备的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
                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 = 1;
                ccImage.bitMaskEnable = 0;
                ccImage.alpha0 = tmpalpha;
                ccImage.alpha1 = tmpalpha;
                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: icpColorConversion: %x \n", i);
                while (!interrupt_done);

            }    /* end tmpalpha */

            for (j = 0; j < WIDTH; j += 5) {

                /*
                 * 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 = j;
                overlay.startY = j;
                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);

                /*
                 * Since no image parameters have changed we
                 * do not neet to adjust the structure
                 */
                interrupt_done = 0;
                if (i = icpColorConversion(instance, &ccImage))
                    printf("Error: icpColorConversion: %x \n", i);
                while (!interrupt_done);


            }    /* end j */

        }        /* end if filterType==2 */

        else if (filterType == 3) {    /* This is bit mask */

            ccImage.yBase = yBlack;
            ccImage.uBase = uBlack;
            ccImage.vBase = vBlack;
            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 = vdfYUV420Planar;    /* 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.alpha0 = tmpalpha;
            ccImage.alpha1 = tmpalpha;
            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: icpColorConversion: %x \n", i);
            while (!interrupt_done);

            ccImage.yBase = yBase;
            ccImage.uBase = uBase;
            ccImage.vBase = vBase;
            ccImage.inType = vtfYUV;
            ccImage.inu.inYUVFormat = vdfYUV422Planar;
            ccImage.bitMaskEnable = 1;
            ccImage.overlayEnable = 0;

            bitmask.bitMaskBase = bitimage;
            bitmask.stride = WIDTH / 8 + 1;
            icpBitMaskSetup(instance, &bitmask);

            for (j = 0; j < HEIGHT / 2 + 1; j += 1) {

                CreateImage(bitimage, HEIGHT, WIDTH + 8, j);

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

            }    /* end for j */

        }        /* end if filterType == 3 */

        else if (filterType == 4) {    /* This is chroma keying */

            for (a = 0; a <= 1; a += 0.008) {

                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.inType = 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 = 0.0;
                ccImage.alpha1 = 1.0;

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

                /*
                 * Now that we have an overlay image, we can
                 * start chroma keying
                 */
                icpGetChromaKey(destImage, O_STRIDE, O_WIDTH, O_HEIGHT, 1.0, a);

                /*
                 * 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 = WIDTH / 2 - O_WIDTH / 2;
                overlay.startY = HEIGHT / 2 - O_HEIGHT / 2;
                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.outputStride = dispStride;
                ccImage.outputImage = (UInt8 *) dispAddr;
                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 = 1;
                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: icpColorConversion: %x \n", i);
                while (!interrupt_done);

            }    /* end for a */

            for (j = (HEIGHT / 2 - O_HEIGHT / 2); j < (HEIGHT - O_HEIGHT); j += 2) {

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

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

            }    /* end for j */

            for (j = 0; j < 1000; j += 2) {

                ccImage.alpha0 = ((Float) (j)) / ((Float) 1000);
                ccImage.alpha1 = 1 - ccImage.alpha0;
                interrupt_done = 0;
                if (i = icpColorConversion(instance, &ccImage))
                    printf("Error: icpColorConversion: %x \n", i);
                while (!interrupt_done);


            }    /* end for j */

        }

    }            /* end while filterType */

    /******************* Finish Processing ICP ***********************/

    if (icpClose(instance))
        printf("Error: Can not close ICP ... \n");
    printf("Done \n");

}                /* end main */


/*
 * Function        : icpISR
 *                   Example Interrupt service routine for ICP.
 *                   User may insert their own Interrupt service routine here.
 *                   Acknowledges Interrupt, and returns.
 * Parameters      : None
 */

void 
icpISR(void)
{
    /* too small for a need to run on the system stack */
#pragma TCS_handler
#pragma TCS_atomic

    interrupt_done = 1;
    icpEnableACK_DONE();

    return;

}

int 
readYUVFile(char *baseName,
            int hsize, int vsize,
            UInt8 ** bufY, UInt8 ** bufU, UInt8 ** bufV,
            int yuv422or420 )
{
    int         count;
    int         ySize;
    int         uvSize;
    char        fn[80];
    FILE       *fp;

    /* get memory */
    ySize = hsize * vsize;
    /* get memory */
    ySize = hsize * vsize;
    if (yuv422or420 == vdfYUV422Planar)
        uvSize = ySize >> 1;
    else if (yuv422or420 == vdfYUV420Planar)
        uvSize = ySize >> 2;
    *bufY = (UInt8 *) _cache_malloc(ySize, -1);
    if (!bufY)
        return (1);
    *bufU = (UInt8 *) _cache_malloc(uvSize, -1);
    if (!bufU)
        return (2);
    *bufV = (UInt8 *) _cache_malloc(uvSize, -1);
    if (!bufV)
        return (3);

    /* Y file: binary */
    sprintf(fn, "%s.y", baseName);
    fp = fopen(fn, "rb");
    if (!fp) {
        printf("ERROR: File %s does not exist. \n", fn);
        return (4);
    }
    count = fread((char *) *bufY, 1, ySize, fp);
    if (count != ySize) {
        printf("ERROR: read error, read only %d, "
               "expected %d. \n", count, ySize);
        return (4);
    }
    _cache_copyback(*bufY, ySize);
    fclose(fp);

    /* U file: binary */
    sprintf(fn, "%s.u", baseName);
    fp = fopen(fn, "rb");
    if (!fp) {
        printf("ERROR: File %s does not exist. \n", fn);
        return (5);
    }
    count = fread((char *) *bufU, 1, uvSize, fp);
    if (count != uvSize) {
        printf("ERROR: read error, read only %d, "
               "expected %d. \n", count, uvSize);
        return (4);
    }
    _cache_copyback(*bufU, uvSize);
    fclose(fp);

    /* V file: binary */
    sprintf(fn, "%s.v", baseName);
    fp = fopen(fn, "rb");
    if (!fp) {
        printf("ERROR: File %s does not exist. \n", fn);
        return (6);
    }
    count = fread((char *) *bufV, 1, uvSize, fp);
    if (count != uvSize) {
        printf("ERROR: read error, read only %d, "
               "expected %d. \n", count, uvSize);
        return (4);
    }
    _cache_copyback(*bufV, uvSize);
    fclose(fp);

    return (0);
}

/* *********************************************************************** */
/*
 * Function             : imageView
 *                        Dump the source image into destination using memcpy.
 * Parameters           : UInt8 *srcAddr; Char pointer to source address.
 *                        Int width;     Width of the image in pixels
 *                        Int height;    Height of the image in pixels

⌨️ 快捷键说明

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