summaryrefslogtreecommitdiff
path: root/src/codec/stb_image
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2024-10-21 19:22:50 -0400
committerAndrew Opalach <andrew@akon.city> 2024-10-21 19:22:50 -0400
commit60b4ebfbf3be78dba9dc7c65ab2bdaa0b218c0c2 (patch)
tree08ff2ce7975f523112e7ad2fe4f797b4fc7db5de /src/codec/stb_image
parent2f9a0945bfeee3296cec3d38d094e4c49f9cb65f (diff)
downloadcamu-60b4ebfbf3be78dba9dc7c65ab2bdaa0b218c0c2.tar.gz
camu-60b4ebfbf3be78dba9dc7c65ab2bdaa0b218c0c2.tar.bz2
camu-60b4ebfbf3be78dba9dc7c65ab2bdaa0b218c0c2.zip
Everything before initial synced list
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/codec/stb_image')
-rw-r--r--src/codec/stb_image/decoder.h3
-rw-r--r--src/codec/stb_image/impl.c75
2 files changed, 45 insertions, 33 deletions
diff --git a/src/codec/stb_image/decoder.h b/src/codec/stb_image/decoder.h
index 7083a09..af50799 100644
--- a/src/codec/stb_image/decoder.h
+++ b/src/codec/stb_image/decoder.h
@@ -4,7 +4,8 @@
struct camu_stbi_decoder {
struct camu_decoder dec;
- void (*callback)(void *, struct camu_frame *);
+ struct camu_codec_stream *stream;
+ void (*callback)(void *, struct camu_codec_frame *);
void (*userdata);
};
diff --git a/src/codec/stb_image/impl.c b/src/codec/stb_image/impl.c
index 6058ff2..98d9e2c 100644
--- a/src/codec/stb_image/impl.c
+++ b/src/codec/stb_image/impl.c
@@ -7,8 +7,10 @@
#define STBI_NO_FAILURE_STRINGS
#define STBI_MALLOC camu_page_alloc
#define STBI_FREE al_free
-#define STBI_REALLOC al_realloc
+#define STBI_REALLOC camu_page_realloc
+AL_UNUSED_FUNCTION_PUSH
#include <stb_image.h>
+AL_UNUSED_FUNCTION_POP
#include "../../cache/entry.h"
@@ -28,27 +30,37 @@ static bool stbi_demuxer_init(struct camu_demuxer *demux, struct cch_handle *han
aki_buffer_ensure_space(&stb->buffer, size);
cch_handle_read(stb->handle, aki_buffer_get_ptr(&stb->buffer, 0), size);
stb->buffer.size = size;
+
s32 w, h, channels;
- stbi_info_from_memory(aki_buffer_get_ptr(&stb->buffer, 0), stb->buffer.size, &w, &h, &channels);
+ u8 *data = aki_buffer_get_ptr(&stb->buffer, 0);
+ if (!stbi_info_from_memory(data, stb->buffer.size, &w, &h, &channels)) {
+ goto err;
+ }
- struct camu_stream stream = { 0 };
- stream.type = CAMU_NORMAL;
+ struct camu_codec_stream stream = { 0 };
+ stream.mode = CAMU_NORMAL;
+ stream.type = CAMU_STREAM_VIDEO;
stream.video.width = w;
stream.video.height = h;
+ stream.video.format = camu_pixel_format_from_channels(channels);
al_array_push(stb->demux.streams, stream);
return true;
+err:
+ return false;
}
-static s32 stbi_demuxer_get_packet(struct camu_demuxer *demux, struct camu_packet *packet)
+static s32 stbi_demuxer_get_packet(struct camu_demuxer *demux, struct camu_codec_packet *packet)
{
struct camu_stbi_demuxer *stb = (struct camu_stbi_demuxer *)demux;
- if (stb->eof) return CAMU_ERR_EOF;
- packet->type = CAMU_NORMAL;
- packet->buffer = &stb->buffer;
- stb->eof = true;
- return CAMU_OK;
+ if (!stb->eof) {
+ packet->mode = CAMU_NORMAL;
+ packet->buffer = &stb->buffer;
+ stb->eof = true;
+ return CAMU_OK;
+ }
+ return CAMU_ERR_EOF;
}
static u64 stbi_demuxer_get_duration(struct camu_demuxer *demux)
@@ -67,44 +79,44 @@ static bool stbi_demuxer_seek(struct camu_demuxer *demux, u64 pos)
static void stbi_demuxer_free(struct camu_demuxer **demux)
{
struct camu_stbi_demuxer *stb = (struct camu_stbi_demuxer *)*demux;
+ aki_buffer_free(&stb->buffer);
+ al_array_free(stb->demux.streams);
al_free(stb);
*demux = NULL;
}
-static bool stbi_decoder_init(struct camu_decoder *dec, struct camu_renderer *renderer, struct camu_stream *stream)
-{
- struct camu_stbi_decoder *stb = (struct camu_stbi_decoder *)dec;
- (void)stb;
- (void)stream;
- (void)renderer;
- return true;
-}
-static void stbi_decoder_set_callback(struct camu_decoder *dec, void (*callback)(void *, struct camu_frame *), void *userdata)
+static bool stbi_decoder_init(struct camu_decoder *dec, struct camu_renderer *renderer, struct camu_codec_stream *stream,
+ void (*callback)(void *, struct camu_codec_frame *), void *userdata)
{
struct camu_stbi_decoder *stb = (struct camu_stbi_decoder *)dec;
+ (void)renderer;
+ stb->stream = stream;
stb->callback = callback;
stb->userdata = userdata;
+ return true;
}
-static s32 stbi_decoder_push(struct camu_decoder *dec, struct camu_packet *packet)
+static s32 stbi_decoder_push(struct camu_decoder *dec, struct camu_codec_packet *packet)
{
- if (!packet) return CAMU_OK;
-
struct camu_stbi_decoder *stb = (struct camu_stbi_decoder *)dec;
+ if (!packet) return CAMU_OK;
s32 w, h, channels;
- u8 *pixels = stbi_load_from_memory(aki_buffer_get_ptr(packet->buffer, 0),
- packet->buffer->size, &w, &h, &channels, 4);
+ u8 *data = aki_buffer_get_ptr(packet->buffer, 0);
+ u8 *pixels = stbi_load_from_memory(data, packet->buffer->size, &w, &h, &channels, 0);
+ if (!pixels) return CAMU_ERR_ERROR;
+ al_assert(w == stb->stream->video.width && h == stb->stream->video.height);
- struct camu_frame *frame = al_alloc_object(struct camu_frame);
- frame->type = CAMU_NORMAL;
+ struct camu_codec_frame *frame = al_alloc_object(struct camu_codec_frame);
+ frame->mode = CAMU_NORMAL;
+ frame->flags = 0;
frame->data = pixels;
- frame->width = stb->dec.stream->video.width;
- frame->height = stb->dec.stream->video.height;
- frame->fmt = CAMU_PIXEL_FMT_RGBA;
+ frame->video.width = w;
+ frame->video.height = h;
+ frame->format = camu_pixel_format_from_channels(channels);
+ al_assert(frame->format == stb->stream->video.format);
frame->pts = 0.0;
- frame->flags = 0;
stb->callback(stb->userdata, frame);
@@ -132,7 +144,7 @@ static void stbi_decoder_free(struct camu_decoder **dec)
struct camu_demuxer *camu_stbi_demuxer_create(void)
{
struct camu_stbi_demuxer *stb = al_alloc_object(struct camu_stbi_demuxer);
- stb->demux.type = CAMU_NORMAL;
+ stb->demux.mode = CAMU_NORMAL;
al_array_init(stb->demux.streams);
stb->demux.init = stbi_demuxer_init;
stb->demux.get_packet = stbi_demuxer_get_packet;
@@ -146,7 +158,6 @@ struct camu_decoder *camu_stbi_decoder_create(void)
{
struct camu_stbi_decoder *stb = al_alloc_object(struct camu_stbi_decoder);
stb->dec.init = stbi_decoder_init;
- stb->dec.set_callback = stbi_decoder_set_callback;
stb->dec.push = stbi_decoder_push;
stb->dec.process = stbi_decoder_process;
stb->dec.flush = stbi_decoder_flush;