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

📄 vivot.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的外部设备的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
        for (j = 0; j < 176; j++) {
            *tmpPtr = ((*pY1++ & 0xff) << 24) | (*pV++ & 0xff) << 16 |
                      ((*pY0++ & 0xff) << 8) | (*pU++ & 0xff) << 0;
            tmpPtr++;
            pY1++;
            pY0++;
        }
        for (j = 0; j < 16; j++) {
            pY0 += 2;
            pY1 += 2;
            pU++;
            pV++;
        }
    }    
}

void
mmOvlyBufUpdate()
{
    Int         mmtmpNum;
    tmLibdevErr_t err;

    mmtmpNum = (mmNum + 1) % NUM_BUF_ENTRIES;
    if (genBuf[mmtmpNum].flag == VID_RDY_MM) {

        /*
         * genBuf[mmtmpNum] has the newly captured image from
         * video-in
         * 
         * convert genBuf[mmtmpNum].YUV CIF422 to
         * gebbuf[mmNum].Y-Overlay
         * 
         * that is: convert them from Y U V planar to YVYU
         * 
         * put the YVYU in genBuf[mmNum] and label it VO ready for
         * display
         * 
         * set mmNum=mmtmpNum
         */
#if 0
        CIF422OVERLAY(genBuf[mmtmpNum].Y, genBuf[mmtmpNum].U,
                  genBuf[mmtmpNum].V, genBuf[mmNum].Y);
#else
        icpImage.yBase = (Pointer)genBuf[mmtmpNum].Y;
        icpImage.uBase = (Pointer)genBuf[mmtmpNum].U;
        icpImage.vBase = (Pointer)genBuf[mmtmpNum].V;
        icpImage.outputImage = (Pointer)genBuf[mmNum].Y;
        if (err = icpColorConversion(icpInst, &icpImage))
            my_abort("icpColorConversion", err);
        while (icpCheckBUSY());
#endif
        genBuf[mmNum].flag = VID_RDY_VO;
        mmNum = mmtmpNum;
    }
}

UInt32
allocSz(int bufSz)
{
    UInt32      temp;
    Int         i;

    if ((temp = (UInt32) _cache_malloc(bufSz, -1)) == Null)
        my_abort("_cache_malloc", 0);

    memset(temp, 0, bufSz);
    _cache_copyback((Pointer)temp, bufSz);

    return temp;
}

void
allocCif422()
{
    Int         i;

    for (i = 0; i < NUM_BUF_ENTRIES; i++) {
        cif422Buf[i].Y = fullResBuf[i].Y;
        cif422Buf[i].U = fullResBuf[i].U;
        cif422Buf[i].V = fullResBuf[i].V;

        /* To save memory, cif422Buf point to fullResBuf. Since 
       fullResBuf and cif422Buf are never used at the same
       time in this program, we can do this.
       If you do allocate separate memory for cif422Buf and 
       use cif422Buf[i].Y to store overlay, then make sure
       you allocate enough memory (>cifStride * (cifHeight + 4))
       for it */

        cif422Buf[i].flag = VID_RDY_VI;
        DP(("Allocate CIF422Buf i %d Y %x U %x V %x\n",
            i, cif422Buf[i].Y, cif422Buf[i].U, cif422Buf[i].V));
    }
}

void
allocFullRes()
{
    Int         i, szY, szUV;

    szY = (fullStride * (fullHeight + 4));
    szUV = ((fullStride >> 1) * (fullHeight + 4));
    for (i = 0; i < NUM_BUF_ENTRIES; i++) {
        fullResBuf[i].Y = allocSz(szY);
        fullResBuf[i].U = allocSz(szUV);
        fullResBuf[i].V = allocSz(szUV);
        fullResBuf[i].flag = VID_RDY_VI;
        DP(("Allocate fullResBuf i %d Y %x U %x V %x\n",
            i, fullResBuf[i].Y, fullResBuf[i].U, fullResBuf[i].V));
    }
}

void
allocBkBuf()
{
    Int         szY, szUV;

    szY = (768 * (576 + 4));
    szUV = ((768 >> 1) * (576 + 4));
    bkBuf[0].Y = allocSz(szY);
    bkBuf[0].U = allocSz(szUV);
    bkBuf[0].V = allocSz(szUV);
    bkBuf[0].flag = VID_RDY_VI;
    DP(("Allocate bkBuf Y %x U %x V %x\n",
        bkBuf[0].Y, bkBuf[0].U, bkBuf[0].V));
}

void
cpGenBuf(vBuf * buf, Int numBuf, Int flag)
{
    vBuf       *pBuf;
    Int         i;

    pBuf = buf;
    for (i = 0; i < numBuf; i++) {
        genBuf[i].Y = pBuf[i].Y;
        genBuf[i].U = pBuf[i].U;
        genBuf[i].V = pBuf[i].V;
        genBuf[i].flag = flag;
    }
}

int
readYUVFiles(char *baseName, Int hsize, Int vsize,
         UInt32 ybuf, UInt32 ubuf, UInt32 vbuf)
{
    Int         count, ySize, uvSize, row;
    char        fn[80];
    UInt8 *pb;
    FILE       *fp;

    printf("Reading the overlay file...\n");
    /* get memory */
    ySize = hsize * vsize;
    uvSize = (ySize >> 1);

    /* just read Y file: binary */
    sprintf(fn, "%s.y", baseName);
    fp = fopen(fn, "rb");
    if (!fp)
        return (4);
    count = fread((char *) ybuf, 1, ySize, fp);
    fclose(fp);
    _cache_copyback((Pointer) ybuf, ySize);

    /* just read U file: binary */
    sprintf(fn, "%s.u", baseName);
    fp = fopen(fn, "rb");
    if (!fp)
        return (4);
    pb = (UInt8 *) ubuf;
    count = 0;
    for (row = 0; row < (vsize >> 1); row++) {
        count += fread(pb, 1, (hsize >> 1), fp);
        memcpy(pb + (hsize >> 1), pb, (hsize >> 1));
        pb += hsize;
    }
    _cache_copyback((Pointer) ubuf, uvSize);
    fclose(fp);

    /* just read V file: binary */
    sprintf(fn, "%s.v", baseName);
    fp = fopen(fn, "rb");
    if (!fp)
        return (4);
    pb = (UInt8 *) vbuf;
    count = 0;
    for (row = 0; row < (vsize >> 1); row++) {
        count += fread(pb, 1, hsize >> 1, fp);
        memcpy(pb + (hsize >> 1), pb, hsize >> 1);
        pb += hsize;
    }
    _cache_copyback((Pointer) vbuf, uvSize);
    fclose(fp);

    return (0);
}

void
voOpenAPI()
{
    tmLibdevErr_t err;

    if (err = voOpen(&voInst))
        my_abort("voOpen", err);

    memset((char *) (&voInstSup), 0, sizeof (voInstanceSetup_t));

    voInstSup.interruptPriority = intPRIO_6;
    voInstSup.isr = voTestISR;
    voInstSup.videoStandard = videoStandard;
    voInstSup.adapterType = outAdapterType;

    /* this function call calculates the ddsFrequency register according to */
    /* the chip version. See formula on VO, Figure 7.6 in the Databook for  */
    /* TM1000. See respective sections for TM1100, TM1300, and TM2700       */
    voFrequencyToDDS(27000000.0, &voInstSup.ddsFrequency);

    voInstSup.hbeEnable = True;
    voInstSup.underrunEnable = True;

    if (err = voInstanceSetup(voInst, &voInstSup))
        my_abort("voInstanceSetup", err);
}

void
voYUVAPI(voYUVModes_t mode,
     Int imageWidth, Int imageHeight, Int imageStride,
     Int imageVertOffset, Int imageHorzOffset,
     Pointer yBase, Pointer uBase, Pointer vBase)
{
    tmLibdevErr_t err;

    memset((char *) (&voYUVSup), 0, sizeof (voYUVSetup_t));
    voYUVSup.mode = mode;
    voYUVSup.buf1emptyEnable = True;
    voYUVSup.yThresholdEnable = False;
    voYUVSup.yThreshold = 0;
    voYUVSup.yBase = yBase;
    voYUVSup.uBase = uBase;
    voYUVSup.vBase = vBase;

    voYUVSup.imageVertOffset = imageVertOffset;
    voYUVSup.imageHorzOffset = imageHorzOffset;
    voYUVSup.imageHeight = (imageHeight >> 1);
    voYUVSup.yStride = (2 * imageStride);
    voYUVSup.uStride = imageStride;
    voYUVSup.vStride = imageStride;

    switch (mode) {
    case vo422_COSITED_UNSCALED:
    case vo422_INTERSPERSED_UNSCALED:
    case vo420_UNSCALED:
        voYUVSup.imageWidth = imageWidth;
        break;
    case vo422_COSITED_SCALED:
    case vo422_INTERSPERSED_SCALED:
    case vo420_SCALED:
    default:
        voYUVSup.imageWidth = imageWidth << 1;
        break;
    }

    if (err = voYUVSetup(voInst, &voYUVSup))
        my_abort("voYUVSetup", err);

    if (err = voStart(voInst))
        my_abort("voStart", err);
}

void
voOverlayAPI(int sLine, Int sPixel, Int width, Int height,
         UInt alpha0, UInt alpha1, Int offset, Pointer base)
{
    tmLibdevErr_t err;

    memset((char *) (&voOverlaySup), 0, sizeof (voOverlaySetup_t));
    voOverlaySup.overlayEnable = True;
    voOverlaySup.overlayStartY = sLine;
    voOverlaySup.overlayStartX = sPixel;
    voOverlaySup.overlayWidth = width;
    voOverlaySup.overlayHeight = height;
    voOverlaySup.alpha0 = alpha0;
    voOverlaySup.alpha1 = alpha1;
    voOverlaySup.overlayStride = offset;
    voOverlaySup.overlayBase = base;

    if (err = voOverlaySetup(voInst, &voOverlaySup))
        my_abort("voOverlaySetup", err);
}

void
viOpenAPI()
{
    tmLibdevErr_t err;

    if (err = viOpenM(&viInst, videoInUnit))
        my_abort("viOpen", err);

    memset((char *) (&viInstSup), 0, sizeof (viInstanceSetup_t));

    viInstSup.interruptPriority = intPRIO_3;
    viInstSup.isr = viTestISR;
    viInstSup.videoStandard = videoStandard;
    viInstSup.adapterType = inAdapterType;

    if (err = viInstanceSetup(viInst, &viInstSup))
        my_abort("viInstanceSetup", err);

}

void
viYUVAPI(viYUVModes_t mode, Int width, Int height, Int stride, Int fieldBuf,
     Int startx, Int starty, Pointer yBase, Pointer uBase, Pointer vBase)
{
    tmLibdevErr_t err;
    UInt startX, startY, endX, endY;

    memset((char *) (&viYUVSup), 0, sizeof (viYUVSetup_t));

    viYUVSup.thresholdReachedEnable = False;
    viYUVSup.captureCompleteEnable = True;
    viYUVSup.cositedSampling = True;

    viYUVSup.mode = mode;
    viYUVSup.yThreshold = 0;

    /* Try to get horizontal and vertical start position from vi */
    if (viGetDefaultAcquisitionWnd(viInst, &startX, &startY, &endX, &endY) == TMLIBDEV_OK)
    {
        if (mode == viHALFRES)
            /* Make sure startX is a multiple of 4 */
            viYUVSup.startX = (startX + 3) & 0xFC;
        else
            viYUVSup.startX = startX;

        viYUVSup.startY = startY;
    }
    else
    {
        /* If not available by vi, use defaults */ 
        viYUVSup.startX = startx;
        viYUVSup.startY = starty;
    }

    /* Using a small vertical offset means we have to invert the field ID... */
    if (viYUVSup.startY < 7)
        invertField = True;
    else
        invertField = False;
 
    viYUVSup.width = width;

    viYUVSup.yBase = yBase;
    viYUVSup.uBase = uBase;
    viYUVSup.vBase = vBase;

    if (fieldBuf) {
        viYUVSup.height = height;
        viYUVSup.yDelta = (stride - width) + 1;
        viYUVSup.uDelta = ((stride - width) >> 1) + 1;
        viYUVSup.vDelta = ((stride - width) >> 1) + 1;
    }
    else {
        viYUVSup.height = (height >> 1);
        viYUVSup.yDelta = (stride - width) + stride + 1;
        viYUVSup.uDelta = ((stride - width) >> 1) + (stride >> 1) + 1;
        viYUVSup.vDelta = ((stride - width) >> 1) + (stride >> 1) + 1;
    }
    if (err = viYUVSetup(viInst, &viYUVSup))
        my_abort("viYUVSetup", err);

    if (err = viStart(viInst))
        my_abort("viStart", err);
}

void
vivoFreeOverlay()
{
    _cache_free((Pointer) bkBuf[0].Y);
    _cache_free((Pointer) bkBuf[0].U);
    _cache_free((Pointer) bkBuf[0].V);
}

void
vivoRunOverlay()
{

⌨️ 快捷键说明

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