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

📄 vconvert.cxx

📁 pwlib源码库
💻 CXX
📖 第 1 页 / 共 4 页
字号:
      SwapRedAndBlueRow(srcRowPtr, dstRowPtr, srcFrameWidth, srcIncrement, dstIncrement);      srcRowPtr += srcRowSize;      dstRowPtr += dstRowSize;    }  }  if (bytesReturned != NULL)    *bytesReturned = dstFrameBytes;  return TRUE;}PSTANDARD_COLOUR_CONVERTER(RGB24,BGR24){  return SwapRedAndBlue(srcFrameBuffer, dstFrameBuffer, bytesReturned, 3, 3);}PSTANDARD_COLOUR_CONVERTER(BGR24,RGB24){  return SwapRedAndBlue(srcFrameBuffer, dstFrameBuffer, bytesReturned, 3, 3);}PSTANDARD_COLOUR_CONVERTER(RGB24,BGR32){  return SwapRedAndBlue(srcFrameBuffer, dstFrameBuffer, bytesReturned, 3, 4);}PSTANDARD_COLOUR_CONVERTER(BGR24,RGB32){  return SwapRedAndBlue(srcFrameBuffer, dstFrameBuffer, bytesReturned, 3, 4);}PSTANDARD_COLOUR_CONVERTER(RGB32,BGR24){  return SwapRedAndBlue(srcFrameBuffer, dstFrameBuffer, bytesReturned, 4, 3);}PSTANDARD_COLOUR_CONVERTER(BGR32,RGB24){  return SwapRedAndBlue(srcFrameBuffer, dstFrameBuffer, bytesReturned, 4, 3);}PSTANDARD_COLOUR_CONVERTER(RGB32,BGR32){  return SwapRedAndBlue(srcFrameBuffer, dstFrameBuffer, bytesReturned, 4, 4);}PSTANDARD_COLOUR_CONVERTER(BGR32,RGB32){  return SwapRedAndBlue(srcFrameBuffer, dstFrameBuffer, bytesReturned, 4, 4);}PSTANDARD_COLOUR_CONVERTER(RGB24,RGB32){  if ((dstFrameWidth != srcFrameWidth) || (dstFrameHeight != srcFrameHeight))    return FALSE;  // Go from bottom to top so can do in place conversion  const BYTE * src = srcFrameBuffer+srcFrameBytes-1;  BYTE * dst = dstFrameBuffer+dstFrameBytes-1;  for (unsigned x = 0; x < srcFrameWidth; x++) {    for (unsigned y = 0; y < srcFrameHeight; y++) {      *dst-- = 0;      for (unsigned p = 0; p < 3; p++)        *dst-- = *src--;    }  }  if (bytesReturned != NULL)    *bytesReturned = dstFrameBytes;  return TRUE;}PSTANDARD_COLOUR_CONVERTER(RGB32,RGB24){  if ((dstFrameWidth != srcFrameWidth) || (dstFrameHeight != srcFrameHeight))    return FALSE;  const BYTE * src = srcFrameBuffer;  BYTE * dst = dstFrameBuffer;  for (unsigned x = 0; x < srcFrameWidth; x++) {    for (unsigned y = 0; y < srcFrameHeight; y++) {      for (unsigned p = 0; p < 3; p++)        *dst++ = *src++;      src++;    }  }  if (bytesReturned != NULL)    *bytesReturned = dstFrameBytes;  return TRUE;}// Consider a YUV420P image of 8x2 pixels.//// A plane of Y values    A B C D E F G H//                        I J K L M N O P//// A plane of U values    1   2   3   4 // A plane of V values    1   2   3   4 ....//// The U1/V1 samples correspond to the ABIJ pixels.//     U2/V2 samples correspond to the CDKL pixels.//// Consider a YUV411P image of 8x2 pixels.//// A plane of Y values as before.//// A plane of U values    1       2//                        3       4//// A plane of V values    1       2//                        3       4//// The U1/V1 samples correspond to the ABCD pixels.//     U2/V2 samples correspond to the EFGH pixels.//// I choose to reoganize the U and V samples by using// using U1 for ABCD, U3 for EFGH, U2 for IJKL, U4 for MNOP//// Possibly discarding U2/U4 completely, or using the// average of U1 and U2 might be easier for compression//// TODO://// - Inplace converter// - Resizing / padding / scaling converter//PSTANDARD_COLOUR_CONVERTER(YUV420P,YUV411P){  if (srcFrameBuffer == dstFrameBuffer)    return FALSE;  if ((dstFrameWidth != srcFrameWidth) || (dstFrameHeight != srcFrameHeight))    return FALSE;  // Copy over the Y plane.  memcpy(dstFrameBuffer, srcFrameBuffer, srcFrameWidth*srcFrameHeight);  unsigned linewidth = dstFrameWidth / 4;  // Source data is the start of the U plane  const BYTE* src = srcFrameBuffer + srcFrameWidth * srcFrameHeight;  // Two output lines at a time  BYTE *dst0 = dstFrameBuffer + dstFrameWidth * dstFrameHeight;  BYTE *dst1 = dst0 + linewidth;  unsigned x, y;  // U plane  for (y = 0; y < dstFrameHeight; y += 2) {    for (x = 0; x < dstFrameWidth; x += 4) {      *dst0++ = *src++;      *dst1++ = *src++;    }    // Skip over the 2nd line we already did.    dst0 += linewidth;    dst1 = dst0 + linewidth;  }  // Source data is the start of the U plane  src = srcFrameBuffer + srcFrameWidth * srcFrameHeight * 5 / 4;  // Two output lines at a time  dst0 = dstFrameBuffer + dstFrameWidth * dstFrameHeight * 5 / 4;  dst1 = dst0 + linewidth;  // V plane  for (y = 0; y < dstFrameHeight; y += 2) {    for (x = 0; x < dstFrameWidth; x += 4) {      *dst0++ = *src++;      *dst1++ = *src++;    }    // Skip over the 2nd line we already did.    dst0 += linewidth;    dst1 = dst0 + linewidth;  }  if (bytesReturned != NULL)    *bytesReturned = dstFrameBytes;    return TRUE;}// YUV411P to YUV420P conversion//// Consider YUV411P U plane (. = pixel) ://// A... B... C... D...// E... F... G... H...// I... J... K... L...// M... N... O... P...//// We map this to a YUV420P plane by// discarding odd rows, and doubling up// the even row samples://// A.A. B.B. C.C. D.D.// .... .... .... ....// I.I. J.J. K.K. L.L.// .... .... .... ....//// TODO://// - Inplace converter// - Resizing / padding / scaling converter//PSTANDARD_COLOUR_CONVERTER(YUV411P,YUV420P){  if (srcFrameBuffer == dstFrameBuffer)    return FALSE;  if ((dstFrameWidth != srcFrameWidth) || (dstFrameHeight != srcFrameHeight))    return FALSE;  // Copy over the Y plane.  memcpy(dstFrameBuffer, srcFrameBuffer, srcFrameWidth*srcFrameHeight);  unsigned linewidth = dstFrameWidth / 4;  // Source data is the start of the U plane  const BYTE* src = srcFrameBuffer + srcFrameWidth * srcFrameHeight;  // Output line  BYTE *dst0 = dstFrameBuffer + dstFrameWidth * dstFrameHeight;  unsigned x, y;  // U plane  for (y = 0; y < dstFrameHeight; y += 2) {    for (x = 0; x < dstFrameWidth; x += 4) {      // Double up the horizontal samples      *dst0++ = *src;      *dst0++ = *src++;    }    // Skip over the 2nd line we are decimating    src += linewidth;  }  // Source data is the start of the U plane  src = srcFrameBuffer + srcFrameWidth * srcFrameHeight * 5 / 4;  // Output line  dst0 = dstFrameBuffer + dstFrameWidth * dstFrameHeight * 5 / 4;  // V plane  for (y = 0; y < dstFrameHeight; y += 2) {    for (x = 0; x < dstFrameWidth; x += 4) {      // Double up the samples horizontal samples      *dst0++ = *src;      *dst0++ = *src++;    }    // Skip over the 2nd source line we already did.    src += linewidth;  }  if (bytesReturned != NULL)    *bytesReturned = dstFrameBytes;  return TRUE;}/* * The following functions converts video from IEEE 1394 cameras into * YUV420P format. The video format of IEEE 1394 cameras can be found *  at Section 2.1.3 ofhttp://www.1394ta.org/Download/Technology/Specifications/2000/IIDC_Spec_v1_30.pdf * 320x240 and 160x120 resolutions are used. * * * UYVY422 is just a byte permutation of YUV422. I believe this is not * due to endian problem * * These functions should accept arbitrary size of image. */PSTANDARD_COLOUR_CONVERTER(UYVY422,YUV420P){  if (srcFrameBuffer == dstFrameBuffer)    return FALSE;  unsigned int row,column;  unsigned char *y = dstFrameBuffer;  //Initialise y,u,v here, to stop compiler warnings.  unsigned char *u = dstFrameBuffer + dstFrameWidth*dstFrameHeight;  unsigned char *v = dstFrameBuffer + dstFrameWidth*(dstFrameHeight + dstFrameHeight/4);  const unsigned char *src = srcFrameBuffer;  for(row=0; row < PMIN(srcFrameHeight, dstFrameHeight); row+=2) {    y = dstFrameBuffer + dstFrameWidth*row;    u = dstFrameBuffer + dstFrameWidth*dstFrameHeight + dstFrameWidth*row/4;    v = dstFrameBuffer + dstFrameWidth*(dstFrameHeight + dstFrameHeight/4) + dstFrameWidth*row/4;    src = srcFrameBuffer + row*srcFrameWidth*2;    for(column=0; column < PMIN(srcFrameWidth, dstFrameWidth); column+=2) {      *(u++) = (unsigned char)(((int)src[0] + src[srcFrameWidth*2])/2);      *(y++) = src[1];      *(v++) = (unsigned char)(((int)src[2] + src[2+srcFrameWidth*2])/2);      *(y++) = src[3];      src += 4;    }    for(column = PMIN(srcFrameWidth, dstFrameWidth);	column < dstFrameWidth; column+=2) {      *(u++) = BLACK_U;      *(y++) = BLACK_Y;      *(v++) = BLACK_V;      *(y++) = BLACK_Y;    }    y = dstFrameBuffer + dstFrameWidth*(row+1);    src = srcFrameBuffer + (row+1)*srcFrameWidth*2;    for(column=0; column < PMIN(srcFrameWidth,dstFrameWidth); column+=2) {      src++;      *(y++) = *(src++);      src++;      *(y++) = *(src++);    }    for(column = PMIN(srcFrameWidth, dstFrameWidth);	column < dstFrameWidth; column+=2) {      *(y++) = BLACK_Y;      *(y++) = BLACK_Y;    }  }  for(row = PMIN(srcFrameHeight, dstFrameHeight);      row < dstFrameHeight; row+=2) {    for(column = 0; column < dstFrameWidth; column+=2) {      *(u++) = BLACK_U;      *(y++) = BLACK_Y;      *(v++) = BLACK_V;      *(y++) = BLACK_Y;    }    for(column = 0; column < dstFrameWidth; column+=2) {      *(y++) = BLACK_Y;      *(y++) = BLACK_Y;    }  }  if (bytesReturned != NULL)    *bytesReturned = dstFrameBytes;  return TRUE;}PSTANDARD_COLOUR_CONVERTER(UYV444,YUV420P){  if (srcFrameBuffer == dstFrameBuffer)    return FALSE;  unsigned int row,column;  unsigned char *y = dstFrameBuffer;  //Initialise y,u,v here, to stop compiler warnings.  unsigned char *u = dstFrameBuffer + dstFrameWidth*dstFrameHeight;  unsigned char *v = dstFrameBuffer + dstFrameWidth*(dstFrameHeight + dstFrameHeight/4);  const unsigned char *src = srcFrameBuffer;  for(row=0; row < PMIN(srcFrameHeight, dstFrameHeight); row+=2) {    y = dstFrameBuffer + dstFrameWidth*row;    u = dstFrameBuffer + dstFrameWidth*dstFrameHeight + dstFrameWidth*row/4;    v = dstFrameBuffer + dstFrameWidth*(dstFrameHeight + dstFrameHeight/4) + dstFrameWidth*row/4;    src = srcFrameBuffer + row*srcFrameWidth*3;    for(column=0; column < PMIN(srcFrameWidth, dstFrameWidth); column+=2) {      *(u++) = (unsigned char)(((unsigned int)src[0] + src[3] + src[srcFrameWidth*3] + src[3+srcFrameWidth*3])/4);      *(y++) = src[1];      *(v++) = (unsigned char)(((unsigned int)src[2] + src[5] + src[srcFrameWidth*3] +src[3+srcFrameWidth*3])/4);      *(y++) = src[4];      src += 6;    }    for(column = PMIN(srcFrameWidth, dstFrameWidth);	column < dstFrameWidth; column+=2) {      *(u++) = BLACK_U;      *(y++) = BLACK_Y;      *(v++) = BLACK_V;      *(y++) = BLACK_Y;    }    y = dstFrameBuffer + dstFrameWidth*(row+1);    src = srcFrameBuffer + (row+1)*srcFrameWidth*3;    for(column=0; column < PMIN(srcFrameWidth, dstFrameWidth); column++) {      src++;      *(y++) = *(src++);      src++;    }    for(column = PMIN(srcFrameWidth, dstFrameWidth);	column < dstFrameWidth; column++)      *(y++) = BLACK_Y;  }  for(row = PMIN(srcFrameHeight, dstFrameHeight);      row<dstFrameHeight; row+=2) {    for(column = 0; column < dstFrameWidth; column+=2) {      *(u++) = BLACK_U;      *(y++) = BLACK_Y;      *(v++) = BLACK_V;      *(y++) = BLACK_Y;    }    for(column = 0; column < dstFrameWidth; column+=2) {      *(y++) = BLACK_Y;      *(y++) = BLACK_Y;    }  }  if (bytesReturned != NULL)    *bytesReturned = dstFrameBytes;  return TRUE;}// End Of File ///////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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