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

📄 testyuv.c

📁 MINI GUI1.6X源码
💻 C
字号:
/*** $Id: testyuv.c,v 1.4 2005/04/21 02:23:06 weiym Exp $**** The demo for YUV overlay.**** Copyright (C) 2003 Feynman Software.**** Create date: 2003/05/12*//***  This source is free software; you can redistribute it and/or**  modify it under the terms of the GNU General Public**  License as published by the Free Software Foundation; either**  version 2 of the License, or (at your option) any later version.****  This software is distributed in the hope that it will be useful,**  but WITHOUT ANY WARRANTY; without even the implied warranty of**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU**  General Public License for more details.****  You should have received a copy of the GNU General Public**  License along with this library; if not, write to the Free**  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,**  MA 02111-1307, USA*//*** TODO:*/#include <stdlib.h>#include <stdio.h>#include <string.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>static HDC pic;static BITMAP logo;static GAL_Overlay *overlay;/* NOTE: These RGB conversion functions are not intended for speed,         only as examples.*/void RGBtoYUV(Uint8 r, Uint8 g, Uint8 b, int *yuv){#if 1 /* these are the two formulas that I found on the FourCC site... */    yuv[0] = 0.299*r + 0.587*g + 0.114*b;    yuv[1] = (b-yuv[0])*0.565 + 128;    yuv[2] = (r-yuv[0])*0.713 + 128;#else    yuv[0] = (0.257 * r) + (0.504 * g) + (0.098 * b) + 16;    yuv[1] = 128 - (0.148 * r) - (0.291 * g) + (0.439 * b);    yuv[2] = 128 + (0.439 * r) - (0.368 * g) - (0.071 * b);#endif}void ConvertRGBtoYV12(HDC pic, GAL_Overlay *o){    int x,y;    int yuv[3];    Uint8 *op[3];    int width = logo.bmWidth, height = logo.bmHeight;    Uint8 r, g, b;    LockYUVOverlay(o);    /* Convert */    for(y=0; y<height && y<o->h; y++)    {        op[0] = o->pixels[0] + o->pitches[0]*y;        op[1] = o->pixels[1] + o->pitches[1]*(y/2);        op[2] = o->pixels[2] + o->pitches[2]*(y/2);        for ( x=0; x<width && x<o->w; x++)        {            GetPixelRGB (pic, x, y, &r, &g, &b);            RGBtoYUV (r, g, b, yuv);            *(op[0]++) = yuv[0];            if(x%2==0 && y%2==0)            {                *(op[1]++) = yuv[2];                *(op[2]++) = yuv[1];            }        }    }    UnlockYUVOverlay (o);}void Draw(void){    RECT rect;    int i;    for(i=30; i<200; i++)    {        rect.left = i;        rect.top=i;        rect.right=rect.left + overlay->w;        rect.bottom=rect.top + overlay->h;        DisplayYUVOverlay(overlay, &rect);    }    printf("Displayed %d times.\n",i);}void test_yuv(HWND hwnd, HDC hdc){    Uint32 overlay_format;    int i;    pic = CreateMemDC (400, 300, 32, MEMDC_FLAG_HWSURFACE, 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000);    LoadBitmapFromFile (pic, &logo, "./res/sample.bmp");    FillBoxWithBitmap (pic, 0, 0, 0, 0, &logo);    overlay_format = GAL_YV12_OVERLAY;    /* Create the overlay */    overlay = CreateYUVOverlay(logo.bmWidth, logo.bmHeight, overlay_format, hdc);    if ( overlay == NULL ) {        fprintf(stderr, "Couldn't create overlay!\n");        return;    }    printf("Created %dx%dx%d %s %s overlay\n",overlay->w,overlay->h,overlay->planes,            overlay->hw_overlay?"hardware":"software",            overlay->format==GAL_YV12_OVERLAY?"YV12":            overlay->format==GAL_IYUV_OVERLAY?"IYUV":            overlay->format==GAL_YUY2_OVERLAY?"YUY2":            overlay->format==GAL_UYVY_OVERLAY?"UYVY":            overlay->format==GAL_YVYU_OVERLAY?"YVYU":            "Unknown");    for(i=0; i<overlay->planes; i++)    {        printf("  plane %d: pitch=%d\n", i, overlay->pitches[i]);    }        /* Convert to YUV, and draw to the overlay */    switch(overlay->format)    {        case GAL_YV12_OVERLAY:            ConvertRGBtoYV12(pic,overlay);            break;        default:            printf("cannot convert RGB picture to obtained YUV format!\n");            return;    }        /* Do all the drawing work */    Draw();    FreeYUVOverlay (overlay);    DeleteMemDC(pic);    UnloadBitmap (&logo);}

⌨️ 快捷键说明

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