QImage *ResizePreview::nv21torgb(CameraFrame *frame) { QByteArray *data = frame->data; int width = frame->width; int height = frame->height; QImage *img = new QImage(width,height,QImage::Format_ARGB32); int frameSize = width * height; int uvp = 0; int u = 0; int v = 0; int y = 0; int r = 0; int g = 0; int b = 0; for (int j = 0, yp = 0; j < height; ++j) { uvp = frameSize + (j >> 1) * width; u = 0; v = 0; for (int i = 0; i < width; ++i, ++yp) { y = (0xff & (int)data->at(yp)); if ((i & 1) == 0) { v = (0xff & ((int)data->at(uvp++)) - 128; u = (0xff & ((int)data->at(uvp++)) - 128; } r = y + 1.402f * v; g = y - 0.34414f * u - 0.71414f * v; b = y + 1.772f * u; if (r < 0) r = 0; else if (r > 255) r = 255; if (g < 0) g = 0; else if (g > 255) g = 255; if (b < 0) b = 0; else if (b > 255) b = 255; img->setPixel(i,j,qRgba(r,g,b,255)); } } return img;}
for (int j = 0, yp = 0; j < height; ++j) { uvp = frameSize + (j >> 1) * width;