Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2008-11-13 00:16:53 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2008-11-13 00:16:53 +0300
commitbdfe7d89e2f1292644577972c716931b4ce3c6c3 (patch)
treed00eb50b749cb001e2b08272c91791e66740b05d /extern/libredcode/format.c
parent78a1c27c4a6abe0ed31ca93ad21910f3df04da56 (diff)
parent7e4db234cee71ead34ee81a12e27da4bd548eb4b (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/format.c')
-rw-r--r--extern/libredcode/format.c218
1 files changed, 218 insertions, 0 deletions
diff --git a/extern/libredcode/format.c b/extern/libredcode/format.c
new file mode 100644
index 00000000000..4677c49b8a5
--- /dev/null
+++ b/extern/libredcode/format.c
@@ -0,0 +1,218 @@
+#ifdef _WIN32
+#include <Winsock2.h>
+#else
+#include <netinet/in.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "format.h"
+
+struct red_reob {
+ unsigned long len;
+ char head[4];
+
+ unsigned long rdvo;
+ unsigned long rdvs;
+ unsigned long rdao;
+ unsigned long rdas;
+
+ unsigned long unknown1;
+ unsigned long unknown2;
+ unsigned long totlen;
+
+ unsigned long avgv;
+ unsigned long avgs;
+
+ unsigned long unknown3;
+ unsigned long unknown4;
+ unsigned long unknown5;
+};
+
+struct redcode_handle {
+ FILE * fp;
+ struct red_reob * reob;
+ unsigned long * rdvo;
+ unsigned long * rdvs;
+ unsigned long * rdao;
+ unsigned long * rdas;
+ long cfra;
+};
+
+
+static unsigned char* read_packet(FILE * fp, char * expect)
+{
+ unsigned long len;
+ char head[5];
+ unsigned char * rv;
+
+ fread(&len, 4, 1, fp);
+ fread(&head, 4, 1, fp);
+
+ head[4] = 0;
+
+ len = ntohl(len);
+
+ if (strcmp(expect, head) != 0) {
+ fprintf(stderr, "Read: %s, expect: %s\n", head, expect);
+ return NULL;
+ }
+
+ rv = (unsigned char*) malloc(len + 8);
+
+ memcpy(rv, &len, 4);
+ memcpy(rv + 4, &head, 4);
+
+ fread(rv + 8, len, 1, fp);
+
+ return rv;
+}
+
+static unsigned long * read_index_packet(FILE * fp, char * expect)
+{
+ unsigned long * rv = (unsigned long*) read_packet(fp, expect);
+ int i;
+
+ if (!rv) {
+ return NULL;
+ }
+
+ for (i = 2; i < rv[0]/4; i++) {
+ rv[i] = ntohl(rv[i]);
+ }
+ return rv;
+}
+
+static struct red_reob * read_reob(FILE * fp)
+{
+ fseek(fp, -0x38, SEEK_END);
+
+ return (struct red_reob *) read_index_packet(fp, "REOB");
+}
+
+static unsigned long * read_index(FILE * fp, unsigned long i, char * expect)
+{
+ fseek(fp, i, SEEK_SET);
+
+ return (unsigned long*) read_index_packet(fp, expect);
+}
+
+static unsigned char * read_data(FILE * fp, unsigned long i, char * expect)
+{
+ fseek(fp, i, SEEK_SET);
+
+ return read_packet(fp, expect);
+}
+
+struct redcode_handle * redcode_open(const char * fname)
+{
+ struct redcode_handle * rv = NULL;
+ struct red_reob * reob = NULL;
+
+ FILE * fp = fopen(fname, "rb");
+
+ if (!fp) {
+ return NULL;
+ }
+
+ reob = read_reob(fp);
+ if (!reob) {
+ fclose(fp);
+ return NULL;
+ }
+
+ rv = (struct redcode_handle*) calloc(1, sizeof(struct redcode_handle));
+
+ rv->fp = fp;
+ rv->reob = reob;
+ rv->rdvo = read_index(fp, reob->rdvo, "RDVO");
+ rv->rdvs = read_index(fp, reob->rdvs, "RDVS");
+ rv->rdao = read_index(fp, reob->rdao, "RDAO");
+ rv->rdas = read_index(fp, reob->rdas, "RDAS");
+
+ if (!rv->rdvo || !rv->rdvs || !rv->rdao || !rv->rdas) {
+ redcode_close(rv);
+ return NULL;
+ }
+
+ return rv;
+}
+
+void redcode_close(struct redcode_handle * handle)
+{
+ if (handle->reob) {
+ free(handle->reob);
+ }
+ if (handle->rdvo) {
+ free(handle->rdvo);
+ }
+ if (handle->rdvs) {
+ free(handle->rdvs);
+ }
+ if (handle->rdao) {
+ free(handle->rdao);
+ }
+ if (handle->rdas) {
+ free(handle->rdas);
+ }
+ fclose(handle->fp);
+ free(handle);
+}
+
+long redcode_get_length(struct redcode_handle * handle)
+{
+ return handle->rdvo[0]/4;
+}
+
+struct redcode_frame * redcode_read_video_frame(
+ struct redcode_handle * handle, long frame)
+{
+ struct redcode_frame * rv;
+ unsigned char * data;
+
+ if (frame > handle->rdvo[0]/4 || handle->rdvo[frame + 2] == 0) {
+ return NULL;
+ }
+ data = read_data(handle->fp, handle->rdvo[frame + 2], "REDV");
+ if (!data) {
+ return NULL;
+ }
+
+ rv = (struct redcode_frame*) calloc(1, sizeof(struct redcode_frame));
+
+ rv->offset = 12+8;
+ rv->length = *(unsigned long*)data - rv->offset;
+ rv->data = data;
+
+ return rv;
+}
+
+struct redcode_frame * redcode_read_audio_frame(
+ struct redcode_handle * handle, long frame)
+{
+ struct redcode_frame * rv;
+ unsigned char * data;
+
+ if (frame > handle->rdao[0]/4 || handle->rdao[frame + 2] == 0) {
+ return NULL;
+ }
+ data = read_data(handle->fp, handle->rdao[frame+2], "REDA");
+ if (!data) {
+ return NULL;
+ }
+
+ rv = (struct redcode_frame*) calloc(1, sizeof(struct redcode_frame));
+
+ rv->offset = 24+8;
+ rv->length = *(unsigned long*)data - rv->offset;
+ rv->data = data;
+
+ return rv;
+}
+
+void redcode_free_frame(struct redcode_frame * frame)
+{
+ free(frame->data);
+ free(frame);
+}