summaryrefslogtreecommitdiff
path: root/src/apps/qcam/assets/feathericons/codepen.svg
blob: ab2a815aa1cf392e2ccc8348ed7a960ecbac9db8 (plain)
1
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-codepen"><polygon points="12 2 22 8.5 22 15.5 12 22 2 15.5 2 8.5 12 2"></polygon><line x1="12" y1="22" x2="12" y2="15.5"></line><polyline points="22 8.5 12 15.5 2 8.5"></polyline><polyline points="2 15.5 12 8.5 22 15.5"></polyline><line x1="12" y1="2" x2="12" y2="8.5"></line></svg>
re_mjpg.cpp - SDL Texture MJPG */ #include "sdl_texture_mjpg.h" #include <iostream> #include <setjmp.h> #include <stdio.h> #include <jpeglib.h> using namespace libcamera; struct JpegErrorManager : public jpeg_error_mgr { JpegErrorManager() { jpeg_std_error(this); error_exit = errorExit; output_message = outputMessage; } static void errorExit(j_common_ptr cinfo) { JpegErrorManager *self = static_cast<JpegErrorManager *>(cinfo->err); longjmp(self->escape_, 1); } static void outputMessage([[maybe_unused]] j_common_ptr cinfo) { } jmp_buf escape_; }; SDLTextureMJPG::SDLTextureMJPG(const SDL_Rect &rect) : SDLTexture(rect, SDL_PIXELFORMAT_RGB24, rect.w * 3), rgb_(std::make_unique<unsigned char[]>(stride_ * rect.h)) { } int SDLTextureMJPG::decompress(Span<const uint8_t> data) { struct jpeg_decompress_struct cinfo; JpegErrorManager errorManager; if (setjmp(errorManager.escape_)) { /* libjpeg found an error */ jpeg_destroy_decompress(&cinfo); std::cerr << "JPEG decompression error" << std::endl; return -EINVAL; } cinfo.err = &errorManager; jpeg_create_decompress(&cinfo); jpeg_mem_src(&cinfo, data.data(), data.size()); jpeg_read_header(&cinfo, TRUE); jpeg_start_decompress(&cinfo); for (int i = 0; cinfo.output_scanline < cinfo.output_height; ++i) { JSAMPROW rowptr = rgb_.get() + i * stride_;