• 记录一下在uyuv 转 planar yuv420 的做法


    1、uyuv 排列格式

    8bit   8bit   8bit  8bit

    u        y        u     v

    planar yuv420 排列格式

    8bit 

    y y y y y y y y

    u u

    v v

    转换代码是

    void YUVCSCWgt::on_btn_spyuv420_clicked()
    {
        char uyuv_buf[LINENUM*2];
        char y_buf[LINENUM];
        char u_buf[LINENUM/2];
        char v_buf[LINENUM/2];
    
        InitFile();
    
        for(int i=0;i<1080;i++)
        {
            rw_len=m_yvuFile->read(uyuv_buf,LINENUM*2);
            if(rw_len!=LINENUM*2)
            {
                printf("read line num error! %d 
    ",rw_len);
            }
    
            for(int j=0;j<LINENUM*2;j++)
            {
                if(i%2==0)
                {
                    if(j%4==0)
                    {
                        u_buf[j/4]=uyuv_buf[j];
                    }
                    else if(j%4==2)
                    {
                        v_buf[j/4]=uyuv_buf[j];
                    }
                }
    
                if(j%4==3 || j%4==1)
                {
                    y_buf[j/2]=uyuv_buf[j];
                }
            }
    
            m_yuvFile_y->write(y_buf,LINENUM);
            m_yuvFile_y->flush();
            if(i%2==0)
            {
                m_yuvFile_u->write(u_buf,LINENUM/2);
                m_yuvFile_u->flush();
                m_yuvFile_v->write(v_buf,LINENUM/2);
                m_yuvFile_v->flush();
            }
        }
    
        //write to yuvfile
        m_yuvFile_y->seek(0);
        m_yuvFile_u->seek(0);
        m_yuvFile_v->seek(0);
    
        for(int i=0;i<1080;i++)
        {
            rw_len=m_yuvFile_y->read(uyuv_buf,LINENUM);
            if(rw_len!=LINENUM)
            {
                printf("read line num error! %d 
    ",rw_len);
            }
            rw_len=m_yuvFile->write(uyuv_buf,LINENUM);
            if(rw_len!=LINENUM)
            {
                printf("read line num error! %d 
    ",rw_len);
            }
            m_yuvFile->flush();
        }
        //m_yuvFile_y->close();
    
        for(int i=0;i<270;i++)
        {
            rw_len=m_yuvFile_u->read(uyuv_buf,LINENUM);
            if(rw_len!=LINENUM)
            {
                printf("read line num error! %d 
    ",rw_len);
            }
            rw_len=m_yuvFile->write(uyuv_buf,LINENUM);
            if(rw_len!=LINENUM)
            {
                printf("read line num error! %d 
    ",rw_len);
            }
            m_yuvFile->flush();
        }
        //m_yuvFile_v->close();
    
        for(int i=0;i<270;i++)
        {
            rw_len=m_yuvFile_v->read(uyuv_buf,LINENUM);
            if(rw_len!=LINENUM)
            {
                printf("read line num error! %d 
    ",rw_len);
            }
            rw_len=m_yuvFile->write(uyuv_buf,LINENUM);
            if(rw_len!=LINENUM)
            {
                printf("read line num error! %d 
    ",rw_len);
            }
            m_yuvFile->flush();
        }
    
        m_yvuFile->close();
        m_yuvFile->close();
        m_yuvFile_y->close();
        m_yuvFile_u->close();
        m_yuvFile_v->close();
    }
  • 相关阅读:
    20171017/20171018
    BZOJ[3193] [JLOI2013]地形生成
    BZOJ[1009] [HNOI2008]GT考试
    BZOJ[4767] 两双手
    BZOJ[4013] [HNOI2015]实验比较
    BZOJ[1925] [Sdoi2010]地精部落
    20171015 杂题
    20171015
    20171014
    USACO 2015 December Contest, Gold Problem 3. Bessie's Dream
  • 原文地址:https://www.cnblogs.com/eastgeneral/p/11940582.html
Copyright © 2020-2023  润新知