diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-13 00:16:53 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-13 00:16:53 +0300 |
commit | bdfe7d89e2f1292644577972c716931b4ce3c6c3 (patch) | |
tree | d00eb50b749cb001e2b08272c91791e66740b05d /extern/libredcode/codec.c | |
parent | 78a1c27c4a6abe0ed31ca93ad21910f3df04da56 (diff) | |
parent | 7e4db234cee71ead34ee81a12e27da4bd548eb4b (diff) |
Merge of trunk into blender 2.5:
svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r12987:17416
Issues:
* GHOST/X11 had conflicting changes. Some code was added in 2.5, which was
later added in trunk also, but reverted partially, specifically revision
16683. I have left out this reversion in the 2.5 branch since I think it is
needed there.
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16683
* Scons had various conflicting changes, I decided to go with trunk version
for everything except priorities and some library renaming.
* In creator.c, there were various fixes and fixes for fixes related to the -w
-W and -p options. In 2.5 -w and -W is not coded yet, and -p is done
differently. Since this is changed so much, and I don't think those fixes
would be needed in 2.5, I've left them out.
* Also in creator.c: there was code for a python bugfix where the screen was not
initialized when running with -P. The code that initializes the screen there
I had to disable, that can't work in 2.5 anymore but left it commented as a
reminder.
Further I had to disable some new function calls. using src/ and python/, as
was done already in this branch, disabled function calls:
* bpath.c: error reporting
* BME_conversions.c: editmesh conversion functions.
* SHD_dynamic: disabled almost completely, there is no python/.
* KX_PythonInit.cpp and Ketsji/ build files: Mathutils is not there, disabled.
* text.c: clipboard copy call.
* object.c: OB_SUPPORT_MATERIAL.
* DerivedMesh.c and subsurf_ccg, stipple_quarttone.
Still to be done:
* Go over files and functions that were moved to a different location but could
still use changes that were done in trunk.
Diffstat (limited to 'extern/libredcode/codec.c')
-rw-r--r-- | extern/libredcode/codec.c | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/extern/libredcode/codec.c b/extern/libredcode/codec.c new file mode 100644 index 00000000000..e0b79119e80 --- /dev/null +++ b/extern/libredcode/codec.c @@ -0,0 +1,141 @@ +#include "codec.h" +#include "format.h" +#include "debayer.h" + +#include <openjpeg.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +static void error_callback(const char *msg, void *client_data) { + FILE *stream = (FILE*)client_data; + fprintf(stream, "[R3D ERR] %s", msg); +} + +static void warning_callback(const char *msg, void *client_data) { + FILE *stream = (FILE*)client_data; + fprintf(stream, "[R3D WARN] %s", msg); +} + +static void info_callback(const char *msg, void *client_data) { + (void)client_data; + fprintf(stdout, "[R3D INFO] %s", msg); +} + +#define J2K_CFMT 0 +#define JP2_CFMT 1 +#define JPT_CFMT 2 + +struct redcode_frame_raw * redcode_decode_video_raw( + struct redcode_frame * frame, int scale) +{ + struct redcode_frame_raw * rv = NULL; + opj_dparameters_t parameters; /* decompression parameters */ + opj_event_mgr_t event_mgr; /* event manager */ + opj_image_t *image = NULL; + opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */ + opj_cio_t *cio = NULL; + + memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); + event_mgr.error_handler = error_callback; + event_mgr.warning_handler = warning_callback; + event_mgr.info_handler = info_callback; + + opj_set_default_decoder_parameters(¶meters); + + parameters.decod_format = JP2_CFMT; + + if (scale == 2) { + parameters.cp_reduce = 1; + } else if (scale == 4) { + parameters.cp_reduce = 2; + } else if (scale == 8) { + parameters.cp_reduce = 3; + } + + /* JPEG 2000 compressed image data */ + + /* get a decoder handle */ + dinfo = opj_create_decompress(CODEC_JP2); + + /* catch events using our callbacks and give a local context */ + opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); + + /* setup the decoder decoding parameters using the current image + and user parameters */ + opj_setup_decoder(dinfo, ¶meters); + + /* open a byte stream */ + cio = opj_cio_open((opj_common_ptr)dinfo, + frame->data + frame->offset, frame->length); + + image = opj_decode(dinfo, cio); + + if(!image) { + fprintf(stderr, + "ERROR -> j2k_to_image: failed to decode image!\n"); + opj_destroy_decompress(dinfo); + opj_cio_close(cio); + return 0; + } + + /* close the byte stream */ + opj_cio_close(cio); + + /* free remaining structures */ + if(dinfo) { + opj_destroy_decompress(dinfo); + } + + if((image->numcomps * image->x1 * image->y1) == 0) { + opj_image_destroy(image); + return 0; + } + + rv = (struct redcode_frame_raw *) calloc( + 1, sizeof(struct redcode_frame_raw)); + + rv->data = image; + rv->width = image->comps[0].w; + rv->height = image->comps[0].h; + + return rv; +} + +int redcode_decode_video_float(struct redcode_frame_raw * frame, + float * out, int scale) +{ + int* planes[4]; + int i; + opj_image_t *image = (opj_image_t*) frame->data; + + if (image->numcomps != 4) { + fprintf(stderr, "R3D: need 4 planes, but got: %d\n", + image->numcomps); + return 0; + } + + for (i = 0; i < 4; i++) { + planes[i] = image->comps[i].data; + } + + if (scale == 1) { + redcode_ycbcr2rgb_fullscale( + planes, frame->width, frame->height, out); + } else if (scale == 2) { + redcode_ycbcr2rgb_halfscale( + planes, frame->width, frame->height, out); + } else if (scale == 4) { + redcode_ycbcr2rgb_quarterscale( + planes, frame->width, frame->height, out); + } + + opj_image_destroy(image); + + free(frame); + + return 1; +} + + + |