主要介绍一下如何读YV12格式信息的问题?头都搞昏了

解决方案 »

  1.   

    see
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/yuvformats.asp
    可能有用
      

  2.   

    可以参考以下程序YV12转BMP
    save_bmp(char *inbase, char *outname, int is411)
    {    char filename [81];
        short int scanLineSize, wd, ht, i, j, r, c, ch, no_by, nibble, 
            repeat_count, R, G, B, y, u, v;
        long int l;
        FILE *ou, *yuvFile;
        BITMAPFILEHEADER fileHd;
        BITMAPINFOHEADER infoHd;
      
        ou = fopen (outname, "rb");
        if (ou != NULL) {
             fclose (ou);
         }
         
       
        ou = fopen (outname, "wb");
        if (ou == NULL) {
             return;
         }    
        yuvFile = fopen (inbase, "rb");

    memcpy(yuvBuf,inbase,bmp_wd * bmp_ht * 2);
        bufy = yuvBuf;
        bufu = yuvBuf + bmp_wd * bmp_ht;
        bufv = yuvBuf + bmp_wd * bmp_ht * 3/2;
       
           scanLineSize = ((bmp_wd + 3)) & ~3;
       
           fileHd.bfType          =     0x4d42;
           fileHd.bfSize          =     sizeof (fileHd) + sizeof (infoHd) +
                                        (long int) scanLineSize * bmp_ht;
           fileHd.bfReserved1     =     0;
           fileHd.bfReserved2     =     0;
           fileHd.bfOffBits       =     sizeof (fileHd) + sizeof (infoHd);
       
           infoHd.biSize          =     sizeof (infoHd);
           infoHd.biWidth         =     bmp_wd;
           infoHd.biHeight        =     bmp_ht;
           infoHd.biPlanes        =     1;
           infoHd.biBitCount      =     24;
           infoHd.biCompression   =     0;
           infoHd.biSizeImage     =     (long int) scanLineSize * (long) bmp_ht * 3;
           infoHd.biXPelsPerMeter =     0;
           infoHd.biYPelsPerMeter =     0;
           infoHd.biClrUsed       =     0;
           infoHd.biClrImportant  =     0;
       
           fwrite (&fileHd, sizeof (fileHd), 1, ou);
           fwrite (&infoHd, sizeof (infoHd), 1, ou);
       
        for (r = 0; r < bmp_ht; r++) {
       
               if ((is411 == 0) || ((r & 1) == 0)) {
           
               }
               fseek (ou, fileHd.bfOffBits + (long int) scanLineSize * (bmp_ht - r - 1) * 3, SEEK_SET);
       
        for (c = 0; c < bmp_wd; c++) {
        y = bufy [c];
        u = bufu [c >> 1] - 128;
        v = bufv [c >> 1] - 128;
        R = y + 1.375 * v;
        G = y - 0.34375 * u - 0.703125 * v;
        B = y + 1.734375 * u;
        R = max (0, min (255, R));
        G = max (0, min (255, G));
        B = max (0, min (255, B));
                   fputc (B, ou); // b
                   fputc (G, ou); // g
                   fputc (R, ou); // r
               }
               for (; c < scanLineSize; c++) {
                   fputc (0, ou);
                   fputc (0, ou);
                   fputc (0, ou);
               }
        bufy += bmp_wd;
        bufu += bmp_wd/2;
        bufv += bmp_wd/2;
        }
    fclose (ou); 
     }