Skip to content

Commit

Permalink
decoder: bayer mipi raw12 dormat
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoming <[email protected]>
  • Loading branch information
QQxiaoming committed Nov 26, 2021
1 parent e49ac73 commit 12e3617
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 19 deletions.
22 changes: 21 additions & 1 deletion src/UI_YUVviewer.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>550</width>
<width>750</width>
<height>255</height>
</rect>
</property>
Expand Down Expand Up @@ -178,6 +178,26 @@
<string>BayerGR</string>
</property>
</item>
<item>
<property name="text">
<string>BayerBG_RAW12</string>
</property>
</item>
<item>
<property name="text">
<string>BayerGB_RAW12</string>
</property>
</item>
<item>
<property name="text">
<string>BayerRG_RAW12</string>
</property>
</item>
<item>
<property name="text">
<string>BayerGR_RAW12</string>
</property>
</item>
</widget>
</item>
<item>
Expand Down
170 changes: 153 additions & 17 deletions src/YUVdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,27 @@

QMap<QString, yuvdecoder_t> YUV2RGB::yuvdecoder_map =
{
{"YV12", YUV2RGB::yv12},
{"YU12/I420", YUV2RGB::i420},
{"NV21", YUV2RGB::nv21},
{"NV12", YUV2RGB::nv12},
{"YUY2/YUYV", YUV2RGB::yuy2},
{"YVYU", YUV2RGB::yvyu},
{"UYVY", YUV2RGB::uyvy},
{"4:4:4", YUV2RGB::yuv444},
{"RGB565_L", YUV2RGB::rgb565_little_endian},
{"RGB565_B", YUV2RGB::rgb565_big_endian},
{"BGR565_L", YUV2RGB::bgr565_little_endian},
{"BGR565_B", YUV2RGB::bgr565_big_endian},
{"RGB888", YUV2RGB::rgb888},
{"BayerBG", YUV2RGB::bayerBG},
{"BayerGB", YUV2RGB::bayerGB},
{"BayerRG", YUV2RGB::bayerRG},
{"BayerGR", YUV2RGB::bayerGR},
{"YV12", YUV2RGB::yv12},
{"YU12/I420", YUV2RGB::i420},
{"NV21", YUV2RGB::nv21},
{"NV12", YUV2RGB::nv12},
{"YUY2/YUYV", YUV2RGB::yuy2},
{"YVYU", YUV2RGB::yvyu},
{"UYVY", YUV2RGB::uyvy},
{"4:4:4", YUV2RGB::yuv444},
{"RGB565_L", YUV2RGB::rgb565_little_endian},
{"RGB565_B", YUV2RGB::rgb565_big_endian},
{"BGR565_L", YUV2RGB::bgr565_little_endian},
{"BGR565_B", YUV2RGB::bgr565_big_endian},
{"RGB888", YUV2RGB::rgb888},
{"BayerBG", YUV2RGB::bayerBG},
{"BayerGB", YUV2RGB::bayerGB},
{"BayerRG", YUV2RGB::bayerRG},
{"BayerGR", YUV2RGB::bayerGR},
{"BayerBG_RAW12", YUV2RGB::bayerBG_RAW12},
{"BayerGB_RAW12", YUV2RGB::bayerGB_RAW12},
{"BayerRG_RAW12", YUV2RGB::bayerRG_RAW12},
{"BayerGR_RAW12", YUV2RGB::bayerGR_RAW12},
};

QList<cv::Mat*> YUV2RGB::yv12(QString yuvfilename,int W, int H, int startframe, int totalframe)
Expand Down Expand Up @@ -475,3 +479,135 @@ QList<cv::Mat*> YUV2RGB::bayerGR(QString yuvfilename,int W, int H, int startfram

return rgbImglist;
}

QList<cv::Mat*> YUV2RGB::bayerBG_RAW12(QString yuvfilename,int W, int H, int startframe, int totalframe)
{
QList<cv::Mat*> rgbImglist;
cv::Mat yuvImg;
QFile file(yuvfilename);
QFileInfo fileInfo(yuvfilename);
file.open(QFile::ReadOnly);
file.seek(startframe*W*H);
QDataStream out(&file);
char *temp = new char[W*H*3/2];

while((!out.atEnd()) && (totalframe != 0))
{
cv::Mat *rgbImg = new cv::Mat;
yuvImg.create(H, W, CV_8UC1);
out.readRawData(temp,W*H*3/2);
for(int i=0,j=0;i<W*H*3/2;i+=3) {
uint16_t piex[3] = {(uint16_t)temp[i],(uint16_t)temp[i+1],(uint16_t)temp[i+1]};
yuvImg.data[j] = (uint8_t)(((piex[0]<<4) | (piex[2]&0xf))/16);
yuvImg.data[j+1] = (uint8_t)(((piex[1]<<4) | ((piex[2]>>4)&0xf))/16);
j+=2;
}
cvtColor(yuvImg, *rgbImg, cv::COLOR_BayerBG2RGB);
totalframe--;
rgbImglist.insert(rgbImglist.end(), rgbImg);
}

delete[] temp;
file.close();

return rgbImglist;
}

QList<cv::Mat*> YUV2RGB::bayerGB_RAW12(QString yuvfilename,int W, int H, int startframe, int totalframe)
{
QList<cv::Mat*> rgbImglist;
cv::Mat yuvImg;
QFile file(yuvfilename);
QFileInfo fileInfo(yuvfilename);
file.open(QFile::ReadOnly);
file.seek(startframe*W*H);
QDataStream out(&file);
char *temp = new char[W*H*3/2];

while((!out.atEnd()) && (totalframe != 0))
{
cv::Mat *rgbImg = new cv::Mat;
yuvImg.create(H, W, CV_8UC1);
out.readRawData(temp,W*H*3/2);
for(int i=0,j=0;i<W*H*3/2;i+=3) {
uint16_t piex[3] = {(uint16_t)temp[i],(uint16_t)temp[i+1],(uint16_t)temp[i+1]};
yuvImg.data[j] = (uint8_t)(((piex[0]<<4) | (piex[2]&0xf))/16);
yuvImg.data[j+1] = (uint8_t)(((piex[1]<<4) | ((piex[2]>>4)&0xf))/16);
j+=2;
}
cvtColor(yuvImg, *rgbImg, cv::COLOR_BayerGB2RGB);
totalframe--;
rgbImglist.insert(rgbImglist.end(), rgbImg);
}

delete[] temp;
file.close();

return rgbImglist;
}

QList<cv::Mat*> YUV2RGB::bayerRG_RAW12(QString yuvfilename,int W, int H, int startframe, int totalframe)
{
QList<cv::Mat*> rgbImglist;
cv::Mat yuvImg;
QFile file(yuvfilename);
QFileInfo fileInfo(yuvfilename);
file.open(QFile::ReadOnly);
file.seek(startframe*W*H);
QDataStream out(&file);
char *temp = new char[W*H*3/2];

while((!out.atEnd()) && (totalframe != 0))
{
cv::Mat *rgbImg = new cv::Mat;
yuvImg.create(H, W, CV_8UC1);
out.readRawData(temp,W*H*3/2);
for(int i=0,j=0;i<W*H*3/2;i+=3) {
uint16_t piex[3] = {(uint16_t)temp[i],(uint16_t)temp[i+1],(uint16_t)temp[i+1]};
yuvImg.data[j] = (uint8_t)(((piex[0]<<4) | (piex[2]&0xf))/16);
yuvImg.data[j+1] = (uint8_t)(((piex[1]<<4) | ((piex[2]>>4)&0xf))/16);
j+=2;
}
cvtColor(yuvImg, *rgbImg, cv::COLOR_BayerRG2RGB);
totalframe--;
rgbImglist.insert(rgbImglist.end(), rgbImg);
}

delete[] temp;
file.close();

return rgbImglist;
}

QList<cv::Mat*> YUV2RGB::bayerGR_RAW12(QString yuvfilename,int W, int H, int startframe, int totalframe)
{
QList<cv::Mat*> rgbImglist;
cv::Mat yuvImg;
QFile file(yuvfilename);
QFileInfo fileInfo(yuvfilename);
file.open(QFile::ReadOnly);
file.seek(startframe*W*H);
QDataStream out(&file);
char *temp = new char[W*H*3/2];

while((!out.atEnd()) && (totalframe != 0))
{
cv::Mat *rgbImg = new cv::Mat;
yuvImg.create(H, W, CV_8UC1);
out.readRawData(temp,W*H*3/2);
for(int i=0,j=0;i<W*H*3/2;i+=3) {
uint16_t piex[3] = {(uint16_t)temp[i],(uint16_t)temp[i+1],(uint16_t)temp[i+1]};
yuvImg.data[j] = (uint8_t)(((piex[0]<<4) | (piex[2]&0xf))/16);
yuvImg.data[j+1] = (uint8_t)(((piex[1]<<4) | ((piex[2]>>4)&0xf))/16);
j+=2;
}
cvtColor(yuvImg, *rgbImg, cv::COLOR_BayerGR2RGB);
totalframe--;
rgbImglist.insert(rgbImglist.end(), rgbImg);
}

delete[] temp;
file.close();

return rgbImglist;
}
4 changes: 4 additions & 0 deletions src/YUVdecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class YUV2RGB
static QList<cv::Mat*> bayerGB(QString yuvfilename,int W, int H, int startframe, int totalframe);
static QList<cv::Mat*> bayerRG(QString yuvfilename,int W, int H, int startframe, int totalframe);
static QList<cv::Mat*> bayerGR(QString yuvfilename,int W, int H, int startframe, int totalframe);
static QList<cv::Mat*> bayerBG_RAW12(QString yuvfilename,int W, int H, int startframe, int totalframe);
static QList<cv::Mat*> bayerGB_RAW12(QString yuvfilename,int W, int H, int startframe, int totalframe);
static QList<cv::Mat*> bayerRG_RAW12(QString yuvfilename,int W, int H, int startframe, int totalframe);
static QList<cv::Mat*> bayerGR_RAW12(QString yuvfilename,int W, int H, int startframe, int totalframe);
static QMap<QString, yuvdecoder_t> yuvdecoder_map;
};

Expand Down
10 changes: 9 additions & 1 deletion src/YUVviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,15 @@ const QList<QPair<QString, QList<uint64_t>>> YUVviewer::YUVFormat_list = {
{"BayerRG", {UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,
UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B}},
{"BayerGR", {UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,UI_G,UI_R,
UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G}}
UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G}},
{"BayerBG_RAW12", {UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,UI_B,UI_G,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