Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define CLAMP(t) ((t>255)?255:((t<0)?0:t))
- // RGB to YUV
- #define GET_Y(R,G,B) CLAMP((( 66 * (R) + 129 * (G) + 25 * (B) + 128) >> 8) + 16)
- #define GET_U(R,G,B) CLAMP(((-38 * (R) - 74 * (G) + 112 * (B) + 128) >> 8) + 128)
- #define GET_V(R,G,B) CLAMP(((112 * (R) - 94 * (G) - 18 * (B) + 128) >> 8) + 128)
- unsigned int Capture::GrabPlanar(unsigned char **Y, unsigned char **U, unsigned char **V){
- if(*Y != nullptr || *U != nullptr || *V != nullptr){return 0;}
- unsigned char *frame = nullptr;
- unsigned int width, height, plane_size = 0;
- unsigned int size = GrabBitmap(&frame, width, height, 1);
- if( size){ // I420 algorithm...
- plane_size = width * height;
- *Y = (unsigned char *)malloc(plane_size );
- *U = (unsigned char *)malloc(plane_size >> 2);
- *V = (unsigned char *)malloc(plane_size >> 2);
- unsigned char R, G, B;
- unsigned int iY, iU, iV;
- iY = iU = iV = 0;
- for(unsigned int i; i < size; i+=3){
- R = frame[i ];
- G = frame[i+1];
- B = frame[i+2];
- (*Y)[iY] = GET_Y(R,G,B);
- // Не знаю что делать с индексами iU и iV
- // там ведь буфер в 4 раза меньше, можно на ошибку сегментации нарваться...
- iY++;
- }
- }
- if( frame != nullptr ){free(frame);}
- return plane_size;
- }
Add Comment
Please, Sign In to add comment