summaryrefslogtreecommitdiff
path: root/src/cam/sdl_texture_mjpg.cpp
blob: 69e99ad3521929892c4fbcaea6cb63ec210c7a96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2022, Ideas on Board Oy
 *
 * sdl_texture_mjpg.cpp - SDL Texture MJPG
 */

#include "sdl_texture_mjpg.h"

#include <SDL2/SDL_image.h>

using namespace libcamera;

SDLTextureMJPG::SDLTextureMJPG(const SDL_Rect &rect)
	: SDLTexture(rect, SDL_PIXELFORMAT_RGB24, 0)
{
}

void SDLTextureMJPG::update(const Span<uint8_t> &data)
{
	SDL_RWops *bufferStream = SDL_RWFromMem(data.data(), data.size());
	SDL_Surface *frame = IMG_Load_RW(bufferStream, 0);
	SDL_UpdateTexture(ptr_, nullptr, frame->pixels, frame->pitch);
	SDL_FreeSurface(frame);
}