aboutsummaryrefslogtreecommitdiff
path: root/Src/jpeg/mp4_jpeg_decoder.cpp
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/jpeg/mp4_jpeg_decoder.cpp
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/jpeg/mp4_jpeg_decoder.cpp')
-rw-r--r--Src/jpeg/mp4_jpeg_decoder.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/Src/jpeg/mp4_jpeg_decoder.cpp b/Src/jpeg/mp4_jpeg_decoder.cpp
new file mode 100644
index 00000000..861d8a89
--- /dev/null
+++ b/Src/jpeg/mp4_jpeg_decoder.cpp
@@ -0,0 +1,91 @@
+#include "mp4_jpeg_decoder.h"
+#include "api__jpeg.h"
+#include <api/service/waservicefactory.h>
+
+MP4JPEGDecoder::MP4JPEGDecoder()
+{
+ jpegLoader=0;
+ width=0;
+ height=0;
+ decoded_image = 0;
+}
+
+int MP4JPEGDecoder::Open(MP4FileHandle mp4_file, MP4TrackId mp4_track)
+{
+ // load JPEG loader
+ jpegLoader = new JpgLoad;
+
+ if (jpegLoader)
+ return MP4_VIDEO_SUCCESS;
+ else
+ return MP4_VIDEO_FAILURE;
+
+}
+
+void MP4JPEGDecoder::Close()
+{
+ delete jpegLoader;
+ delete this;
+}
+
+int MP4JPEGDecoder::GetOutputFormat(int *x, int *y, int *color_format, double *aspect_ratio)
+{
+ if (!height || !width)
+ return MP4_VIDEO_FAILURE;
+
+ *x = width;
+ *y = height;
+ *color_format = '23GR'; // RGB32
+ return MP4_VIDEO_SUCCESS;
+}
+
+int MP4JPEGDecoder::DecodeSample(const void *inputBuffer, size_t inputBufferBytes, MP4Timestamp timestamp)
+{
+ bool change_in_size=false;
+ if (decoded_image)
+ WASABI_API_MEMMGR->sysFree(decoded_image);
+ int decode_width, decode_height;
+ decoded_image = jpegLoader->loadImage(inputBuffer, (int)inputBufferBytes, &decode_width, &decode_height);
+ if (!decoded_image)
+ return MP4_VIDEO_FAILURE;
+ if (width && decode_width != width // if we have a different width from last time
+ || height && decode_height != height)
+ change_in_size = true;
+
+ width = decode_width;
+ height = decode_height;
+ return change_in_size?MP4_VIDEO_OUTPUT_FORMAT_CHANGED:MP4_VIDEO_SUCCESS;
+}
+
+int MP4JPEGDecoder::CanHandleCodec(const char *codecName)
+{
+ return !strcmp(codecName, "jpeg");
+}
+
+int MP4JPEGDecoder::GetPicture(void **data, void **decoder_data, MP4Timestamp *timestamp)
+{
+ if (!decoded_image)
+ return MP4_VIDEO_FAILURE;
+
+ *data = decoded_image;
+ *decoder_data = 0;
+ decoded_image = 0; // wipe our hands clean of it so we don't double free
+ return MP4_VIDEO_SUCCESS;
+}
+
+void MP4JPEGDecoder::FreePicture(void *data, void *decoder_data)
+{
+ WASABI_API_MEMMGR->sysFree(data);
+}
+
+#define CBCLASS MP4JPEGDecoder
+START_DISPATCH;
+CB(MPEG4_VIDEO_OPEN, Open)
+CB(MPEG4_VIDEO_GETOUTPUTFORMAT, GetOutputFormat)
+CB(MPEG4_VIDEO_DECODE, DecodeSample)
+CB(MPEG4_VIDEO_HANDLES_CODEC, CanHandleCodec)
+CB(MPEG4_VIDEO_GET_PICTURE, GetPicture)
+VCB(MPEG4_VIDEO_FREE_PICTURE, FreePicture)
+END_DISPATCH;
+#undef CBCLASS
+