本帖最后由 zhanghuichun 于 2015-11-11 21:05 编辑
采集回来的YUY2数据转换成RGB565格式之后显示出来的效果居然是这样的。
YUY2转RGB565代码:
- static void replace_yuy2_to_rgb565_1(uint8_t *buf, uint32_t len)
- {
- int32_t c, d, e, r, g, b;
-
- len = len >> 2;
- while (len)
- {
- d = buf[1] - 128;
- e = buf[3] - 128;
-
- c = buf[0] - 16;
- r = (298 * c + 409 * e + 128) >> 8;
- if (r < 0)
- r = 0;
- else if (r > 255)
- r = 255;
- g = (298 * c - 100 * d - 208 * e + 128) >> 8;
- if (g < 0)
- g = 0;
- else if (g > 255)
- g = 255;
- b = (298 * c + 516 * d + 128) >> 8;
- if (b < 0)
- b = 0;
- else if (b > 255)
- b = 255;
-
- //r = 255;
- //g = 255;
- //b = 255;
-
- *(uint16_t *)buf = ((r & 0xf8) << 11) | ((g & 0xfc) << 5) | ((b & 0xf8) >> 3);
- buf += 2;
-
- c = buf[0] - 16;
- r = (298 * c + 409 * e + 128) >> 8;
- if (r < 0)
- r = 0;
- else if (r > 255)
- r = 255;
- g = (298 * c - 100 * d - 208 * e + 128) >> 8;
- if (g < 0)
- g = 0;
- else if (g > 255)
- g = 255;
- b = (298 * c + 516 * d + 128) >> 8;
- if (b < 0)
- b = 0;
- else if (b > 255)
- b = 255;
-
- //r = 255;
- //g = 255;
- //b = 255;
-
- *(uint16_t *)buf = ((r & 0xf8) << 11) | ((g & 0xfc) << 5) | ((b & 0xf8) >> 3);
- buf += 2;
-
- len--;
- }
- }
复制代码数据处理代码:
- void uvc_decode_report_recv(void *dev_data, struct vsfusbh_uvc_param_t *param,
- struct vsfusbh_uvc_payload_t *payload)
- {
- uint8_t RGB_Buff[2000];
- uint8_t YUY_Buff[2000];
- uint32_t i=0;
- if (dev_data == NULL)
- return;
-
- if (test_uvc_data == NULL)
- {
- struct vsfusbh_uvc_param_t param = {1, 1, 0,
- VSFUSBH_UVC_VIDEO_FORMAT_YUY2, 30, 640, 480};
- test_uvc_data = dev_data;
- vsfusbh_uvc_set(dev_data, ¶m);
- }
- else if (payload != NULL)
- {
- if (payload->len > 12)
- {
- // just for record frame length
- if (frame_cnt < 300)
- {
- replace_yuy2_to_rgb565_1(&payload->buf[12], payload->len - 12);
- fill_frame_rgb565(&payload->buf[12], payload->len - 12, frame_shift);
- frame_bytes[frame_cnt] += payload->len - 12;
- if (payload->buf[1] & 0x2)
- {
- frame_cnt++;
- frame_shift = 0;
- }
- else
- {
- frame_shift += (payload->len - 12) / 2;
- }
- }
- else
- {
- frame_cnt = 0;
- memset(frame_bytes, 0, sizeof(frame_bytes));
- }
- }
- }
- else
- {
- // get current param
- }
- }
复制代码
此帖出自
小平头技术问答
不是我写的驱动,是le062大神写的,我负责显示部分
有高位对齐和低位对齐
一周热门 更多>