Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CODEC_ERROR ConvertBGRA64ToFrame_4444_16s(uint8_t *data, int pitch, FRAME *frame,
- uint8_t *buffer, int precision)
- {
- //#pragma unused(buffer);
- //TODO: Add code to write the alpha channel into the fourth plane
- int num_channels;
- uint8_t *rgb_row_ptr = data;
- int rgb_row_pitch = pitch;
- PIXEL *color_plane[FRAME_MAX_CHANNELS];
- int color_pitch[FRAME_MAX_CHANNELS];
- int frame_width;
- int frame_height;
- int display_height;
- int row;
- int i;
- uint8_t *r_row_ptr;
- uint8_t *g_row_ptr;
- uint8_t *b_row_ptr;
- uint8_t *a_row_ptr = NULL;
- int r_row_pitch;
- int g_row_pitch;
- int b_row_pitch;
- int a_row_pitch = 0;
- //int shift = 20; // Shift down to form a 10-bit pixel
- int shift = 16 - precision;
- int channel_depth;
- bool alpha_flag;
- //const int max_rgb = USHRT_MAX;
- //TODO: Need to return error codes
- assert(frame != NULL);
- if (! (frame != NULL)) {
- return CODEC_ERROR_INVALID_ARGUMENT;
- }
- assert(frame->format == FRAME_FORMAT_RGB || frame->format == FRAME_FORMAT_RGBA);
- if (! (frame->format == FRAME_FORMAT_RGB || frame->format == FRAME_FORMAT_RGBA)) {
- return CODEC_ERROR_BAD_FRAME;
- }
- alpha_flag = (frame->format == FRAME_FORMAT_RGBA);
- num_channels = (alpha_flag ? 4 : 3);
- // Check that the frame was allocated with enough channels
- assert(frame->num_channels >= num_channels);
- //TODO: Set the alpha flag and number of channels using the values in the frame data structure
- display_height = frame->display_height;
- // Get pointers to the image planes and set the pitch for each plane
- for (i = 0; i < num_channels; i++)
- {
- IMAGE *image = frame->channel[i];
- // Set the pointer to the individual planes and pitch for each channel
- color_plane[i] = image->band[0];
- color_pitch[i] = image->pitch;
- // The first channel establishes the frame dimensions
- if (i == 0) {
- frame_width = image->width;
- frame_height = image->height;
- }
- }
- // This routine does not handle the RG30 format
- channel_depth = pitch * 8 / frame_width;
- assert(channel_depth != 32);
- if (! (channel_depth != 32)) {
- return CODEC_ERROR_BADFORMAT;
- }
- // Set the row pointers for each channel to the correct plane
- r_row_ptr = (uint8_t *)color_plane[1]; r_row_pitch = color_pitch[1];
- g_row_ptr = (uint8_t *)color_plane[0]; g_row_pitch = color_pitch[0];
- b_row_ptr = (uint8_t *)color_plane[2]; b_row_pitch = color_pitch[2];
- if (alpha_flag)
- {
- a_row_ptr = (uint8_t *)color_plane[3]; a_row_pitch = color_pitch[3];
- }
- for (row = 0; row < display_height; row++)
- {
- // Start at the leftmost column
- int column = 0;
- //TODO: Process each row by calling an optimized subroutine
- #if (1 && XMMOPT)
- #endif
- // Pointer into the RGB input row
- PIXEL16U *rgb_ptr = (PIXEL16U *)rgb_row_ptr;
- // Pointers into the output rows for each plane
- PIXEL16U *r_ptr = (PIXEL16U *)r_row_ptr;
- PIXEL16U *g_ptr = (PIXEL16U *)g_row_ptr;
- PIXEL16U *b_ptr = (PIXEL16U *)b_row_ptr;
- PIXEL16U *a_ptr = (PIXEL16U *)a_row_ptr;
- // Process the rest of the column
- for (; column < frame_width; column ++)
- {
- int r, g, b, a;
- // Load the first set of ARGB values
- a = *(rgb_ptr++);
- r = *(rgb_ptr++);
- g = *(rgb_ptr++);
- b = *(rgb_ptr++);
- // Shift the 16-bit pixels to the encoded precision
- *(r_ptr++) = r >> shift;
- *(g_ptr++) = g >> shift;
- *(b_ptr++) = b >> shift;
- if (alpha_flag)
- {
- //*(a_ptr++) = a >> shift;
- a >>= shift;
- // This help preserve the encoding of alpha channel extremes 0 and 1. Alpha encoding curve
- if(a > 0 && a < (255<<4))
- {
- // step function 0 = 0, 0.0001 = 16/255, 0.9999 = 239/256, 1 = 255/256
- a *= 223;
- a += 128;
- a >>= 8;
- a += 16<<4;
- }
- // if (a < 0) a = 0;
- // if (a > YU10_MAX) a = YU10_MAX;
- *(a_ptr++) = a;
- }
- }
- // Advance the input row pointer
- rgb_row_ptr += rgb_row_pitch;
- // Advance the output row pointers
- r_row_ptr += r_row_pitch;
- g_row_ptr += g_row_pitch;
- b_row_ptr += b_row_pitch;
- a_row_ptr += a_row_pitch;
- }
- // Successful conversion
- return CODEC_ERROR_OKAY;
- }
Add Comment
Please, Sign In to add comment