The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

a/util: Add MJPEG -> L8 conversion

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2482>

authored by

Beyley Cardellio and committed by
Marge Bot
15fd4a2d 6f824b5f

+26 -45
+26 -45
src/xrt/auxiliary/util/u_sink_converter.c
··· 309 309 } 310 310 311 311 static bool 312 - from_MJPEG_to_R8G8B8(struct xrt_frame *dst_frame, size_t size, const uint8_t *data) 312 + from_MJPEG_to_frame(struct xrt_frame *dst_frame, size_t size, const uint8_t *data) 313 313 { 314 314 SINK_TRACE_MARKER(); 315 315 ··· 332 332 return false; 333 333 } 334 334 335 - cinfo.out_color_space = JCS_RGB; 336 - jpeg_start_decompress(&cinfo); 337 - 338 - uint8_t *moving_ptr = dst_frame->data; 339 - 340 - uint32_t scanlines_read = 0; 341 - while (scanlines_read < cinfo.image_height) { 342 - int read_count = jpeg_read_scanlines(&cinfo, &moving_ptr, 16); 343 - moving_ptr += read_count * dst_frame->stride; 344 - scanlines_read += read_count; 345 - } 346 - 347 - jpeg_finish_decompress(&cinfo); 348 - jpeg_destroy_decompress(&cinfo); 349 - 350 - return true; 351 - } 352 - 353 - static bool 354 - from_MJPEG_to_YUV888(struct xrt_frame *dst_frame, size_t size, const uint8_t *data) 355 - { 356 - SINK_TRACE_MARKER(); 335 + switch (dst_frame->format) { 336 + case XRT_FORMAT_L8: cinfo.out_color_space = JCS_GRAYSCALE; break; 337 + case XRT_FORMAT_R8G8B8: cinfo.out_color_space = JCS_RGB; break; 338 + case XRT_FORMAT_YUV888: cinfo.out_color_space = JCS_YCbCr; break; 339 + default: { 340 + assert(!"unsupported format"); 357 341 358 - if (!check_header(size, data)) { 342 + jpeg_destroy_decompress(&cinfo); 359 343 return false; 360 344 } 361 - 362 - struct jpeg_decompress_struct cinfo = {0}; 363 - struct jpeg_error_mgr jerr = {0}; 364 - 365 - cinfo.err = jpeg_std_error(&jerr); 366 - jerr.trace_level = 0; 367 - 368 - jpeg_create_decompress(&cinfo); 369 - jpeg_mem_src(&cinfo, data, size); 370 - 371 - int ret = jpeg_read_header(&cinfo, TRUE); 372 - if (ret != JPEG_HEADER_OK) { 373 - jpeg_destroy_decompress(&cinfo); 374 - return false; 375 345 } 376 346 377 - cinfo.out_color_space = JCS_YCbCr; 378 347 jpeg_start_decompress(&cinfo); 379 348 380 349 uint8_t *moving_ptr = dst_frame->data; ··· 524 493 } 525 494 from_YUYV422_to_L8(converted, xf->width, xf->height, xf->stride, xf->data); 526 495 break; 496 + #ifdef XRT_HAVE_JPEG 497 + case XRT_FORMAT_MJPEG: 498 + if (!create_frame_with_format(xf, XRT_FORMAT_L8, &converted)) { 499 + return; 500 + } 501 + if (!from_MJPEG_to_frame(converted, xf->size, xf->data)) { 502 + // Make sure to free frame when we fail to decode. 503 + xrt_frame_reference(&converted, NULL); 504 + return; 505 + } 506 + break; 507 + #endif 527 508 default: U_LOG_E("Cannot convert from '%s' to L8!", u_format_str(xf->format)); return; 528 509 } 529 510 ··· 582 563 if (!create_frame_with_format(xf, XRT_FORMAT_R8G8B8, &converted)) { 583 564 return; 584 565 } 585 - if (!from_MJPEG_to_R8G8B8(converted, xf->size, xf->data)) { 566 + if (!from_MJPEG_to_frame(converted, xf->size, xf->data)) { 586 567 // Make sure to free frame when we fail to decode. 587 568 xrt_frame_reference(&converted, NULL); 588 569 return; ··· 650 631 if (!create_frame_with_format(xf, XRT_FORMAT_R8G8B8, &converted)) { 651 632 return; 652 633 } 653 - if (!from_MJPEG_to_R8G8B8(converted, xf->size, xf->data)) { 634 + if (!from_MJPEG_to_frame(converted, xf->size, xf->data)) { 654 635 // Make sure to free frame when we fail to decode. 655 636 xrt_frame_reference(&converted, NULL); 656 637 return; ··· 714 695 if (!create_frame_with_format(xf, XRT_FORMAT_R8G8B8, &converted)) { 715 696 return; 716 697 } 717 - if (!from_MJPEG_to_R8G8B8(converted, xf->size, xf->data)) { 698 + if (!from_MJPEG_to_frame(converted, xf->size, xf->data)) { 718 699 // Make sure to free frame when we fail to decode. 719 700 xrt_frame_reference(&converted, NULL); 720 701 return; ··· 750 731 if (!create_frame_with_format(xf, XRT_FORMAT_YUV888, &converted)) { 751 732 return; 752 733 } 753 - if (!from_MJPEG_to_YUV888(converted, xf->size, xf->data)) { 734 + if (!from_MJPEG_to_frame(converted, xf->size, xf->data)) { 754 735 return; 755 736 } 756 737 break; ··· 785 766 if (!create_frame_with_format(xf, XRT_FORMAT_YUV888, &converted)) { 786 767 return; 787 768 } 788 - if (!from_MJPEG_to_YUV888(converted, xf->size, xf->data)) { 769 + if (!from_MJPEG_to_frame(converted, xf->size, xf->data)) { 789 770 return; 790 771 } 791 772 break; ··· 821 802 if (!create_frame_with_format(xf, XRT_FORMAT_YUV888, &converted)) { 822 803 return; 823 804 } 824 - if (!from_MJPEG_to_YUV888(converted, xf->size, xf->data)) { 805 + if (!from_MJPEG_to_frame(converted, xf->size, xf->data)) { 825 806 return; 826 807 } 827 808 break;