svn merge ^/trunk/blender -r46380:HEAD
authorOve Murberg Henriksen <sorayasilvermoon@hotmail.com>
Tue, 8 May 2012 00:22:02 +0000 (00:22 +0000)
committerOve Murberg Henriksen <sorayasilvermoon@hotmail.com>
Tue, 8 May 2012 00:22:02 +0000 (00:22 +0000)
29 files changed:
intern/cycles/blender/blender_shader.cpp
intern/cycles/kernel/CMakeLists.txt
intern/cycles/kernel/svm/svm.h
intern/cycles/kernel/svm/svm_light_path.h
intern/cycles/kernel/svm/svm_mapping.h
intern/cycles/kernel/svm/svm_types.h
intern/cycles/render/nodes.cpp
intern/cycles/render/nodes.h
source/blender/avi/intern/avi.c
source/blender/avi/intern/avirgb.c
source/blender/avi/intern/codecs.c
source/blender/avi/intern/endian.c
source/blender/avi/intern/mjpeg.c
source/blender/avi/intern/options.c
source/blender/avi/intern/rgb32.c
source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.c
source/blender/collada/ExportSettings.h
source/blender/collada/GeometryExporter.cpp
source/blender/collada/GeometryExporter.h
source/blender/collada/collada.cpp
source/blender/collada/collada.h
source/blender/editors/mesh/editmesh_tools.c
source/blender/makesrna/intern/rna_nodetree_types.h
source/blender/makesrna/intern/rna_scene_api.c
source/blender/modifiers/intern/MOD_solidify.c
source/blender/nodes/CMakeLists.txt
source/blender/nodes/NOD_shader.h
source/blender/windowmanager/intern/wm_operators.c

index 52d97753db3962e11b98885e1703725143331b9e..b33de789631101e64be4d4fe83938d421448ffa7 100644 (file)
@@ -97,6 +97,13 @@ static void get_tex_mapping(TextureMapping *mapping, BL::ShaderNodeMapping b_map
        mapping->translation = get_float3(b_mapping.translation());
        mapping->rotation = get_float3(b_mapping.rotation());
        mapping->scale = get_float3(b_mapping.scale());
+
+       mapping->use_minmax = b_mapping.use_min() || b_mapping.use_max();
+
+       if(b_mapping.use_min())
+               mapping->min = get_float3(b_mapping.min());
+       if(b_mapping.use_max())
+               mapping->max = get_float3(b_mapping.max());
 }
 
 static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::ShaderNode b_node)
@@ -323,6 +330,10 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Shader
                        node = new LightPathNode();
                        break;
                }
+               case BL::ShaderNode::type_LIGHT_FALLOFF: {
+                       node = new LightFalloffNode();
+                       break;
+               }
                case BL::ShaderNode::type_TEX_IMAGE: {
                        BL::ShaderNodeTexImage b_image_node(b_node);
                        BL::Image b_image(b_image_node.image());
index e9820010b6360e2fa6f1af8286fbe9b9b144015c..d165716aacaabed34ebdc3745ea8d1ff30c81479 100644 (file)
@@ -33,6 +33,7 @@ set(SRC_HEADERS
        kernel_object.h
        kernel_passes.h
        kernel_path.h
+       kernel_projection.h
        kernel_qbvh.h
        kernel_random.h
        kernel_shader.h
index 50181c0cf2c29c4341aaa4d7d27b9a193b62bd91..5f4d7bbd0c4496559846d0e1d4dd8111ccb58fda 100644 (file)
@@ -326,6 +326,9 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT
                        case NODE_MAPPING:
                                svm_node_mapping(kg, sd, stack, node.y, node.z, &offset);
                                break;
+                       case NODE_MIN_MAX:
+                               svm_node_min_max(kg, sd, stack, node.y, node.z, &offset);
+                               break;
                        case NODE_TEX_COORD:
                                svm_node_tex_coord(kg, sd, stack, node.y, node.z);
                                break;
@@ -344,6 +347,9 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT
                        case NODE_RGB_CURVES:
                                svm_node_rgb_curves(kg, sd, stack, node, &offset);
                                break;
+                       case NODE_LIGHT_FALLOFF:
+                               svm_node_light_falloff(sd, stack, node);
+                               break;
                        case NODE_END:
                        default:
 #ifndef __MULTI_CLOSURE__
index ebbcb5be61ff6953d6e6d57a380e60668eecd6fe..b29dc9cbd45c436e8e3c287b40386a1e623fc875 100644 (file)
@@ -39,5 +39,32 @@ __device void svm_node_light_path(ShaderData *sd, float *stack, uint type, uint
        stack_store_float(stack, out_offset, info);
 }
 
+/* Light Falloff Node */
+
+__device void svm_node_light_falloff(ShaderData *sd, float *stack, uint4 node)
+{
+       uint strength_offset, out_offset, smooth_offset;
+
+       decode_node_uchar4(node.z, &strength_offset, &smooth_offset, &out_offset, NULL);
+
+       float strength = stack_load_float(stack, strength_offset);
+       uint type = node.y;
+
+       switch(type) {
+               case NODE_LIGHT_FALLOFF_QUADRATIC: break;
+               case NODE_LIGHT_FALLOFF_LINEAR: strength *= sd->ray_length; break;
+               case NODE_LIGHT_FALLOFF_CONSTANT: strength *= sd->ray_length*sd->ray_length; break;
+       }
+
+       float smooth = stack_load_float(stack, smooth_offset);
+
+       if(smooth > 0.0f) {
+               float squared = sd->ray_length*sd->ray_length;
+               strength *= squared/(smooth + squared);
+       }
+
+       stack_store_float(stack, out_offset, strength);
+}
+
 CCL_NAMESPACE_END
 
index 6dc74aece085f35d970c4ab83b6844b9ee6d7c7f..96645ac97dbc7def0e17bbccbb2d6982f2a00a6d 100644 (file)
@@ -34,5 +34,16 @@ __device void svm_node_mapping(KernelGlobals *kg, ShaderData *sd, float *stack,
        stack_store_float3(stack, out_offset, r);
 }
 
+__device void svm_node_min_max(KernelGlobals *kg, ShaderData *sd, float *stack, uint vec_offset, uint out_offset, int *offset)
+{
+       float3 v = stack_load_float3(stack, vec_offset);
+
+       float3 mn = float4_to_float3(read_node_float(kg, offset));
+       float3 mx = float4_to_float3(read_node_float(kg, offset));
+
+       float3 r = min(max(mn, v), mx);
+       stack_store_float3(stack, out_offset, r);
+}
+
 CCL_NAMESPACE_END
 
index 8037c3964a97ba194fbc7122aa65311de18c5697..867709f29e09b190b2a586a23284e3aff935b37b 100644 (file)
@@ -90,7 +90,9 @@ typedef enum NodeType {
        NODE_TEX_CHECKER = 5700,
        NODE_BRIGHTCONTRAST = 5800,
        NODE_RGB_RAMP = 5900,
-       NODE_RGB_CURVES = 6000
+       NODE_RGB_CURVES = 6000,
+       NODE_MIN_MAX = 6100,
+       NODE_LIGHT_FALLOFF = 6200
 } NodeType;
 
 typedef enum NodeAttributeType {
@@ -119,6 +121,12 @@ typedef enum NodeLightPath {
        NODE_LP_ray_length
 } NodeLightPath;
 
+typedef enum NodeLightFalloff {
+       NODE_LIGHT_FALLOFF_QUADRATIC,
+       NODE_LIGHT_FALLOFF_LINEAR,
+       NODE_LIGHT_FALLOFF_CONSTANT
+} NodeLightFalloff;
+
 typedef enum NodeTexCoord {
        NODE_TEXCO_NORMAL,
        NODE_TEXCO_OBJECT,
index fd26c552f21ce468aeff567a47f8a6d7912aa72a..afc590984328978d22751bb4cb09d6cefd741df3 100644 (file)
@@ -33,6 +33,11 @@ TextureMapping::TextureMapping()
        rotation = make_float3(0.0f, 0.0f, 0.0f);
        scale = make_float3(1.0f, 1.0f, 1.0f);
 
+       min = make_float3(-FLT_MAX, -FLT_MAX, -FLT_MAX);
+       max = make_float3(FLT_MAX, FLT_MAX, FLT_MAX);
+
+       use_minmax = false;
+
        x_mapping = X;
        y_mapping = Y;
        z_mapping = Z;
@@ -69,6 +74,8 @@ bool TextureMapping::skip()
        
        if(x_mapping != X || y_mapping != Y || z_mapping != Z)
                return false;
+       if(use_minmax)
+               return false;
        
        return true;
 }
@@ -85,6 +92,12 @@ void TextureMapping::compile(SVMCompiler& compiler, int offset_in, int offset_ou
        compiler.add_node(tfm.y);
        compiler.add_node(tfm.z);
        compiler.add_node(tfm.w);
+
+       if(use_minmax) {
+               compiler.add_node(NODE_MIN_MAX, offset_out, offset_out);
+               compiler.add_node(float3_to_float4(min));
+               compiler.add_node(float3_to_float4(max));
+       }
 }
 
 /* Image Texture */
@@ -1686,6 +1699,54 @@ void LightPathNode::compile(OSLCompiler& compiler)
        compiler.add(this, "node_light_path");
 }
 
+/* Light Path */
+
+LightFalloffNode::LightFalloffNode()
+: ShaderNode("light_path")
+{
+       add_input("Strength", SHADER_SOCKET_FLOAT, 100.0f);
+       add_input("Smooth", SHADER_SOCKET_FLOAT, 0.0f);
+       add_output("Quadratic", SHADER_SOCKET_FLOAT);
+       add_output("Linear", SHADER_SOCKET_FLOAT);
+       add_output("Constant", SHADER_SOCKET_FLOAT);
+}
+
+void LightFalloffNode::compile(SVMCompiler& compiler)
+{
+       ShaderInput *strength_in = input("Strength");
+       ShaderInput *smooth_in = input("Smooth");
+
+       compiler.stack_assign(strength_in);
+       compiler.stack_assign(smooth_in);
+
+       ShaderOutput *out = output("Quadratic");
+       if(!out->links.empty()) {
+               compiler.stack_assign(out);
+               compiler.add_node(NODE_LIGHT_FALLOFF, NODE_LIGHT_FALLOFF_QUADRATIC,
+                       compiler.encode_uchar4(strength_in->stack_offset, smooth_in->stack_offset, out->stack_offset));
+       }
+
+       out = output("Linear");
+       if(!out->links.empty()) {
+               compiler.stack_assign(out);
+               compiler.add_node(NODE_LIGHT_FALLOFF, NODE_LIGHT_FALLOFF_LINEAR,
+                       compiler.encode_uchar4(strength_in->stack_offset, smooth_in->stack_offset, out->stack_offset));
+               compiler.add_node(NODE_LIGHT_FALLOFF, NODE_LIGHT_FALLOFF_LINEAR, out->stack_offset);
+       }
+
+       out = output("Constant");
+       if(!out->links.empty()) {
+               compiler.stack_assign(out);
+               compiler.add_node(NODE_LIGHT_FALLOFF, NODE_LIGHT_FALLOFF_CONSTANT,
+                       compiler.encode_uchar4(strength_in->stack_offset, smooth_in->stack_offset, out->stack_offset));
+       }
+}
+
+void LightFalloffNode::compile(OSLCompiler& compiler)
+{
+       compiler.add(this, "node_light_falloff");
+}
+
 /* Value */
 
 ValueNode::ValueNode()
index 364209f8c5ee1c81c5296bf3fa4e2131a99d8645..ff9e3647d0134da7dc28d9c8edd2e2ed2497e606 100644 (file)
@@ -41,6 +41,9 @@ public:
        float3 rotation;
        float3 scale;
 
+       float3 min, max;
+       bool use_minmax;
+
        enum Mapping { NONE=0, X=1, Y=2, Z=3 };
        Mapping x_mapping, y_mapping, z_mapping;
 
@@ -277,6 +280,11 @@ public:
        SHADER_NODE_CLASS(LightPathNode)
 };
 
+class LightFalloffNode : public ShaderNode {
+public:
+       SHADER_NODE_CLASS(LightFalloffNode)
+};
+
 class ValueNode : public ShaderNode {
 public:
        SHADER_NODE_CLASS(ValueNode)
index 17c29e2a834852f14edbf64ebded8a3bacfa7fd9..c4c4e65a7bec0194d545d846e2e2625ce0616c3b 100644 (file)
@@ -51,7 +51,7 @@
 
 #include "endian.h"
 
-static int AVI_DEBUG=0;
+static int AVI_DEBUG = 0;
 static char DEBUG_FCC[4];
 
 #define DEBUG_PRINT(x) if (AVI_DEBUG) { printf("AVI DEBUG: " x); } (void)0
@@ -64,7 +64,7 @@ char *tcc_to_char(unsigned int tcc);
 
 /* implemetation */
 
-unsigned int GET_FCC (FILE *fp)
+unsigned int GET_FCC(FILE *fp)
 {
        unsigned char tmp[4];
 
@@ -73,10 +73,10 @@ unsigned int GET_FCC (FILE *fp)
        tmp[2] = getc(fp);
        tmp[3] = getc(fp);
 
-       return FCC (tmp);
+       return FCC(tmp);
 }
 
-unsigned int GET_TCC (FILE *fp)
+unsigned int GET_TCC(FILE *fp)
 {
        char tmp[5];
 
@@ -85,25 +85,25 @@ unsigned int GET_TCC (FILE *fp)
        tmp[2] = 0;
        tmp[3] = 0;
 
-       return FCC (tmp);
+       return FCC(tmp);
 }
 
 char *fcc_to_char(unsigned int fcc)
 {
-       DEBUG_FCC[0]= (fcc)&127;
-       DEBUG_FCC[1]= (fcc>>8)&127;
-       DEBUG_FCC[2]= (fcc>>16)&127;
-       DEBUG_FCC[3]= (fcc>>24)&127;
+       DEBUG_FCC[0] = (fcc) & 127;
+       DEBUG_FCC[1] = (fcc >> 8) & 127;
+       DEBUG_FCC[2] = (fcc >> 16) & 127;
+       DEBUG_FCC[3] = (fcc >> 24) & 127;
 
        return DEBUG_FCC;       
 }
 
 char *tcc_to_char(unsigned int tcc)
 {
-       DEBUG_FCC[0]= (tcc)&127;
-       DEBUG_FCC[1]= (tcc>>8)&127;
-       DEBUG_FCC[2]= 0;
-       DEBUG_FCC[3]= 0;
+       DEBUG_FCC[0] = (tcc) & 127;
+       DEBUG_FCC[1] = (tcc >> 8) & 127;
+       DEBUG_FCC[2] = 0;
+       DEBUG_FCC[3] = 0;
 
        return DEBUG_FCC;       
 }
@@ -115,7 +115,7 @@ int AVI_get_stream(AviMovie *movie, int avist_type, int stream_num)
        if (movie == NULL)
                return -AVI_ERROR_OPTION;
 
-       for (cur_stream=0; cur_stream < movie->header->Streams; cur_stream++) {
+       for (cur_stream = 0; cur_stream < movie->header->Streams; cur_stream++) {
                if (movie->streams[cur_stream].sh.Type == avist_type) {
                        if (stream_num == 0)
                                return cur_stream;
@@ -127,28 +127,28 @@ int AVI_get_stream(AviMovie *movie, int avist_type, int stream_num)
        return -AVI_ERROR_FOUND;
 }
 
-static int fcc_get_stream (int fcc)
+static int fcc_get_stream(int fcc)
 {
        char fccs[4];
 
        fccs[0] = fcc;
-       fccs[1] = fcc>>8;
-       fccs[2] = fcc>>16;
-       fccs[3] = fcc>>24;
+       fccs[1] = fcc >> 8;
+       fccs[2] = fcc >> 16;
+       fccs[3] = fcc >> 24;
 
-       return 10*(fccs[0]-'0') + (fccs[1]-'0');
+       return 10 * (fccs[0] - '0') + (fccs[1] - '0');
 }
 
-static int fcc_is_data (int fcc)
+static int fcc_is_data(int fcc)
 {
        char fccs[4];
 
        fccs[0] = fcc;
-       fccs[1] = fcc>>8;
-       fccs[2] = fcc>>16;
-       fccs[3] = fcc>>24;
+       fccs[1] = fcc >> 8;
+       fccs[2] = fcc >> 16;
+       fccs[3] = fcc >> 24;
 
-       if (!isdigit (fccs[0]) || !isdigit (fccs[1]) || (fccs[2] != 'd' && fccs[2] != 'w'))
+       if (!isdigit(fccs[0]) || !isdigit(fccs[1]) || (fccs[2] != 'd' && fccs[2] != 'w'))
                return 0;
        if (fccs[3] != 'b' && fccs[3] != 'c')
                return 0;
@@ -166,34 +166,34 @@ AviError AVI_print_error(AviError in_error)
                error = in_error;
 
        switch (error) {
-       case AVI_ERROR_NONE:
-               break;
-       case AVI_ERROR_COMPRESSION:
-               printf ("AVI ERROR: compressed in an unsupported format\n");
-               break;
-       case AVI_ERROR_OPEN:
-               printf ("AVI ERROR: could not open file\n");
-               break;
-       case AVI_ERROR_READING:
-               printf ("AVI ERROR: could not read from file\n");
-               break;
-       case AVI_ERROR_WRITING:
-               printf ("AVI ERROR: could not write to file\n");
-               break;
-       case AVI_ERROR_FORMAT:
-               printf ("AVI ERROR: file is in an illegal or unrecognized format\n");
-               break;
-       case AVI_ERROR_ALLOC:
-               printf ("AVI ERROR: error encountered while allocating memory\n");
-               break;
-       case AVI_ERROR_OPTION:
-               printf ("AVI ERROR: program made illegal request\n");
-               break;
-       case AVI_ERROR_FOUND:
-               printf ("AVI ERROR: movie did not contain expected item\n");
-               break;
-       default: 
-               break;
+               case AVI_ERROR_NONE:
+                       break;
+               case AVI_ERROR_COMPRESSION:
+                       printf("AVI ERROR: compressed in an unsupported format\n");
+                       break;
+               case AVI_ERROR_OPEN:
+                       printf("AVI ERROR: could not open file\n");
+                       break;
+               case AVI_ERROR_READING:
+                       printf("AVI ERROR: could not read from file\n");
+                       break;
+               case AVI_ERROR_WRITING:
+                       printf("AVI ERROR: could not write to file\n");
+                       break;
+               case AVI_ERROR_FORMAT:
+                       printf("AVI ERROR: file is in an illegal or unrecognized format\n");
+                       break;
+               case AVI_ERROR_ALLOC:
+                       printf("AVI ERROR: error encountered while allocating memory\n");
+                       break;
+               case AVI_ERROR_OPTION:
+                       printf("AVI ERROR: program made illegal request\n");
+                       break;
+               case AVI_ERROR_FOUND:
+                       printf("AVI ERROR: movie did not contain expected item\n");
+                       break;
+               default:
+                       break;
        }
 
        return in_error;
@@ -201,7 +201,7 @@ AviError AVI_print_error(AviError in_error)
 #if 0
 void AVI_set_debug(int mode)
 {
-       AVI_DEBUG= mode;
+       AVI_DEBUG = mode;
 }
 
 int AVI_is_avi(char *name)
@@ -209,13 +209,13 @@ int AVI_is_avi(char *name)
        FILE *fp;
        int ret;
        
-       fp = fopen (name, "rb");
+       fp = fopen(name, "rb");
        if (fp == NULL)
                return 0;
 
-       if (GET_FCC (fp) != FCC("RIFF") ||
-               !GET_FCC (fp) ||
-               GET_FCC (fp) != FCC("AVI ")) {
+       if (GET_FCC(fp) != FCC("RIFF") ||
+           !GET_FCC(fp) ||
+           GET_FCC(fp) != FCC("AVI ")) {
                ret = 0;
        }
        else {
@@ -230,7 +230,7 @@ int AVI_is_avi(char *name)
 int AVI_is_avi(const char *name)
 {
        int temp, fcca, j;
-       AviMovie movie= {NULL};
+       AviMovie movie = {NULL};
        AviMainHeader header;
        AviBitmapInfoHeader bheader;
        int movie_tracks = 0;
@@ -238,26 +238,26 @@ int AVI_is_avi(const char *name)
        DEBUG_PRINT("opening movie\n");
 
        movie.type = AVI_MOVIE_READ;
-       movie.fp = fopen (name, "rb");
+       movie.fp = fopen(name, "rb");
        movie.offset_table = NULL;
 
        if (movie.fp == NULL)
                return 0;
 
-       if (GET_FCC (movie.fp) != FCC("RIFF") ||
-               !(movie.size = GET_FCC (movie.fp))) {
+       if (GET_FCC(movie.fp) != FCC("RIFF") ||
+           !(movie.size = GET_FCC(movie.fp))) {
                fclose(movie.fp);
                return 0;
        }
 
        movie.header = &header;
 
-       if (GET_FCC (movie.fp) != FCC("AVI ") ||
-               GET_FCC (movie.fp) != FCC("LIST") ||
-               !GET_FCC (movie.fp) ||
-               GET_FCC (movie.fp) != FCC("hdrl") ||
-               (movie.header->fcc = GET_FCC (movie.fp)) != FCC("avih") ||
-               !(movie.header->size = GET_FCC (movie.fp))) {
+       if (GET_FCC(movie.fp) != FCC("AVI ") ||
+           GET_FCC(movie.fp) != FCC("LIST") ||
+           !GET_FCC(movie.fp) ||
+           GET_FCC(movie.fp) != FCC("hdrl") ||
+           (movie.header->fcc = GET_FCC(movie.fp)) != FCC("avih") ||
+           !(movie.header->size = GET_FCC(movie.fp))) {
                DEBUG_PRINT("bad initial header info\n");
                fclose(movie.fp);
                return 0;
@@ -278,7 +278,7 @@ int AVI_is_avi(const char *name)
        movie.header->Reserved[2] = GET_FCC(movie.fp);
        movie.header->Reserved[3] = GET_FCC(movie.fp);
 
-       fseek (movie.fp, movie.header->size-14*4, SEEK_CUR);
+       fseek(movie.fp, movie.header->size - 14 * 4, SEEK_CUR);
 
        if (movie.header->Streams < 1) {
                DEBUG_PRINT("streams less than 1\n");
@@ -286,15 +286,16 @@ int AVI_is_avi(const char *name)
                return 0;
        }
        
-       movie.streams = (AviStreamRec *) MEM_callocN (sizeof(AviStreamRec) * movie.header->Streams, "moviestreams");
+       movie.streams = (AviStreamRec *) MEM_callocN(sizeof(AviStreamRec) * movie.header->Streams, "moviestreams");
 
-       for (temp=0; temp < movie.header->Streams; temp++) {
+       for (temp = 0; temp < movie.header->Streams; temp++) {
 
                if (GET_FCC(movie.fp) != FCC("LIST") ||
-                       !GET_FCC (movie.fp) ||
-                       GET_FCC (movie.fp) != FCC ("strl") ||
-                       (movie.streams[temp].sh.fcc = GET_FCC (movie.fp)) != FCC ("strh") ||
-                       !(movie.streams[temp].sh.size = GET_FCC (movie.fp))) {
+                   !GET_FCC(movie.fp) ||
+                   GET_FCC(movie.fp) != FCC("strl") ||
+                   (movie.streams[temp].sh.fcc = GET_FCC(movie.fp)) != FCC("strh") ||
+                   !(movie.streams[temp].sh.size = GET_FCC(movie.fp)))
+               {
                        DEBUG_PRINT("bad stream header information\n");
                        
                        MEM_freeN(movie.streams);
@@ -302,20 +303,21 @@ int AVI_is_avi(const char *name)
                        return 0;                               
                }
 
-               movie.streams[temp].sh.Type = GET_FCC (movie.fp);
-               movie.streams[temp].sh.Handler = GET_FCC (movie.fp);
+               movie.streams[temp].sh.Type = GET_FCC(movie.fp);
+               movie.streams[temp].sh.Handler = GET_FCC(movie.fp);
 
                fcca = movie.streams[temp].sh.Handler;
                
                if (movie.streams[temp].sh.Type == FCC("vids")) {
-                       if (fcca == FCC ("DIB ") ||
-                               fcca == FCC ("RGB ") ||
-                               fcca == FCC ("rgb ") ||
-                               fcca == FCC ("RAW ") ||
-                               fcca == 0) {
+                       if (fcca == FCC("DIB ") ||
+                           fcca == FCC("RGB ") ||
+                           fcca == FCC("rgb ") ||
+                           fcca == FCC("RAW ") ||
+                           fcca == 0)
+                       {
                                movie.streams[temp].format = AVI_FORMAT_AVI_RGB;
                        }
-                       else if (fcca == FCC ("mjpg")||fcca == FCC ("MJPG")) {
+                       else if (fcca == FCC("mjpg") || fcca == FCC("MJPG")) {
                                movie.streams[temp].format = AVI_FORMAT_MJPEG;
                        }
                        else {
@@ -326,67 +328,70 @@ int AVI_is_avi(const char *name)
                        movie_tracks++;
                }
                
-               movie.streams[temp].sh.Flags = GET_FCC (movie.fp);
-               movie.streams[temp].sh.Priority = GET_TCC (movie.fp);
-               movie.streams[temp].sh.Language = GET_TCC (movie.fp);
-               movie.streams[temp].sh.InitialFrames = GET_FCC (movie.fp);
-               movie.streams[temp].sh.Scale = GET_FCC (movie.fp);
-               movie.streams[temp].sh.Rate = GET_FCC (movie.fp);
-               movie.streams[temp].sh.Start = GET_FCC (movie.fp);
-               movie.streams[temp].sh.Length = GET_FCC (movie.fp);
-               movie.streams[temp].sh.SuggestedBufferSize = GET_FCC (movie.fp);
-               movie.streams[temp].sh.Quality = GET_FCC (movie.fp);
-               movie.streams[temp].sh.SampleSize = GET_FCC (movie.fp);
-               movie.streams[temp].sh.left = GET_TCC (movie.fp);
-               movie.streams[temp].sh.top = GET_TCC (movie.fp);
-               movie.streams[temp].sh.right = GET_TCC (movie.fp);
-               movie.streams[temp].sh.bottom = GET_TCC (movie.fp);
-
-               fseek (movie.fp, movie.streams[temp].sh.size-14*4, SEEK_CUR);
-
-               if (GET_FCC (movie.fp) != FCC("strf")) {
+               movie.streams[temp].sh.Flags = GET_FCC(movie.fp);
+               movie.streams[temp].sh.Priority = GET_TCC(movie.fp);
+               movie.streams[temp].sh.Language = GET_TCC(movie.fp);
+               movie.streams[temp].sh.InitialFrames = GET_FCC(movie.fp);
+               movie.streams[temp].sh.Scale = GET_FCC(movie.fp);
+               movie.streams[temp].sh.Rate = GET_FCC(movie.fp);
+               movie.streams[temp].sh.Start = GET_FCC(movie.fp);
+               movie.streams[temp].sh.Length = GET_FCC(movie.fp);
+               movie.streams[temp].sh.SuggestedBufferSize = GET_FCC(movie.fp);
+               movie.streams[temp].sh.Quality = GET_FCC(movie.fp);
+               movie.streams[temp].sh.SampleSize = GET_FCC(movie.fp);
+               movie.streams[temp].sh.left = GET_TCC(movie.fp);
+               movie.streams[temp].sh.top = GET_TCC(movie.fp);
+               movie.streams[temp].sh.right = GET_TCC(movie.fp);
+               movie.streams[temp].sh.bottom = GET_TCC(movie.fp);
+
+               fseek(movie.fp, movie.streams[temp].sh.size - 14 * 4, SEEK_CUR);
+
+               if (GET_FCC(movie.fp) != FCC("strf")) {
                        DEBUG_PRINT("no stream format information\n");
                        MEM_freeN(movie.streams);
                        fclose(movie.fp);
                        return 0;
                }
 
-               movie.streams[temp].sf_size= GET_FCC(movie.fp);
+               movie.streams[temp].sf_size = GET_FCC(movie.fp);
                if (movie.streams[temp].sh.Type == FCC("vids")) {
                        j = movie.streams[temp].sf_size - (sizeof(AviBitmapInfoHeader) - 8);
                        if (j >= 0) {
                                AviBitmapInfoHeader *bi;
                                
-                               movie.streams[temp].sf= &bheader;
-                               bi= (AviBitmapInfoHeader *) movie.streams[temp].sf;
+                               movie.streams[temp].sf = &bheader;
+                               bi = (AviBitmapInfoHeader *) movie.streams[temp].sf;
                                
-                               bi->fcc= FCC("strf");
-                               bi->size= movie.streams[temp].sf_size;
-                               bi->Size= GET_FCC(movie.fp);
-                               bi->Width= GET_FCC(movie.fp);
-                               bi->Height= GET_FCC(movie.fp);
-                               bi->Planes= GET_TCC(movie.fp);
-                               bi->BitCount= GET_TCC(movie.fp);
-                               bi->Compression= GET_FCC(movie.fp);
-                               bi->SizeImage= GET_FCC(movie.fp);
-                               bi->XPelsPerMeter= GET_FCC(movie.fp);
-                               bi->YPelsPerMeter= GET_FCC(movie.fp);
-                               bi->ClrUsed= GET_FCC(movie.fp);
-                               bi->ClrImportant= GET_FCC(movie.fp);
+                               bi->fcc = FCC("strf");
+                               bi->size = movie.streams[temp].sf_size;
+                               bi->Size = GET_FCC(movie.fp);
+                               bi->Width = GET_FCC(movie.fp);
+                               bi->Height = GET_FCC(movie.fp);
+                               bi->Planes = GET_TCC(movie.fp);
+                               bi->BitCount = GET_TCC(movie.fp);
+                               bi->Compression = GET_FCC(movie.fp);
+                               bi->SizeImage = GET_FCC(movie.fp);
+                               bi->XPelsPerMeter = GET_FCC(movie.fp);
+                               bi->YPelsPerMeter = GET_FCC(movie.fp);
+                               bi->ClrUsed = GET_FCC(movie.fp);
+                               bi->ClrImportant = GET_FCC(movie.fp);
                                
                                fcca = bi->Compression;
 
-                               if ( movie.streams[temp].format ==
-                                        AVI_FORMAT_AVI_RGB) {
-                                       if (fcca == FCC ("DIB ") ||
-                                               fcca == FCC ("RGB ") ||
-                                               fcca == FCC ("rgb ") ||
-                                               fcca == FCC ("RAW ") ||
-                                               fcca == 0 ) {
+                               if (movie.streams[temp].format ==
+                                   AVI_FORMAT_AVI_RGB) {
+                                       if (fcca == FCC("DIB ") ||
+                                           fcca == FCC("RGB ") ||
+                                           fcca == FCC("rgb ") ||
+                                           fcca == FCC("RAW ") ||
+                                           fcca == 0)
+                                       {
+                                               /* pass */
                                        }
-                                       else if ( fcca == FCC ("mjpg") ||
-                                               fcca == FCC ("MJPG")) {
-                                                       movie.streams[temp].format = AVI_FORMAT_MJPEG;
+                                       else if (fcca == FCC("mjpg") ||
+                                                fcca == FCC("MJPG"))
+                                       {
+                                               movie.streams[temp].format = AVI_FORMAT_MJPEG;
                                        }
                                        else {
                                                MEM_freeN(movie.streams);
@@ -396,14 +401,14 @@ int AVI_is_avi(const char *name)
                                }
 
                        } 
-                       if (j > 0) fseek (movie.fp, j, SEEK_CUR);
+                       if (j > 0) fseek(movie.fp, j, SEEK_CUR);
                }
-               else fseek (movie.fp, movie.streams[temp].sf_size, SEEK_CUR);
+               else fseek(movie.fp, movie.streams[temp].sf_size, SEEK_CUR);
 
                /* Walk to the next LIST */             
-               while (GET_FCC (movie.fp) != FCC("LIST")) {
-                       temp= GET_FCC (movie.fp);
-                       if (temp<0 || ftell(movie.fp) > movie.size) {
+               while (GET_FCC(movie.fp) != FCC("LIST")) {
+                       temp = GET_FCC(movie.fp);
+                       if (temp < 0 || ftell(movie.fp) > movie.size) {
                                DEBUG_PRINT("incorrect size in header or error in AVI\n");
                                
                                MEM_freeN(movie.streams);
@@ -433,26 +438,27 @@ AviError AVI_open_movie(const char *name, AviMovie *movie)
        memset(movie, 0, sizeof(AviMovie));
 
        movie->type = AVI_MOVIE_READ;
-       movie->fp = fopen (name, "rb");
+       movie->fp = fopen(name, "rb");
        movie->offset_table = NULL;
 
        if (movie->fp == NULL)
                return AVI_ERROR_OPEN;
 
-       if (GET_FCC (movie->fp) != FCC("RIFF") ||
-               !(movie->size = GET_FCC (movie->fp)))
+       if (GET_FCC(movie->fp) != FCC("RIFF") ||
+           !(movie->size = GET_FCC(movie->fp)))
        {
                return AVI_ERROR_FORMAT;
        }
 
-       movie->header = (AviMainHeader *) MEM_mallocN (sizeof (AviMainHeader), "movieheader");
+       movie->header = (AviMainHeader *) MEM_mallocN(sizeof (AviMainHeader), "movieheader");
 
-       if (GET_FCC (movie->fp) != FCC("AVI ") ||
-               GET_FCC (movie->fp) != FCC("LIST") ||
-               !GET_FCC (movie->fp) ||
-               GET_FCC (movie->fp) != FCC("hdrl") ||
-               (movie->header->fcc = GET_FCC (movie->fp)) != FCC("avih") ||
-               !(movie->header->size = GET_FCC (movie->fp))) {
+       if (GET_FCC(movie->fp) != FCC("AVI ") ||
+           GET_FCC(movie->fp) != FCC("LIST") ||
+           !GET_FCC(movie->fp) ||
+           GET_FCC(movie->fp) != FCC("hdrl") ||
+           (movie->header->fcc = GET_FCC(movie->fp)) != FCC("avih") ||
+           !(movie->header->size = GET_FCC(movie->fp)))
+       {
                DEBUG_PRINT("bad initial header info\n");
                return AVI_ERROR_FORMAT;
        }
@@ -472,40 +478,42 @@ AviError AVI_open_movie(const char *name, AviMovie *movie)
        movie->header->Reserved[2] = GET_FCC(movie->fp);
        movie->header->Reserved[3] = GET_FCC(movie->fp);
 
-       fseek (movie->fp, movie->header->size-14*4, SEEK_CUR);
+       fseek(movie->fp, movie->header->size - 14 * 4, SEEK_CUR);
 
        if (movie->header->Streams < 1) {
                DEBUG_PRINT("streams less than 1\n");
                return AVI_ERROR_FORMAT;
        }
        
-       movie->streams = (AviStreamRec *) MEM_callocN (sizeof(AviStreamRec) * movie->header->Streams, "moviestreams");
+       movie->streams = (AviStreamRec *) MEM_callocN(sizeof(AviStreamRec) * movie->header->Streams, "moviestreams");
 
-       for (temp=0; temp < movie->header->Streams; temp++) {
+       for (temp = 0; temp < movie->header->Streams; temp++) {
 
                if (GET_FCC(movie->fp) != FCC("LIST") ||
-                       !GET_FCC (movie->fp) ||
-                       GET_FCC (movie->fp) != FCC ("strl") ||
-                       (movie->streams[temp].sh.fcc = GET_FCC (movie->fp)) != FCC ("strh") ||
-                       !(movie->streams[temp].sh.size = GET_FCC (movie->fp))) {
+                   !GET_FCC(movie->fp) ||
+                   GET_FCC(movie->fp) != FCC("strl") ||
+                   (movie->streams[temp].sh.fcc = GET_FCC(movie->fp)) != FCC("strh") ||
+                   !(movie->streams[temp].sh.size = GET_FCC(movie->fp)))
+               {
                        DEBUG_PRINT("bad stream header information\n");
-                       return AVI_ERROR_FORMAT;                                
+                       return AVI_ERROR_FORMAT;
                }
 
-               movie->streams[temp].sh.Type = GET_FCC (movie->fp);
-               movie->streams[temp].sh.Handler = GET_FCC (movie->fp);
+               movie->streams[temp].sh.Type = GET_FCC(movie->fp);
+               movie->streams[temp].sh.Handler = GET_FCC(movie->fp);
 
                fcca = movie->streams[temp].sh.Handler;
                
                if (movie->streams[temp].sh.Type == FCC("vids")) {
-                       if (fcca == FCC ("DIB ") ||
-                               fcca == FCC ("RGB ") ||
-                               fcca == FCC ("rgb ") ||
-                               fcca == FCC ("RAW ") ||
-                               fcca == 0) {
+                       if (fcca == FCC("DIB ") ||
+                           fcca == FCC("RGB ") ||
+                           fcca == FCC("rgb ") ||
+                           fcca == FCC("RAW ") ||
+                           fcca == 0)
+                       {
                                movie->streams[temp].format = AVI_FORMAT_AVI_RGB;
                        }
-                       else if (fcca == FCC ("mjpg")||fcca == FCC ("MJPG")) {
+                       else if (fcca == FCC("mjpg") || fcca == FCC("MJPG")) {
                                movie->streams[temp].format = AVI_FORMAT_MJPEG;
                        }
                        else {
@@ -513,66 +521,70 @@ AviError AVI_open_movie(const char *name, AviMovie *movie)
                        }
                }
                
-               movie->streams[temp].sh.Flags = GET_FCC (movie->fp);
-               movie->streams[temp].sh.Priority = GET_TCC (movie->fp);
-               movie->streams[temp].sh.Language = GET_TCC (movie->fp);
-               movie->streams[temp].sh.InitialFrames = GET_FCC (movie->fp);
-               movie->streams[temp].sh.Scale = GET_FCC (movie->fp);
-               movie->streams[temp].sh.Rate = GET_FCC (movie->fp);
-               movie->streams[temp].sh.Start = GET_FCC (movie->fp);
-               movie->streams[temp].sh.Length = GET_FCC (movie->fp);
-               movie->streams[temp].sh.SuggestedBufferSize = GET_FCC (movie->fp);
-               movie->streams[temp].sh.Quality = GET_FCC (movie->fp);
-               movie->streams[temp].sh.SampleSize = GET_FCC (movie->fp);
-               movie->streams[temp].sh.left = GET_TCC (movie->fp);
-               movie->streams[temp].sh.top = GET_TCC (movie->fp);
-               movie->streams[temp].sh.right = GET_TCC (movie->fp);
-               movie->streams[temp].sh.bottom = GET_TCC (movie->fp);
-
-               fseek (movie->fp, movie->streams[temp].sh.size-14*4, SEEK_CUR);
-
-               if (GET_FCC (movie->fp) != FCC("strf")) {
+               movie->streams[temp].sh.Flags = GET_FCC(movie->fp);
+               movie->streams[temp].sh.Priority = GET_TCC(movie->fp);
+               movie->streams[temp].sh.Language = GET_TCC(movie->fp);
+               movie->streams[temp].sh.InitialFrames = GET_FCC(movie->fp);
+               movie->streams[temp].sh.Scale = GET_FCC(movie->fp);
+               movie->streams[temp].sh.Rate = GET_FCC(movie->fp);
+               movie->streams[temp].sh.Start = GET_FCC(movie->fp);
+               movie->streams[temp].sh.Length = GET_FCC(movie->fp);
+               movie->streams[temp].sh.SuggestedBufferSize = GET_FCC(movie->fp);
+               movie->streams[temp].sh.Quality = GET_FCC(movie->fp);
+               movie->streams[temp].sh.SampleSize = GET_FCC(movie->fp);
+               movie->streams[temp].sh.left = GET_TCC(movie->fp);
+               movie->streams[temp].sh.top = GET_TCC(movie->fp);
+               movie->streams[temp].sh.right = GET_TCC(movie->fp);
+               movie->streams[temp].sh.bottom = GET_TCC(movie->fp);
+
+               fseek(movie->fp, movie->streams[temp].sh.size - 14 * 4, SEEK_CUR);
+
+               if (GET_FCC(movie->fp) != FCC("strf")) {
                        DEBUG_PRINT("no stream format information\n");
                        return AVI_ERROR_FORMAT;
                }
 
-               movie->streams[temp].sf_size= GET_FCC(movie->fp);
+               movie->streams[temp].sf_size = GET_FCC(movie->fp);
                if (movie->streams[temp].sh.Type == FCC("vids")) {
                        j = movie->streams[temp].sf_size - (sizeof(AviBitmapInfoHeader) - 8);
                        if (j >= 0) {
                                AviBitmapInfoHeader *bi;
                                
-                               movie->streams[temp].sf= MEM_mallocN(sizeof(AviBitmapInfoHeader), "streamformat");
+                               movie->streams[temp].sf = MEM_mallocN(sizeof(AviBitmapInfoHeader), "streamformat");
                                
-                               bi= (AviBitmapInfoHeader *) movie->streams[temp].sf;
+                               bi = (AviBitmapInfoHeader *) movie->streams[temp].sf;
                                
-                               bi->fcc= FCC("strf");
-                               bi->size= movie->streams[temp].sf_size;
-                               bi->Size= GET_FCC(movie->fp);
-                               bi->Width= GET_FCC(movie->fp);
-                               bi->Height= GET_FCC(movie->fp);
-                               bi->Planes= GET_TCC(movie->fp);
-                               bi->BitCount= GET_TCC(movie->fp);
-                               bi->Compression= GET_FCC(movie->fp);
-                               bi->SizeImage= GET_FCC(movie->fp);
-                               bi->XPelsPerMeter= GET_FCC(movie->fp);
-                               bi->YPelsPerMeter= GET_FCC(movie->fp);
-                               bi->ClrUsed= GET_FCC(movie->fp);
-                               bi->ClrImportant= GET_FCC(movie->fp);
+                               bi->fcc = FCC("strf");
+                               bi->size = movie->streams[temp].sf_size;
+                               bi->Size = GET_FCC(movie->fp);
+                               bi->Width = GET_FCC(movie->fp);
+                               bi->Height = GET_FCC(movie->fp);
+                               bi->Planes = GET_TCC(movie->fp);
+                               bi->BitCount = GET_TCC(movie->fp);
+                               bi->Compression = GET_FCC(movie->fp);
+                               bi->SizeImage = GET_FCC(movie->fp);
+                               bi->XPelsPerMeter = GET_FCC(movie->fp);
+                               bi->YPelsPerMeter = GET_FCC(movie->fp);
+                               bi->ClrUsed = GET_FCC(movie->fp);
+                               bi->ClrImportant = GET_FCC(movie->fp);
                                
                                fcca = bi->Compression;
 
-                                                               if ( movie->streams[temp].format ==
-                                        AVI_FORMAT_AVI_RGB) {
-                                       if (fcca == FCC ("DIB ") ||
-                                               fcca == FCC ("RGB ") ||
-                                               fcca == FCC ("rgb ") ||
-                                               fcca == FCC ("RAW ") ||
-                                               fcca == 0 ) {
+                               if (movie->streams[temp].format ==
+                                   AVI_FORMAT_AVI_RGB)
+                               {
+                                       if (fcca == FCC("DIB ") ||
+                                           fcca == FCC("RGB ") ||
+                                           fcca == FCC("rgb ") ||
+                                           fcca == FCC("RAW ") ||
+                                           fcca == 0)
+                                       {
+                                               /* pass */
                                        }
-                                       else if ( fcca == FCC ("mjpg") ||
-                                               fcca == FCC ("MJPG")) {
-                                                       movie->streams[temp].format = AVI_FORMAT_MJPEG;
+                                       else if (fcca == FCC("mjpg") ||
+                                                fcca == FCC("MJPG"))
+                                       {
+                                               movie->streams[temp].format = AVI_FORMAT_MJPEG;
                                        }
                                        else {
                                                return AVI_ERROR_COMPRESSION;
@@ -580,38 +592,38 @@ AviError AVI_open_movie(const char *name, AviMovie *movie)
                                }
 
                        } 
-                       if (j > 0) fseek (movie->fp, j, SEEK_CUR);
+                       if (j > 0) fseek(movie->fp, j, SEEK_CUR);
                }
-               else fseek (movie->fp, movie->streams[temp].sf_size, SEEK_CUR);
+               else fseek(movie->fp, movie->streams[temp].sf_size, SEEK_CUR);
                
                /* Walk to the next LIST */             
-               while (GET_FCC (movie->fp) != FCC("LIST")) {
-                       temp= GET_FCC (movie->fp);
-                       if (temp<0 || ftell(movie->fp) > movie->size) {
+               while (GET_FCC(movie->fp) != FCC("LIST")) {
+                       temp = GET_FCC(movie->fp);
+                       if (temp < 0 || ftell(movie->fp) > movie->size) {
                                DEBUG_PRINT("incorrect size in header or error in AVI\n");
-                               return AVI_ERROR_FORMAT;                                
+                               return AVI_ERROR_FORMAT;
                        }
-                       fseek(movie->fp, temp, SEEK_CUR);                       
+                       fseek(movie->fp, temp, SEEK_CUR);
                }
                
-               fseek(movie->fp, -4L, SEEK_CUR);                
+               fseek(movie->fp, -4L, SEEK_CUR);
        }
 
        while (1) {
-               temp = GET_FCC (movie->fp);
-               size = GET_FCC (movie->fp);
+               temp = GET_FCC(movie->fp);
+               size = GET_FCC(movie->fp);
 
                if (size == 0)
                        break;
 
                if (temp == FCC("LIST")) {
-                       if (GET_FCC(movie->fp) == FCC ("movi"))
+                       if (GET_FCC(movie->fp) == FCC("movi"))
                                break;
                        else
-                               fseek (movie->fp, size-4, SEEK_CUR);
+                               fseek(movie->fp, size - 4, SEEK_CUR);
                }
                else {
-                       fseek (movie->fp, size, SEEK_CUR);
+                       fseek(movie->fp, size, SEEK_CUR);
                }
                if (ftell(movie->fp) > movie->size) {
                        DEBUG_PRINT("incorrect size in header or error in AVI\n");
@@ -619,31 +631,31 @@ AviError AVI_open_movie(const char *name, AviMovie *movie)
                }
        }
 
-       movie->movi_offset = ftell (movie->fp);
+       movie->movi_offset = ftell(movie->fp);
        movie->read_offset = movie->movi_offset;
        
        /* Read in the index if the file has one, otherwise create one */
        if (movie->header->Flags & AVIF_HASINDEX) {
-               fseek(movie->fp, size-4, SEEK_CUR);
+               fseek(movie->fp, size - 4, SEEK_CUR);
 
                if (GET_FCC(movie->fp) != FCC("idx1")) {
                        DEBUG_PRINT("bad index informatio\n");
                        return AVI_ERROR_FORMAT;
                }
 
-               movie->index_entries = GET_FCC (movie->fp)/sizeof(AviIndexEntry);
+               movie->index_entries = GET_FCC(movie->fp) / sizeof(AviIndexEntry);
                if (movie->index_entries == 0) {
                        DEBUG_PRINT("no index entries\n");
                        return AVI_ERROR_FORMAT;
                }
 
-               movie->entries = (AviIndexEntry *) MEM_mallocN (movie->index_entries * sizeof(AviIndexEntry), "movieentries");
+               movie->entries = (AviIndexEntry *) MEM_mallocN(movie->index_entries * sizeof(AviIndexEntry), "movieentries");
 
-               for (temp=0; temp < movie->index_entries; temp++) {
-                       movie->entries[temp].ChunkId = GET_FCC (movie->fp);
-                       movie->entries[temp].Flags = GET_FCC (movie->fp);
-                       movie->entries[temp].Offset = GET_FCC (movie->fp);
-                       movie->entries[temp].Size = GET_FCC (movie->fp);
+               for (temp = 0; temp < movie->index_entries; temp++) {
+                       movie->entries[temp].ChunkId = GET_FCC(movie->fp);
+                       movie->entries[temp].Flags = GET_FCC(movie->fp);
+                       movie->entries[temp].Offset = GET_FCC(movie->fp);
+                       movie->entries[temp].Size = GET_FCC(movie->fp);
                        
                        if (AVI_DEBUG) {
                                printf("Index entry %04d: ChunkId:%s Flags:%d Offset:%d Size:%d\n",
@@ -660,31 +672,32 @@ AviError AVI_open_movie(const char *name, AviMovie *movie)
  * undetermined reason */
  
                if (movie->entries[0].Offset == movie->movi_offset)
-                       movie->read_offset= 4;
+                       movie->read_offset = 4;
        }
 
        DEBUG_PRINT("movie succesfully opened\n");
        return AVI_ERROR_NONE;
 }
 
-void *AVI_read_frame (AviMovie *movie, AviFormat format, int frame, int stream)
+void *AVI_read_frame(AviMovie *movie, AviFormat format, int frame, int stream)
 {
-       int cur_frame=-1, temp, i=0, rewind=1;
+       int cur_frame = -1, temp, i = 0, rewind = 1;
        void *buffer;
 
        /* Retrieve the record number of the desired frame in the index 
         * If a chunk has Size 0 we need to rewind to previous frame */
        while (rewind && frame > -1) {
-               i=0;
-               cur_frame=-1;
+               i = 0;
+               cur_frame = -1;
                rewind = 0;
 
                while (cur_frame < frame && i < movie->index_entries) {
-                       if (fcc_is_data (movie->entries[i].ChunkId) &&
-                               fcc_get_stream (movie->entries[i].ChunkId) == stream) {
-                               if ((cur_frame == frame -1) && (movie->entries[i].Size == 0)) {
+                       if (fcc_is_data(movie->entries[i].ChunkId) &&
+                           fcc_get_stream(movie->entries[i].ChunkId) == stream)
+                       {
+                               if ((cur_frame == frame - 1) && (movie->entries[i].Size == 0)) {
                                        rewind = 1;
-                                       frame = frame -1;
+                                       frame = frame - 1;
                                }
                                else {
                                        cur_frame++;
@@ -697,18 +710,18 @@ void *AVI_read_frame (AviMovie *movie, AviFormat format, int frame, int stream)
        if (cur_frame != frame) return NULL;
 
 
-       fseek (movie->fp, movie->read_offset + movie->entries[i-1].Offset, SEEK_SET);
+       fseek(movie->fp, movie->read_offset + movie->entries[i - 1].Offset, SEEK_SET);
 
        temp = GET_FCC(movie->fp);
-       buffer = MEM_mallocN (temp, "readbuffer");
+       buffer = MEM_mallocN(temp, "readbuffer");
 
-       if (fread (buffer, 1, temp, movie->fp) != temp) {
+       if (fread(buffer, 1, temp, movie->fp) != temp) {
                MEM_freeN(buffer);
 
                return NULL;
        }
        
-       buffer = avi_format_convert (movie, stream, buffer, movie->streams[stream].format, format, &temp);
+       buffer = avi_format_convert(movie, stream, buffer, movie->streams[stream].format, format, &temp);
 
        return buffer;
 }
@@ -717,21 +730,21 @@ AviError AVI_close(AviMovie *movie)
 {
        int i;
 
-       fclose (movie->fp);
+       fclose(movie->fp);
 
-       for (i=0; i < movie->header->Streams; i++) {
+       for (i = 0; i < movie->header->Streams; i++) {
                if (movie->streams[i].sf != NULL)
-                       MEM_freeN (movie->streams[i].sf);
+                       MEM_freeN(movie->streams[i].sf);
        }
 
        if (movie->header != NULL)
-               MEM_freeN (movie->header);
-       if (movie->streams!= NULL)
-               MEM_freeN (movie->streams);
+               MEM_freeN(movie->header);
+       if (movie->streams != NULL)
+               MEM_freeN(movie->streams);
        if (movie->entries != NULL)
-               MEM_freeN (movie->entries);
+               MEM_freeN(movie->entries);
        if (movie->offset_table != NULL)
-               MEM_freeN (movie->offset_table);
+               MEM_freeN(movie->offset_table);
 
        return AVI_ERROR_NONE;
 }
@@ -747,21 +760,21 @@ AviError AVI_open_compress(char *name, AviMovie *movie, int streams, ...)
        int64_t junk_pos;
 
        movie->type = AVI_MOVIE_WRITE;
-       movie->fp = fopen (name, "wb");
+       movie->fp = fopen(name, "wb");
 
        movie->index_entries = 0;
 
        if (movie->fp == NULL)
                return AVI_ERROR_OPEN;
 
-       movie->offset_table = (int64_t *) MEM_mallocN ((1+streams*2) * sizeof (int64_t), "offsettable");
+       movie->offset_table = (int64_t *) MEM_mallocN((1 + streams * 2) * sizeof (int64_t), "offsettable");
        
-       for (i=0; i < 1 + streams*2; i++)
+       for (i = 0; i < 1 + streams * 2; i++)
                movie->offset_table[i] = -1L;
 
        movie->entries = NULL;
 
-       movie->header = (AviMainHeader *) MEM_mallocN (sizeof(AviMainHeader), "movieheader");
+       movie->header = (AviMainHeader *) MEM_mallocN(sizeof(AviMainHeader), "movieheader");
 
        movie->header->fcc = FCC("avih");
        movie->header->size = 56;
@@ -780,20 +793,20 @@ AviError AVI_open_compress(char *name, AviMovie *movie, int streams, ...)
        movie->header->Reserved[2] = 0;
        movie->header->Reserved[3] = 0;
 
-       movie->streams = (AviStreamRec *) MEM_mallocN (sizeof(AviStreamRec) * movie->header->Streams, "moviestreams");
+       movie->streams = (AviStreamRec *) MEM_mallocN(sizeof(AviStreamRec) * movie->header->Streams, "moviestreams");
 
-       va_start (ap, streams);
+       va_start(ap, streams);
 
-       for (i=0; i < movie->header->Streams; i++) {
+       for (i = 0; i < movie->header->Streams; i++) {
                movie->streams[i].format = va_arg(ap, AviFormat);
 
-               movie->streams[i].sh.fcc = FCC ("strh");
+               movie->streams[i].sh.fcc = FCC("strh");
                movie->streams[i].sh.size = 56;
-               movie->streams[i].sh.Type = avi_get_format_type (movie->streams[i].format);
+               movie->streams[i].sh.Type = avi_get_format_type(movie->streams[i].format);
                if (movie->streams[i].sh.Type == 0)
                        return AVI_ERROR_FORMAT;
 
-               movie->streams[i].sh.Handler = avi_get_format_fcc (movie->streams[i].format);
+               movie->streams[i].sh.Handler = avi_get_format_fcc(movie->streams[i].format);
                if (movie->streams[i].sh.Handler == 0)
                        return AVI_ERROR_FORMAT;
 
@@ -816,30 +829,30 @@ AviError AVI_open_compress(char *name, AviMovie *movie, int streams, ...)
                if (movie->streams[i].sh.Type == FCC("vids")) { 
 #if 0
                        if (movie->streams[i].format == AVI_FORMAT_MJPEG) {
-                               movie->streams[i].sf = MEM_mallocN (sizeof(AviBitmapInfoHeader) 
-                                                                               + sizeof(AviMJPEGUnknown), "moviestreamformatL");
+                               movie->streams[i].sf = MEM_mallocN(sizeof(AviBitmapInfoHeader)
+                                                                  + sizeof(AviMJPEGUnknown), "moviestreamformatL");
                                movie->streams[i].sf_size = sizeof(AviBitmapInfoHeader) + sizeof(AviMJPEGUnknown);
                        }
                        else {
 #endif
-                       movie->streams[i].sf = MEM_mallocN (sizeof(AviBitmapInfoHeader),  "moviestreamformatS");
+                       movie->streams[i].sf = MEM_mallocN(sizeof(AviBitmapInfoHeader),  "moviestreamformatS");
                        movie->streams[i].sf_size = sizeof(AviBitmapInfoHeader);
 
-                       ((AviBitmapInfoHeader *) movie->streams[i].sf)->fcc = FCC ("strf");
+                       ((AviBitmapInfoHeader *) movie->streams[i].sf)->fcc = FCC("strf");
                        ((AviBitmapInfoHeader *) movie->streams[i].sf)->size = movie->streams[i].sf_size - 8;
                        ((AviBitmapInfoHeader *) movie->streams[i].sf)->Size = movie->streams[i].sf_size - 8;
                        ((AviBitmapInfoHeader *) movie->streams[i].sf)->Width = 0;
                        ((AviBitmapInfoHeader *) movie->streams[i].sf)->Height = 0;
                        ((AviBitmapInfoHeader *) movie->streams[i].sf)->Planes = 1;
                        ((AviBitmapInfoHeader *) movie->streams[i].sf)->BitCount = 24;
-                       ((AviBitmapInfoHeader *) movie->streams[i].sf)->Compression = avi_get_format_compression (movie->streams[i].format);
+                       ((AviBitmapInfoHeader *) movie->streams[i].sf)->Compression = avi_get_format_compression(movie->streams[i].format);
                        ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = 0;
                        ((AviBitmapInfoHeader *) movie->streams[i].sf)->XPelsPerMeter = 0;
                        ((AviBitmapInfoHeader *) movie->streams[i].sf)->YPelsPerMeter = 0;
                        ((AviBitmapInfoHeader *) movie->streams[i].sf)->ClrUsed = 0;
                        ((AviBitmapInfoHeader *) movie->streams[i].sf)->ClrImportant = 0;
 
-/*
+#if 0
                        if (movie->streams[i].format == AVI_FORMAT_MJPEG) {
                                AviMJPEGUnknown *tmp;
                                
@@ -857,7 +870,7 @@ AviError AVI_open_compress(char *name, AviMovie *movie, int streams, ...)
                else if (movie->streams[i].sh.Type == FCC("auds")) {
                        // pass
                }
-*/
+#endif
                }
        }
 
@@ -865,53 +878,53 @@ AviError AVI_open_compress(char *name, AviMovie *movie, int streams, ...)
        list.size = 0;
        list.ids = FCC("AVI ");
 
-       awrite (movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST);
+       awrite(movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST);
 
        list.fcc = FCC("LIST");
        list.size = 0;
        list.ids = FCC("hdrl");
 
-       awrite (movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST);
+       awrite(movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST);
 
        header_pos1 = ftell(movie->fp);
 
        movie->offset_table[0] = ftell(movie->fp);
 
-       awrite (movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH);
+       awrite(movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH);
 
-       for (i=0; i < movie->header->Streams; i++) {
+       for (i = 0; i < movie->header->Streams; i++) {
                list.fcc = FCC("LIST");
                list.size = 0;
                list.ids = FCC("strl");
 
-               awrite (movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST);
+               awrite(movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST);
 
                stream_pos1 = ftell(movie->fp);
 
-               movie->offset_table[1+i*2] = ftell(movie->fp);
-               awrite (movie, &movie->streams[i].sh, 1, sizeof(AviStreamHeader), movie->fp, AVI_STREAMH);
+               movie->offset_table[1 + i * 2] = ftell(movie->fp);
+               awrite(movie, &movie->streams[i].sh, 1, sizeof(AviStreamHeader), movie->fp, AVI_STREAMH);
 
-               movie->offset_table[1+i*2+1] = ftell(movie->fp);
-               awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
+               movie->offset_table[1 + i * 2 + 1] = ftell(movie->fp);
+               awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
 
                stream_pos2 = ftell(movie->fp);
 
-               fseek (movie->fp, stream_pos1-8, SEEK_SET);
+               fseek(movie->fp, stream_pos1 - 8, SEEK_SET);
 
-               PUT_FCCN((stream_pos2-stream_pos1+4L), movie->fp);
+               PUT_FCCN((stream_pos2 - stream_pos1 + 4L), movie->fp);
 
-               fseek (movie->fp, stream_pos2, SEEK_SET);
+               fseek(movie->fp, stream_pos2, SEEK_SET);
        }
 
-       junk_pos= ftell(movie->fp);
+       junk_pos = ftell(movie->fp);
 
        if (junk_pos < 2024 - 8) {
                chunk.fcc = FCC("JUNK");
                chunk.size = 2024 - 8 - (int)junk_pos;
 
-               awrite (movie, &chunk, 1, sizeof(AviChunk), movie->fp, AVI_CHUNK);
+               awrite(movie, &chunk, 1, sizeof(AviChunk), movie->fp, AVI_CHUNK);
 
-               for (i=0; i < chunk.size; i++)
+               for (i = 0; i < chunk.size; i++)
                        putc(0, movie->fp);
        }
 
@@ -921,13 +934,13 @@ AviError AVI_open_compress(char *name, AviMovie *movie, int streams, ...)
        list.size = 0;
        list.ids = FCC("movi");
 
-       awrite (movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST);
+       awrite(movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST);
 
-       movie->movi_offset = ftell(movie->fp)-8L;
+       movie->movi_offset = ftell(movie->fp) - 8L;
 
-       fseek (movie->fp, AVI_HDRL_SOFF, SEEK_SET);
+       fseek(movie->fp, AVI_HDRL_SOFF, SEEK_SET);
 
-       PUT_FCCN((header_pos2-header_pos1+4L), movie->fp);
+       PUT_FCCN((header_pos2 - header_pos1 + 4L), movie->fp);
 
        return AVI_ERROR_NONE;
 }
@@ -949,93 +962,93 @@ AviError AVI_write_frame(AviMovie *movie, int frame_num, ...)
 
        /* Allocate the new memory for the index entry */
 
-       if (frame_num+1 > movie->index_entries) {
-               temp = (AviIndexEntry *) MEM_mallocN ((frame_num+1) * 
-                       (movie->header->Streams+1) * sizeof(AviIndexEntry), "newidxentry");
+       if (frame_num + 1 > movie->index_entries) {
+               temp = (AviIndexEntry *) MEM_mallocN((frame_num + 1) *
+                                                    (movie->header->Streams + 1) * sizeof(AviIndexEntry), "newidxentry");
                if (movie->entries != NULL) {
-                       memcpy (temp, movie->entries, movie->index_entries * (movie->header->Streams+1)
-                               * sizeof(AviIndexEntry));
-                       MEM_freeN (movie->entries);
+                       memcpy(temp, movie->entries, movie->index_entries * (movie->header->Streams + 1)
+                              * sizeof(AviIndexEntry));
+                       MEM_freeN(movie->entries);
                }
 
                movie->entries = temp;
-               movie->index_entries = frame_num+1;
+               movie->index_entries = frame_num + 1;
        }
 
        /* Slap a new record entry onto the end of the file */
 
-       fseek (movie->fp, 0L, SEEK_END);
+       fseek(movie->fp, 0L, SEEK_END);
 
        list.fcc = FCC("LIST");
        list.size = 0;
        list.ids = FCC("rec ");
 
-       awrite (movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST);
+       awrite(movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST);
 
-       rec_off = ftell (movie->fp)-8L;
+       rec_off = ftell(movie->fp) - 8L;
 
        /* Write a frame for every stream */
 
-       va_start (ap, frame_num);
+       va_start(ap, frame_num);
 
-       for (stream=0; stream < movie->header->Streams; stream++) {
-               unsigned int tbuf=0;
+       for (stream = 0; stream < movie->header->Streams; stream++) {
+               unsigned int tbuf = 0;
                
-               format = va_arg (ap, AviFormat);
-               buffer = va_arg (ap, void*);
-               size = va_arg (ap, int);
+               format = va_arg(ap, AviFormat);
+               buffer = va_arg(ap, void *);
+               size = va_arg(ap, int);
 
                /* Convert the buffer into the output format */
-               buffer = avi_format_convert (movie, stream, buffer, format, movie->streams[stream].format, &size);
+               buffer = avi_format_convert(movie, stream, buffer, format, movie->streams[stream].format, &size);
 
                /* Write the header info for this data chunk */
 
-               fseek (movie->fp, 0L, SEEK_END);
+               fseek(movie->fp, 0L, SEEK_END);
 
-               chunk.fcc = avi_get_data_id (format, stream);
+               chunk.fcc = avi_get_data_id(format, stream);
                chunk.size = size;
                
-               if (size%4) chunk.size += 4 - size%4;
+               if (size % 4) chunk.size += 4 - size % 4;
                
-               awrite (movie, &chunk, 1, sizeof(AviChunk), movie->fp, AVI_CHUNK);
+               awrite(movie, &chunk, 1, sizeof(AviChunk), movie->fp, AVI_CHUNK);
 
                /* Write the index entry for this data chunk */
 
-               movie->entries[frame_num * (movie->header->Streams+1) + stream + 1].ChunkId = chunk.fcc;
-               movie->entries[frame_num * (movie->header->Streams+1) + stream + 1].Flags = AVIIF_KEYFRAME;
-               movie->entries[frame_num * (movie->header->Streams+1) + stream + 1].Offset = (int)(ftell(movie->fp) - 12L - movie->movi_offset);
-               movie->entries[frame_num * (movie->header->Streams+1) + stream + 1].Size = chunk.size;
+               movie->entries[frame_num * (movie->header->Streams + 1) + stream + 1].ChunkId = chunk.fcc;
+               movie->entries[frame_num * (movie->header->Streams + 1) + stream + 1].Flags = AVIIF_KEYFRAME;
+               movie->entries[frame_num * (movie->header->Streams + 1) + stream + 1].Offset = (int)(ftell(movie->fp) - 12L - movie->movi_offset);
+               movie->entries[frame_num * (movie->header->Streams + 1) + stream + 1].Size = chunk.size;
 
                /* Write the chunk */
-               awrite (movie, buffer, 1, size, movie->fp, AVI_RAW);
-               MEM_freeN (buffer);
+               awrite(movie, buffer, 1, size, movie->fp, AVI_RAW);
+               MEM_freeN(buffer);
 
-               if (size%4) awrite (movie, &tbuf, 1, 4-size%4, movie->fp, AVI_RAW);
+               if (size % 4) awrite(movie, &tbuf, 1, 4 - size % 4, movie->fp, AVI_RAW);
 
                /* Update the stream headers length field */
                movie->streams[stream].sh.Length++;
-               fseek (movie->fp, movie->offset_table[1+stream*2], SEEK_SET);
-               awrite (movie, &movie->streams[stream].sh, 1, sizeof(AviStreamHeader), movie->fp, AVI_STREAMH);
+               fseek(movie->fp, movie->offset_table[1 + stream * 2], SEEK_SET);
+               awrite(movie, &movie->streams[stream].sh, 1, sizeof(AviStreamHeader), movie->fp, AVI_STREAMH);
        }
-       va_end (ap);
+       va_end(ap);
 
        /* Record the entry for the new record */
 
-       fseek (movie->fp, 0L, SEEK_END);
+       fseek(movie->fp, 0L, SEEK_END);
 
-       movie->entries[frame_num * (movie->header->Streams+1)].ChunkId = FCC("rec ");
-       movie->entries[frame_num * (movie->header->Streams+1)].Flags = AVIIF_LIST;
-       movie->entries[frame_num * (movie->header->Streams+1)].Offset = (int)(rec_off - 8L - movie->movi_offset);
-       movie->entries[frame_num * (movie->header->Streams+1)].Size = (int)(ftell(movie->fp) - (rec_off + 4L));
+       movie->entries[frame_num * (movie->header->Streams + 1)].ChunkId = FCC("rec ");
+       movie->entries[frame_num * (movie->header->Streams + 1)].Flags = AVIIF_LIST;
+       movie->entries[frame_num * (movie->header->Streams + 1)].Offset = (int)(rec_off - 8L - movie->movi_offset);
+       movie->entries[frame_num * (movie->header->Streams + 1)].Size = (int)(ftell(movie->fp) - (rec_off + 4L));
 
        /* Update the record size */
-       fseek (movie->fp, rec_off, SEEK_SET);
-       PUT_FCCN (movie->entries[frame_num * (movie->header->Streams+1)].Size, movie->fp);
+       fseek(movie->fp, rec_off, SEEK_SET);
+       PUT_FCCN(movie->entries[frame_num * (movie->header->Streams + 1)].Size, movie->fp);
 
        /* Update the main header information in the file */
        movie->header->TotalFrames++;
-       fseek (movie->fp, movie->offset_table[0], SEEK_SET);
-       awrite (movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH);
+       fseek(movie->fp, movie->offset_table[0], SEEK_SET);
+       awrite(movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH);
 
        return AVI_ERROR_NONE;
 }
@@ -1044,38 +1057,38 @@ AviError AVI_close_compress(AviMovie *movie)
 {
        int temp, movi_size, i;
 
-       fseek (movie->fp, 0L, SEEK_END);
+       fseek(movie->fp, 0L, SEEK_END);
        movi_size = (int)ftell(movie->fp);
 
-       PUT_FCC ("idx1", movie->fp);
-       PUT_FCCN ((movie->index_entries*(movie->header->Streams+1)*16), movie->fp);
+       PUT_FCC("idx1", movie->fp);
+       PUT_FCCN((movie->index_entries * (movie->header->Streams + 1) * 16), movie->fp);
 
-       for (temp=0; temp < movie->index_entries*(movie->header->Streams+1); temp++)
-               awrite (movie, &movie->entries[temp], 1, sizeof(AviIndexEntry), movie->fp, AVI_INDEXE);
+       for (temp = 0; temp < movie->index_entries * (movie->header->Streams + 1); temp++)
+               awrite(movie, &movie->entries[temp], 1, sizeof(AviIndexEntry), movie->fp, AVI_INDEXE);
 
        temp = (int)ftell(movie->fp);
 
-       fseek (movie->fp, AVI_RIFF_SOFF, SEEK_SET);
+       fseek(movie->fp, AVI_RIFF_SOFF, SEEK_SET);
 
-       PUT_FCCN((temp-8L), movie->fp);
+       PUT_FCCN((temp - 8L), movie->fp);
 
-       fseek (movie->fp, movie->movi_offset, SEEK_SET);
+       fseek(movie->fp, movie->movi_offset, SEEK_SET);
 
-       PUT_FCCN((movi_size-(movie->movi_offset+4L)), movie->fp);
+       PUT_FCCN((movi_size - (movie->movi_offset + 4L)), movie->fp);
 
-       fclose (movie->fp);
+       fclose(movie->fp);
 
-       for (i=0; i < movie->header->Streams; i++) {
+       for (i = 0; i < movie->header->Streams; i++) {
                if (movie->streams[i].sf != NULL)
-                       MEM_freeN (movie->streams[i].sf);
+                       MEM_freeN(movie->streams[i].sf);
        }
        if (movie->header != NULL)
-               MEM_freeN (movie->header);
+               MEM_freeN(movie->header);
        if (movie->entries != NULL)
-               MEM_freeN (movie->entries);
+               MEM_freeN(movie->entries);
        if (movie->streams != NULL)
-               MEM_freeN (movie->streams);
+               MEM_freeN(movie->streams);
        if (movie->offset_table != NULL)
-               MEM_freeN (movie->offset_table);
+               MEM_freeN(movie->offset_table);
        return AVI_ERROR_NONE;
 }
index 36e862708f4db2eff5d161e17b14bf5be8f0749d..78316990d54c44252ad9ba2be418b04895fee3d1 100644 (file)
 
 /* implementation */
 
-void *avi_converter_from_avi_rgb (AviMovie *movie, int stream, unsigned char *buffer, int *size)
+void *avi_converter_from_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, int *size)
 {
        int x, y, i, rowstride;
        unsigned char *buf;
        AviBitmapInfoHeader *bi;
-       short bits= 32;
+       short bits = 32;
        
        (void)size; /* unused */
 
-       bi= (AviBitmapInfoHeader *) movie->streams[stream].sf;
-       if (bi) bits= bi->BitCount;
+       bi = (AviBitmapInfoHeader *) movie->streams[stream].sf;
+       if (bi) bits = bi->BitCount;
 
-       if (bits==16) {
+       if (bits == 16) {
                unsigned short *pxl;
                unsigned char *to;
 #ifdef __BIG_ENDIAN__
                unsigned char  *pxla;
 #endif           
                
-               buf = MEM_mallocN (movie->header->Height * movie->header->Width * 3, "fromavirgbbuf");
+               buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromavirgbbuf");
 
-               y= movie->header->Height;
-               to= buf;
+               y = movie->header->Height;
+               to = buf;
                                
                while (y--) {
-                       pxl= (unsigned short *) (buffer + y * movie->header->Width * 2);
+                       pxl = (unsigned short *) (buffer + y * movie->header->Width * 2);
                        
 #ifdef __BIG_ENDIAN__
-                       pxla= (unsigned char *)pxl;
+                       pxla = (unsigned char *)pxl;
 #endif
 
-                       x= movie->header->Width;
+                       x = movie->header->Width;
                        while (x--) {
 #ifdef __BIG_ENDIAN__
-                               i= pxla[0];
-                               pxla[0]= pxla[1];
-                               pxla[1]= i;
+                               i = pxla[0];
+                               pxla[0] = pxla[1];
+                               pxla[1] = i;
        
-                               pxla+=2;
+                               pxla += 2;
 #endif
                        
-                               *(to++)= ((*pxl>>10)&0x1f)*8;
-                               *(to++)= ((*pxl>>5)&0x1f)*8;
-                               *(to++)= (*pxl&0x1f)*8;
+                               *(to++) = ((*pxl >> 10) & 0x1f) * 8;
+                               *(to++) = ((*pxl >> 5) & 0x1f) * 8;
+                               *(to++) = (*pxl & 0x1f) * 8;
                                pxl++;  
                        }
                }
 
-               MEM_freeN (buffer);
+               MEM_freeN(buffer);
                
                return buf;
        }
        else {
-               buf = MEM_mallocN (movie->header->Height * movie->header->Width * 3, "fromavirgbbuf");
+               buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromavirgbbuf");
        
-               rowstride = movie->header->Width*3;
-               if (bits!=16) if (movie->header->Width%2) rowstride++;
+               rowstride = movie->header->Width * 3;
+               if (bits != 16) if (movie->header->Width % 2) rowstride++;
        
-               for (y=0; y < movie->header->Height; y++) {
-                       memcpy (&buf[y*movie->header->Width*3], &buffer[((movie->header->Height-1)-y)*rowstride], movie->header->Width*3);
+               for (y = 0; y < movie->header->Height; y++) {
+                       memcpy(&buf[y * movie->header->Width * 3], &buffer[((movie->header->Height - 1) - y) * rowstride], movie->header->Width * 3);
                }
        
-               for (y=0; y < movie->header->Height*movie->header->Width*3; y+=3) {
+               for (y = 0; y < movie->header->Height * movie->header->Width * 3; y += 3) {
                        i = buf[y];
-                       buf[y] = buf[y+2];
-                       buf[y+2] = i;
+                       buf[y] = buf[y + 2];
+                       buf[y + 2] = i;
                }
        
-               MEM_freeN (buffer);
+               MEM_freeN(buffer);
        
                return buf;
        }
 }
 
-void *avi_converter_to_avi_rgb (AviMovie *movie, int stream, unsigned char *buffer, int *size)
+void *avi_converter_to_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, int *size)
 {
        int y, x, i, rowstride;
        unsigned char *buf;
 
        (void)stream; /* unused */
 
-       *size= movie->header->Height * movie->header->Width * 3;
-       if (movie->header->Width%2) *size+= movie->header->Height;
+       *size = movie->header->Height * movie->header->Width * 3;
+       if (movie->header->Width % 2) *size += movie->header->Height;
        
-       buf = MEM_mallocN (*size, "toavirgbbuf");
+       buf = MEM_mallocN(*size, "toavirgbbuf");
 
-       rowstride = movie->header->Width*3;
-       if (movie->header->Width%2) rowstride++;
+       rowstride = movie->header->Width * 3;
+       if (movie->header->Width % 2) rowstride++;
 
-       for (y=0; y < movie->header->Height; y++) {
-               memcpy (&buf[y*rowstride], &buffer[((movie->header->Height-1)-y)*movie->header->Width*3], movie->header->Width*3);
+       for (y = 0; y < movie->header->Height; y++) {
+               memcpy(&buf[y * rowstride], &buffer[((movie->header->Height - 1) - y) * movie->header->Width * 3], movie->header->Width * 3);
        }
 
-       for (y=0; y < movie->header->Height; y++) {
-               for (x=0; x < movie->header->Width*3; x+=3) {
-                       i = buf[y*rowstride+x];
-                       buf[y*rowstride+x] = buf[y*rowstride+x+2];
-                       buf[y*rowstride+x+2] = i;
+       for (y = 0; y < movie->header->Height; y++) {
+               for (x = 0; x < movie->header->Width * 3; x += 3) {
+                       i = buf[y * rowstride + x];
+                       buf[y * rowstride + x] = buf[y * rowstride + x + 2];
+                       buf[y * rowstride + x + 2] = i;
                }
        }
 
-       MEM_freeN (buffer);
+       MEM_freeN(buffer);
 
        return buf;
 }
index c99938e7b9eb927c114b74b8288c09c2c7da649f..01e228d570e18159f74ffa79c27d684f46195546 100644 (file)
@@ -39,7 +39,7 @@
 #include "mjpeg.h"
 #include "rgb32.h"
 
-void *avi_format_convert (AviMovie *movie, int stream, void *buffer, AviFormat from, AviFormat to, int *size)
+void *avi_format_convert(AviMovie *movie, int stream, void *buffer, AviFormat from, AviFormat to, int *size)
 {
        if (from == to)
                return buffer;
@@ -53,32 +53,32 @@ void *avi_format_convert (AviMovie *movie, int stream, void *buffer, AviFormat f
        }
 
        switch (to) {
-       case AVI_FORMAT_RGB24:
-               switch (from) {
+               case AVI_FORMAT_RGB24:
+                       switch (from) {
+                               case AVI_FORMAT_AVI_RGB:
+                                       buffer = avi_converter_from_avi_rgb(movie, stream, buffer, size);
+                                       break;
+                               case AVI_FORMAT_MJPEG:
+                                       buffer = avi_converter_from_mjpeg(movie, stream, buffer, size);
+                                       break;
+                               case AVI_FORMAT_RGB32:
+                                       buffer = avi_converter_from_rgb32(movie, stream, buffer, size);
+                                       break;
+                               default:
+                                       break;
+                       }
+                       break;
                case AVI_FORMAT_AVI_RGB:
-                       buffer = avi_converter_from_avi_rgb (movie, stream, buffer, size);
+                       buffer = avi_converter_to_avi_rgb(movie, stream, buffer, size);
                        break;
                case AVI_FORMAT_MJPEG:
-                       buffer = avi_converter_from_mjpeg (movie, stream, buffer, size);
+                       buffer = avi_converter_to_mjpeg(movie, stream, buffer, size);
                        break;
                case AVI_FORMAT_RGB32:
-                       buffer = avi_converter_from_rgb32 (movie, stream, buffer, size);
+                       buffer = avi_converter_to_rgb32(movie, stream, buffer, size);
                        break;
                default:
                        break;
-               }
-               break;
-       case AVI_FORMAT_AVI_RGB:
-               buffer = avi_converter_to_avi_rgb (movie, stream, buffer, size);
-               break;
-       case AVI_FORMAT_MJPEG:
-               buffer = avi_converter_to_mjpeg (movie, stream, buffer, size);
-               break;
-       case AVI_FORMAT_RGB32:
-               buffer = avi_converter_to_rgb32 (movie, stream, buffer, size);
-               break;
-       default:
-               break;
        }
 
        return buffer;
@@ -88,10 +88,10 @@ int avi_get_data_id(AviFormat format, int stream)
 {
        char fcc[5];
 
-       if (avi_get_format_type (format) == FCC("vids"))
-               sprintf (fcc, "%2.2ddc", stream);
-       else if (avi_get_format_type (format) == FCC("auds"))
-               sprintf (fcc, "%2.2ddc", stream);
+       if (avi_get_format_type(format) == FCC("vids"))
+               sprintf(fcc, "%2.2ddc", stream);
+       else if (avi_get_format_type(format) == FCC("auds"))
+               sprintf(fcc, "%2.2ddc", stream);
        else
                return 0;
 
@@ -101,48 +101,48 @@ int avi_get_data_id(AviFormat format, int stream)
 int avi_get_format_type(AviFormat format)
 {
        switch (format) {
-       case AVI_FORMAT_RGB24:
-       case AVI_FORMAT_RGB32:
-       case AVI_FORMAT_AVI_RGB:
-       case AVI_FORMAT_MJPEG:
-               return FCC("vids");
-               break;
-       default:
-               return 0;
-               break;
+               case AVI_FORMAT_RGB24:
+               case AVI_FORMAT_RGB32:
+               case AVI_FORMAT_AVI_RGB:
+               case AVI_FORMAT_MJPEG:
+                       return FCC("vids");
+                       break;
+               default:
+                       return 0;
+                       break;
        }
 }
 
 int avi_get_format_fcc(AviFormat format)
 {
        switch (format) {
-       case AVI_FORMAT_RGB24:
-       case AVI_FORMAT_RGB32:
-       case AVI_FORMAT_AVI_RGB:
-               return FCC("DIB ");
-               break;
-       case AVI_FORMAT_MJPEG:
-               return FCC("MJPG");
-               break;
-       default:
-               return 0;
-               break;
+               case AVI_FORMAT_RGB24:
+               case AVI_FORMAT_RGB32:
+               case AVI_FORMAT_AVI_RGB:
+                       return FCC("DIB ");
+                       break;
+               case AVI_FORMAT_MJPEG:
+                       return FCC("MJPG");
+                       break;
+               default:
+                       return 0;
+                       break;
        }
 }
 
 int avi_get_format_compression(AviFormat format)
 {
        switch (format) {
-       case AVI_FORMAT_RGB24:
-       case AVI_FORMAT_RGB32:
-       case AVI_FORMAT_AVI_RGB:
-               return 0;
-               break;
-       case AVI_FORMAT_MJPEG:
-               return FCC("MJPG");
-               break;
-       default:
-               return 0;
-               break;
+               case AVI_FORMAT_RGB24:
+               case AVI_FORMAT_RGB32:
+               case AVI_FORMAT_AVI_RGB:
+                       return 0;
+                       break;
+               case AVI_FORMAT_MJPEG:
+                       return FCC("MJPG");
+                       break;
+               default:
+                       return 0;
+                       break;
        }
 }
index fd8cc56f5515fa9debc4236d93e2479283bd852e..c9b95d258105de24ef791185ba914dccbe7d1e45 100644 (file)
 #endif
 
 #ifdef __BIG_ENDIAN__
-static void invert (int *num)
+static void invert(int *num)
 {
-       int new=0, i, j;
+       int new = 0, i, j;
 
-       for (j=0; j < 4; j++) {
-               for (i=0; i<8; i++) {
-                       new |= ((*num>>(j*8+i))&1)<<((3-j)*8+i);
+       for (j = 0; j < 4; j++) {
+               for (i = 0; i < 8; i++) {
+                       new |= ((*num >> (j * 8 + i)) & 1) << ((3 - j) * 8 + i);
                }
        }
        
        *num = new;
 }
 
-static void sinvert (short int *num)
+static void sinvert(short int *num)
 {
-       short int new=0;
+       short int new = 0;
        int i, j;
 
-       for (j=0; j < 2; j++) {
-               for (i=0; i<8; i++) {
-                       new |= ((*num>>(j*8+i))&1)<<((1-j)*8+i);
+       for (j = 0; j < 2; j++) {
+               for (i = 0; i < 8; i++) {
+                       new |= ((*num >> (j * 8 + i)) & 1) << ((1 - j) * 8 + i);
                }
        }
 
        *num = new;
 }
 
-static void Ichunk (AviChunk *chunk)
+static void Ichunk(AviChunk *chunk)
 {
-       invert (&chunk->fcc);
-       invert (&chunk->size);
+       invert(&chunk->fcc);
+       invert(&chunk->size);
 }
 #endif
 
 #ifdef __BIG_ENDIAN__
-static void Ilist (AviList *list)
+static void Ilist(AviList *list)
 {
-       invert (&list->fcc);
-       invert (&list->size);
-       invert (&list->ids);
+       invert(&list->fcc);
+       invert(&list->size);
+       invert(&list->ids);
 }
 
-static void Imainh (AviMainHeader *mainh)
+static void Imainh(AviMainHeader *mainh)
 {
-       invert (&mainh->fcc);
-       invert (&mainh->size);
-       invert (&mainh->MicroSecPerFrame);
-       invert (&mainh->MaxBytesPerSec);
-       invert (&mainh->PaddingGranularity);
-       invert (&mainh->Flags);
-       invert (&mainh->TotalFrames);
-       invert (&mainh->InitialFrames);
-       invert (&mainh->Streams);
-       invert (&mainh->SuggestedBufferSize);
-       invert (&mainh->Width);
-       invert (&mainh->Height);
-       invert (&mainh->Reserved[0]);
-       invert (&mainh->Reserved[1]);
-       invert (&mainh->Reserved[2]);
-       invert (&mainh->Reserved[3]);
+       invert(&mainh->fcc);
+       invert(&mainh->size);
+       invert(&mainh->MicroSecPerFrame);
+       invert(&mainh->MaxBytesPerSec);
+       invert(&mainh->PaddingGranularity);
+       invert(&mainh->Flags);
+       invert(&mainh->TotalFrames);
+       invert(&mainh->InitialFrames);
+       invert(&mainh->Streams);
+       invert(&mainh->SuggestedBufferSize);
+       invert(&mainh->Width);
+       invert(&mainh->Height);
+       invert(&mainh->Reserved[0]);
+       invert(&mainh->Reserved[1]);
+       invert(&mainh->Reserved[2]);
+       invert(&mainh->Reserved[3]);
 }
 
-static void Istreamh (AviStreamHeader *streamh)
+static void Istreamh(AviStreamHeader *streamh)
 {
-       invert (&streamh->fcc);
-       invert (&streamh->size);
-       invert (&streamh->Type);
-       invert (&streamh->Handler);
-       invert (&streamh->Flags);
-       sinvert (&streamh->Priority);
-       sinvert (&streamh->Language);
-       invert (&streamh->InitialFrames);
-       invert (&streamh->Scale);
-       invert (&streamh->Rate);
-       invert (&streamh->Start);
-       invert (&streamh->Length);
-       invert (&streamh->SuggestedBufferSize);
-       invert (&streamh->Quality);
-       invert (&streamh->SampleSize);
-       sinvert (&streamh->left);
-       sinvert (&streamh->right);
-       sinvert (&streamh->top);
-       sinvert (&streamh->bottom);
+       invert(&streamh->fcc);
+       invert(&streamh->size);
+       invert(&streamh->Type);
+       invert(&streamh->Handler);
+       invert(&streamh->Flags);
+       sinvert(&streamh->Priority);
+       sinvert(&streamh->Language);
+       invert(&streamh->InitialFrames);
+       invert(&streamh->Scale);
+       invert(&streamh->Rate);
+       invert(&streamh->Start);
+       invert(&streamh->Length);
+       invert(&streamh->SuggestedBufferSize);
+       invert(&streamh->Quality);
+       invert(&streamh->SampleSize);
+       sinvert(&streamh->left);
+       sinvert(&streamh->right);
+       sinvert(&streamh->top);
+       sinvert(&streamh->bottom);
 }
 
-static void Ibitmaph (AviBitmapInfoHeader *bitmaph)
+static void Ibitmaph(AviBitmapInfoHeader *bitmaph)
 {
-       invert (&bitmaph->fcc);
-       invert (&bitmaph->size);
-       invert (&bitmaph->Size);
-       invert (&bitmaph->Width);
-       invert (&bitmaph->Height);
-       sinvert (&bitmaph->Planes);
-       sinvert (&bitmaph->BitCount);
-       invert (&bitmaph->Compression);
-       invert (&bitmaph->SizeImage);
-       invert (&bitmaph->XPelsPerMeter);
-       invert (&bitmaph->YPelsPerMeter);
-       invert (&bitmaph->ClrUsed);
-       invert (&bitmaph->ClrImportant);
+       invert(&bitmaph->fcc);
+       invert(&bitmaph->size);
+       invert(&bitmaph->Size);
+       invert(&bitmaph->Width);
+       invert(&bitmaph->Height);
+       sinvert(&bitmaph->Planes);
+       sinvert(&bitmaph->BitCount);
+       invert(&bitmaph->Compression);
+       invert(&bitmaph->SizeImage);
+       invert(&bitmaph->XPelsPerMeter);
+       invert(&bitmaph->YPelsPerMeter);
+       invert(&bitmaph->ClrUsed);
+       invert(&bitmaph->ClrImportant);
 }
 
-static void Imjpegu (AviMJPEGUnknown *mjpgu)
+static void Imjpegu(AviMJPEGUnknown *mjpgu)
 {
-       invert (&mjpgu->a);
-       invert (&mjpgu->b);
-       invert (&mjpgu->c);
-       invert (&mjpgu->d);
-       invert (&mjpgu->e);
-       invert (&mjpgu->f);
-       invert (&mjpgu->g);
+       invert(&mjpgu->a);
+       invert(&mjpgu->b);
+       invert(&mjpgu->c);
+       invert(&mjpgu->d);
+       invert(&mjpgu->e);
+       invert(&mjpgu->f);
+       invert(&mjpgu->g);
 }
 
-static void Iindexe (AviIndexEntry *indexe)
+static void Iindexe(AviIndexEntry *indexe)
 {
-       invert (&indexe->ChunkId);
-       invert (&indexe->Flags);
-       invert (&indexe->Offset);
-       invert (&indexe->Size);
+       invert(&indexe->ChunkId);
+       invert(&indexe->Flags);
+       invert(&indexe->Offset);
+       invert(&indexe->Size);
 }
 #endif /* __BIG_ENDIAN__ */
 
@@ -173,53 +173,53 @@ void awrite(AviMovie *movie, void *datain, int block, int size, FILE *fp, int ty
 #ifdef __BIG_ENDIAN__
        void *data;
 
-       data = MEM_mallocN (size, "avi endian");
+       data = MEM_mallocN(size, "avi endian");
 
-       memcpy (data, datain, size);
+       memcpy(data, datain, size);
 
        switch (type) {
-       case AVI_RAW:
-               fwrite (data, block, size, fp);
-               break;
-       case AVI_CHUNK:
-               Ichunk ((AviChunk *) data);
-               fwrite (data, block, size, fp);
-               break;
-       case AVI_LIST:
-               Ilist ((AviList *) data);
-               fwrite (data, block, size, fp);
-               break;
-       case AVI_MAINH:
-               Imainh ((AviMainHeader *) data);
-               fwrite (data, block, size, fp);
-               break;
-       case AVI_STREAMH:
-               Istreamh ((AviStreamHeader *) data);
-               fwrite (data, block, size, fp);
-               break;
-       case AVI_BITMAPH:
-               Ibitmaph ((AviBitmapInfoHeader *) data);
-               if (size==sizeof(AviBitmapInfoHeader) + sizeof(AviMJPEGUnknown)) {
-                       Imjpegu((AviMJPEGUnknown*)((char*)data+sizeof(AviBitmapInfoHeader)));
-               }
-               fwrite (data, block, size, fp);
-               break;
-       case AVI_MJPEGU:
-               Imjpegu ((AviMJPEGUnknown *) data);
-               fwrite (data, block, size, fp);
-               break;
-       case AVI_INDEXE:
-               Iindexe ((AviIndexEntry *) data);
-               fwrite (data, block, size, fp);
-               break;
-       default:
-               break;
+               case AVI_RAW:
+                       fwrite(data, block, size, fp);
+                       break;
+               case AVI_CHUNK:
+                       Ichunk((AviChunk *) data);
+                       fwrite(data, block, size, fp);
+                       break;
+               case AVI_LIST:
+                       Ilist((AviList *) data);
+                       fwrite(data, block, size, fp);
+                       break;
+               case AVI_MAINH:
+                       Imainh((AviMainHeader *) data);
+                       fwrite(data, block, size, fp);
+                       break;
+               case AVI_STREAMH:
+                       Istreamh((AviStreamHeader *) data);
+                       fwrite(data, block, size, fp);
+                       break;
+               case AVI_BITMAPH:
+                       Ibitmaph((AviBitmapInfoHeader *) data);
+                       if (size == sizeof(AviBitmapInfoHeader) + sizeof(AviMJPEGUnknown)) {
+                               Imjpegu((AviMJPEGUnknown *)((char *)data + sizeof(AviBitmapInfoHeader)));
+                       }
+                       fwrite(data, block, size, fp);
+                       break;
+               case AVI_MJPEGU:
+                       Imjpegu((AviMJPEGUnknown *) data);
+                       fwrite(data, block, size, fp);
+                       break;
+               case AVI_INDEXE:
+                       Iindexe((AviIndexEntry *) data);
+                       fwrite(data, block, size, fp);
+                       break;
+               default:
+                       break;
        }
 
-       MEM_freeN (data);
+       MEM_freeN(data);
 #else /* __BIG_ENDIAN__ */
        (void)movie; /* unused */
        (void)type; /* unused */
-       fwrite (datain, block, size, fp);
+       fwrite(datain, block, size, fp);
 #endif /* __BIG_ENDIAN__ */
 }
index 29356f8ef289bfd984989c0a63500e894fa47fc0..a700284bf681eb1b6339b9db0aa5b1a86a376787 100644 (file)
 
 #include "mjpeg.h"
 
-#define PADUP(num, amt)        ((num+(amt-1))&~(amt-1))
+#define PADUP(num, amt) ((num + (amt - 1)) & ~(amt - 1))
 
-static void jpegmemdestmgr_build (j_compress_ptr cinfo, unsigned char *buffer, int bufsize);
-static void jpegmemsrcmgr_build (j_decompress_ptr dinfo, unsigned char *buffer, int bufsize);
+static void jpegmemdestmgr_build(j_compress_ptr cinfo, unsigned char *buffer, int bufsize);
+static void jpegmemsrcmgr_build(j_decompress_ptr dinfo, unsigned char *buffer, int bufsize);
 
 static int numbytes;
 
-static void add_huff_table (j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
+static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
 {
        if (*htblptr == NULL)
                *htblptr = jpeg_alloc_huff_table((j_common_ptr) dinfo);
@@ -64,25 +64,30 @@ static void add_huff_table (j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const U
 /* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
 /* IMPORTANT: these are only valid for 8-bit data precision! */
 
-static void std_huff_tables (j_decompress_ptr dinfo)
+static void std_huff_tables(j_decompress_ptr dinfo)
 {
        static const UINT8 bits_dc_luminance[17] =
        { /* 0-base */
-               0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0       };
+               0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0
+       };
        static const UINT8 val_dc_luminance[] =
        { 
-               0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11    };
+               0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
+       };
 
        static const UINT8 bits_dc_chrominance[17] =
        { /* 0-base */
-               0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0       };
+               0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
+       };
        static const UINT8 val_dc_chrominance[] =
        { 
-               0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11    };
+               0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
+       };
 
        static const UINT8 bits_ac_luminance[17] =
        { /* 0-base */
-               0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d    };
+               0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d
+       };
        static const UINT8 val_ac_luminance[] =
        { 
                0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
@@ -105,10 +110,12 @@ static void std_huff_tables (j_decompress_ptr dinfo)
                0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
                0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
                0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
-               0xf9, 0xfa      };
+               0xf9, 0xfa
+       };
        static const UINT8 bits_ac_chrominance[17] =
        { /* 0-base */
-               0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77    };
+               0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77
+       };
        static const UINT8 val_ac_chrominance[] =
        { 
                0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
@@ -131,16 +138,17 @@ static void std_huff_tables (j_decompress_ptr dinfo)
                0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
                0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
                0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
-               0xf9, 0xfa      };
+               0xf9, 0xfa
+       };
 
        add_huff_table(dinfo, &dinfo->dc_huff_tbl_ptrs[0],
-               bits_dc_luminance, val_dc_luminance);
+                      bits_dc_luminance, val_dc_luminance);
        add_huff_table(dinfo, &dinfo->ac_huff_tbl_ptrs[0],
-               bits_ac_luminance, val_ac_luminance);
+                      bits_ac_luminance, val_ac_luminance);
        add_huff_table(dinfo, &dinfo->dc_huff_tbl_ptrs[1],
-               bits_dc_chrominance, val_dc_chrominance);
+                      bits_dc_chrominance, val_dc_chrominance);
        add_huff_table(dinfo, &dinfo->ac_huff_tbl_ptrs[1],
-               bits_ac_chrominance, val_ac_chrominance);
+                      bits_ac_chrominance, val_ac_chrominance);
 }
 
 static int Decode_JPEG(unsigned char *inBuffer, unsigned char *outBuffer, unsigned int width, unsigned int height, int bufsize)
@@ -152,7 +160,7 @@ static int Decode_JPEG(unsigned char *inBuffer, unsigned char *outBuffer, unsign
        
        (void)width; /* unused */
 
-       numbytes= 0;
+       numbytes = 0;
 
        dinfo.err = jpeg_std_error(&jerr);
        jpeg_create_decompress(&dinfo);
@@ -166,8 +174,8 @@ static int Decode_JPEG(unsigned char *inBuffer, unsigned char *outBuffer, unsign
 
        jpeg_start_decompress(&dinfo);
 
-       rowstride= dinfo.output_width*dinfo.output_components;
-       for (y= 0; y<dinfo.output_height; y++) {
+       rowstride = dinfo.output_width * dinfo.output_components;
+       for (y = 0; y < dinfo.output_height; y++) {
                jpeg_read_scanlines(&dinfo, (JSAMPARRAY) &outBuffer, 1);
                outBuffer += rowstride;
        }
@@ -175,18 +183,18 @@ static int Decode_JPEG(unsigned char *inBuffer, unsigned char *outBuffer, unsign
 
        if (dinfo.output_height >= height) return 0;
        
-       inBuffer+= numbytes;
-       jpegmemsrcmgr_build(&dinfo, inBuffer, bufsize-numbytes);
+       inBuffer += numbytes;
+       jpegmemsrcmgr_build(&dinfo, inBuffer, bufsize - numbytes);
 
-       numbytes= 0;
+       numbytes = 0;
        jpeg_read_header(&dinfo, TRUE);
        if (dinfo.dc_huff_tbl_ptrs[0] == NULL) {
                std_huff_tables(&dinfo);
        }
 
        jpeg_start_decompress(&dinfo);
-       rowstride= dinfo.output_width*dinfo.output_components;
-       for (y= 0; y<dinfo.output_height; y++) {
+       rowstride = dinfo.output_width * dinfo.output_components;
+       for (y = 0; y < dinfo.output_height; y++) {
                jpeg_read_scanlines(&dinfo, (JSAMPARRAY) &outBuffer, 1);
                outBuffer += rowstride;
        }
@@ -214,9 +222,9 @@ static void Compress_JPEG(int quality, unsigned char *outbuffer, unsigned char *
        cinfo.in_color_space = JCS_RGB;
 
        jpeg_set_defaults(&cinfo);
-       jpeg_set_colorspace (&cinfo, JCS_YCbCr);
+       jpeg_set_colorspace(&cinfo, JCS_YCbCr);
                
-       jpeg_set_quality (&cinfo, quality, TRUE);
+       jpeg_set_quality(&cinfo, quality, TRUE);
 
        cinfo.dc_huff_tbl_ptrs[0]->sent_table = TRUE;
        cinfo.dc_huff_tbl_ptrs[1]->sent_table = TRUE;
@@ -232,24 +240,24 @@ static void Compress_JPEG(int quality, unsigned char *outbuffer, unsigned char *
 
        jpeg_start_compress(&cinfo, FALSE);
 
-       i=0;
+       i = 0;
        marker[i++] = 'A';
        marker[i++] = 'V';
        marker[i++] = 'I';
        marker[i++] = '1';
        marker[i++] = 0;
-       while (i<60)
+       while (i < 60)
                marker[i++] = 32;
 
-       jpeg_write_marker (&cinfo, JPEG_APP0, marker, 60);
+       jpeg_write_marker(&cinfo, JPEG_APP0, marker, 60);
 
-       i=0;
-       while (i<60)
+       i = 0;
+       while (i < 60)
                marker[i++] = 0;
 
-       jpeg_write_marker (&cinfo, JPEG_COM, marker, 60);
+       jpeg_write_marker(&cinfo, JPEG_COM, marker, 60);
 
-       rowstride= cinfo.image_width*cinfo.input_components;
+       rowstride = cinfo.image_width * cinfo.input_components;
        for (y = 0; y < cinfo.image_height; y++) {
                jpeg_write_scanlines(&cinfo, (JSAMPARRAY) &inBuffer, 1);
                inBuffer += rowstride;
@@ -260,43 +268,43 @@ static void Compress_JPEG(int quality, unsigned char *outbuffer, unsigned char *
 
 static void interlace(unsigned char *to, unsigned char *from, int width, int height)
 {
-       int i, rowstride= width*3;
+       int i, rowstride = width * 3;
        
-       for (i=0; i<height; i++) {
-               if (i&1)
-                       memcpy (&to[i*rowstride], &from[(i/2 + height/2)*rowstride], rowstride);
+       for (i = 0; i < height; i++) {
+               if (i & 1)
+                       memcpy(&to[i * rowstride], &from[(i / 2 + height / 2) * rowstride], rowstride);
                else 
-                       memcpy (&to[i*rowstride], &from[(i/2)*rowstride], rowstride);
+                       memcpy(&to[i * rowstride], &from[(i / 2) * rowstride], rowstride);
        }
 }
 
 static void deinterlace(int odd, unsigned char *to, unsigned char *from, int width, int height)
 {
-       int i, rowstride= width*3;
+       int i, rowstride = width * 3;
        
-       for (i=0; i<height; i++) {
-               if ((i&1)==odd)
-                       memcpy (&to[(i/2 + height/2)*rowstride], &from[i*rowstride], rowstride);
+       for (i = 0; i < height; i++) {
+               if ((i & 1) == odd)
+                       memcpy(&to[(i / 2 + height / 2) * rowstride], &from[i * rowstride], rowstride);
                else 
-                       memcpy (&to[(i/2)*rowstride], &from[i*rowstride], rowstride);
+                       memcpy(&to[(i / 2) * rowstride], &from[i * rowstride], rowstride);
        }
 }
 
 static int check_and_decode_jpeg(unsigned char *inbuf, unsigned char *outbuf, int width, int height, int bufsize)
 {
-               /* JPEG's are always multiples of 16, extra is cropped out AVI's */     
-       if ((width&0xF) || (height&0xF)) {
+       /* JPEG's are always multiples of 16, extra is cropped out AVI's */
+       if ((width & 0xF) || (height & 0xF)) {
                int i, rrowstride, jrowstride;
-               int jwidth= PADUP(width, 16);
-               int jheight= PADUP(height, 16);
-               unsigned char *tmpbuf= MEM_mallocN(jwidth*jheight*3, "avi.check_and_decode_jpeg");
-               int ret= Decode_JPEG(inbuf, tmpbuf, jwidth, jheight, bufsize);
-               
-                       /* crop the tmpbuf into the real buffer */
-               rrowstride= width*3;
-               jrowstride= jwidth*3;
-               for (i=0; i<height; i++)
-                       memcpy(&outbuf[i*rrowstride], &tmpbuf[i*jrowstride], rrowstride);
+               int jwidth = PADUP(width, 16);
+               int jheight = PADUP(height, 16);
+               unsigned char *tmpbuf = MEM_mallocN(jwidth * jheight * 3, "avi.check_and_decode_jpeg");
+               int ret = Decode_JPEG(inbuf, tmpbuf, jwidth, jheight, bufsize);
+
+               /* crop the tmpbuf into the real buffer */
+               rrowstride = width * 3;
+               jrowstride = jwidth * 3;
+               for (i = 0; i < height; i++)
+                       memcpy(&outbuf[i * rrowstride], &tmpbuf[i * jrowstride], rrowstride);
                MEM_freeN(tmpbuf);
                
                return ret;
@@ -308,22 +316,22 @@ static int check_and_decode_jpeg(unsigned char *inbuf, unsigned char *outbuf, in
 
 static void check_and_compress_jpeg(int quality, unsigned char *outbuf, unsigned char *inbuf, int width, int height, int bufsize)
 {
-               /* JPEG's are always multiples of 16, extra is ignored in AVI's */      
-       if ((width&0xF) || (height&0xF)) {
+       /* JPEG's are always multiples of 16, extra is ignored in AVI's */
+       if ((width & 0xF) || (height & 0xF)) {
                int i, rrowstride, jrowstride;
-               int jwidth= PADUP(width, 16);
-               int jheight= PADUP(height, 16);
-               unsigned char *tmpbuf= MEM_mallocN(jwidth*jheight*3, "avi.check_and_compress_jpeg");
-               
-                       /* resize the realbuf into the tmpbuf */
-               rrowstride= width*3;
-               jrowstride= jwidth*3;
-               for (i=0; i<jheight; i++) {
-                       if (i<height)
-                               memcpy(&tmpbuf[i*jrowstride], &inbuf[i*rrowstride], rrowstride);
+               int jwidth = PADUP(width, 16);
+               int jheight = PADUP(height, 16);
+               unsigned char *tmpbuf = MEM_mallocN(jwidth * jheight * 3, "avi.check_and_compress_jpeg");
+
+               /* resize the realbuf into the tmpbuf */
+               rrowstride = width * 3;
+               jrowstride = jwidth * 3;
+               for (i = 0; i < jheight; i++) {
+                       if (i < height)
+                               memcpy(&tmpbuf[i * jrowstride], &inbuf[i * rrowstride], rrowstride);
                        else
-                               memset(&tmpbuf[i*jrowstride], 0, rrowstride);
-                       memset(&tmpbuf[i*jrowstride+rrowstride], 0, jrowstride-rrowstride);
+                               memset(&tmpbuf[i * jrowstride], 0, rrowstride);
+                       memset(&tmpbuf[i * jrowstride + rrowstride], 0, jrowstride - rrowstride);
                }
 
                Compress_JPEG(quality, outbuf, tmpbuf, jwidth, jheight, bufsize);
@@ -335,57 +343,57 @@ static void check_and_compress_jpeg(int quality, unsigned char *outbuf, unsigned
        }
 }
 
-void *avi_converter_from_mjpeg (AviMovie *movie, int stream, unsigned char *buffer, int *size)
+void *avi_converter_from_mjpeg(AviMovie *movie, int stream, unsigned char *buffer, int *size)
 {
        int deint;
        unsigned char *buf;
 
        (void)stream; /* unused */
 
-       buf= MEM_mallocN (movie->header->Height * movie->header->Width * 3, "avi.avi_converter_from_mjpeg 1");
+       buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_from_mjpeg 1");
 
-       deint= check_and_decode_jpeg(buffer, buf, movie->header->Width, movie->header->Height, *size);
+       deint = check_and_decode_jpeg(buffer, buf, movie->header->Width, movie->header->Height, *size);
        
        MEM_freeN(buffer);
        
        if (deint) {
-               buffer = MEM_mallocN (movie->header->Height * movie->header->Width * 3, "avi.avi_converter_from_mjpeg 2");
-               interlace (buffer, buf, movie->header->Width, movie->header->Height);
-               MEM_freeN (buf);
+               buffer = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_from_mjpeg 2");
+               interlace(buffer, buf, movie->header->Width, movie->header->Height);
+               MEM_freeN(buf);
        
-               buf= buffer;
+               buf = buffer;
        }
                
        return buf;
 }
 
-void *avi_converter_to_mjpeg (AviMovie *movie, int stream, unsigned char *buffer, int *size)
+void *avi_converter_to_mjpeg(AviMovie *movie, int stream, unsigned char *buffer, int *size)
 {
        unsigned char *buf;
-       int bufsize= *size;
+       int bufsize = *size;
        
        numbytes = 0;
-       *size= 0;
+       *size = 0;
 
-       buf = MEM_mallocN (movie->header->Height * movie->header->Width * 3, "avi.avi_converter_to_mjpeg 1");   
+       buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_to_mjpeg 1");
        if (!movie->interlace) {
-               check_and_compress_jpeg(movie->streams[stream].sh.Quality/100, buf, buffer,  movie->header->Width, movie->header->Height, bufsize);
+               check_and_compress_jpeg(movie->streams[stream].sh.Quality / 100, buf, buffer,  movie->header->Width, movie->header->Height, bufsize);
        }
        else {
-               deinterlace (movie->odd_fields, buf, buffer, movie->header->Width, movie->header->Height);
-               MEM_freeN (buffer);
+               deinterlace(movie->odd_fields, buf, buffer, movie->header->Width, movie->header->Height);
+               MEM_freeN(buffer);
        
-               buffer= buf;
-               buf= MEM_mallocN (movie->header->Height * movie->header->Width * 3, "avi.avi_converter_to_mjpeg 2");
+               buffer = buf;
+               buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_to_mjpeg 2");
        
-               check_and_compress_jpeg(movie->streams[stream].sh.Quality/100, buf, buffer,  movie->header->Width, movie->header->Height/2, bufsize/2);
-               *size+= numbytes;
-               numbytes=0;
-               check_and_compress_jpeg(movie->streams[stream].sh.Quality/100, buf+*size, buffer+(movie->header->Height/2)*movie->header->Width*3,  movie->header->Width, movie->header->Height/2, bufsize/2);
+               check_and_compress_jpeg(movie->streams[stream].sh.Quality / 100, buf, buffer,  movie->header->Width, movie->header->Height / 2, bufsize / 2);
+               *size += numbytes;
+               numbytes = 0;
+               check_and_compress_jpeg(movie->streams[stream].sh.Quality / 100, buf + *size, buffer + (movie->header->Height / 2) * movie->header->Width * 3,  movie->header->Width, movie->header->Height / 2, bufsize / 2);
        }
        *size += numbytes;      
 
-       MEM_freeN (buffer);
+       MEM_freeN(buffer);
        return buf;
 }
 
@@ -405,23 +413,23 @@ static boolean jpegmemdestmgr_empty_output_buffer(j_compress_ptr cinfo)
 
 static void jpegmemdestmgr_term_destination(j_compress_ptr cinfo)
 {
-       numbytes-= cinfo->dest->free_in_buffer;
+       numbytes -= cinfo->dest->free_in_buffer;
 
        MEM_freeN(cinfo->dest);
 }
 
 static void jpegmemdestmgr_build(j_compress_ptr cinfo, unsigned char *buffer, int bufsize)
 {
-       cinfo->dest= MEM_mallocN(sizeof(*(cinfo->dest)), "avi.jpegmemdestmgr_build");
+       cinfo->dest = MEM_mallocN(sizeof(*(cinfo->dest)), "avi.jpegmemdestmgr_build");
        
-       cinfo->dest->init_destination= jpegmemdestmgr_init_destination;
-       cinfo->dest->empty_output_buffer= jpegmemdestmgr_empty_output_buffer;
-       cinfo->dest->term_destination= jpegmemdestmgr_term_destination;
+       cinfo->dest->init_destination = jpegmemdestmgr_init_destination;
+       cinfo->dest->empty_output_buffer = jpegmemdestmgr_empty_output_buffer;
+       cinfo->dest->term_destination = jpegmemdestmgr_term_destination;
 
-       cinfo->dest->next_output_byte= buffer;
-       cinfo->dest->free_in_buffer= bufsize;
+       cinfo->dest->next_output_byte = buffer;
+       cinfo->dest->free_in_buffer = bufsize;
        
-       numbytes= bufsize;
+       numbytes = bufsize;
 }
 
 /* Decompression from memory */
@@ -433,48 +441,48 @@ static void jpegmemsrcmgr_init_source(j_decompress_ptr dinfo)
 
 static boolean jpegmemsrcmgr_fill_input_buffer(j_decompress_ptr dinfo)
 {
-       unsigned char *buf= (unsigned char*) dinfo->src->next_input_byte-2;
+       unsigned char *buf = (unsigned char *) dinfo->src->next_input_byte - 2;
        
-               /* if we get called, must have run out of data */
+       /* if we get called, must have run out of data */
        WARNMS(dinfo, JWRN_JPEG_EOF);
        
-       buf[0]= (JOCTET) 0xFF;
-       buf[1]= (JOCTET) JPEG_EOI;
+       buf[0] = (JOCTET) 0xFF;
+       buf[1] = (JOCTET) JPEG_EOI;
        
-       dinfo->src->next_input_byte= buf;
-       dinfo->src->bytes_in_buffer= 2;
+       dinfo->src->next_input_byte = buf;
+       dinfo->src->bytes_in_buffer = 2;
        
        return TRUE;
 }
 
 static void jpegmemsrcmgr_skip_input_data(j_decompress_ptr dinfo, long skipcnt)
 {
-       if (dinfo->src->bytes_in_buffer<skipcnt)
-               skipcnt= dinfo->src->bytes_in_buffer;
+       if (dinfo->src->bytes_in_buffer < skipcnt)
+               skipcnt = dinfo->src->bytes_in_buffer;
 
-       dinfo->src->next_input_byte+= skipcnt;
-       dinfo->src->bytes_in_buffer-= skipcnt;
+       dinfo->src->next_input_byte += skipcnt;
+       dinfo->src->bytes_in_buffer -= skipcnt;
 }
 
 static void jpegmemsrcmgr_term_source(j_decompress_ptr dinfo)
 {
-       numbytes-= dinfo->src->bytes_in_buffer;
+       numbytes -= dinfo->src->bytes_in_buffer;
        
        MEM_freeN(dinfo->src);
 }
 
 static void jpegmemsrcmgr_build(j_decompress_ptr dinfo, unsigned char *buffer, int bufsize)
 {
-       dinfo->src= MEM_mallocN(sizeof(*(dinfo->src)), "avi.jpegmemsrcmgr_build");
+       dinfo->src = MEM_mallocN(sizeof(*(dinfo->src)), "avi.jpegmemsrcmgr_build");
        
-       dinfo->src->init_source= jpegmemsrcmgr_init_source;
-       dinfo->src->fill_input_buffer= jpegmemsrcmgr_fill_input_buffer;
-       dinfo->src->skip_input_data= jpegmemsrcmgr_skip_input_data;
-       dinfo->src->resync_to_restart= jpeg_resync_to_restart;
-       dinfo->src->term_source= jpegmemsrcmgr_term_source;
+       dinfo->src->init_source = jpegmemsrcmgr_init_source;
+       dinfo->src->fill_input_buffer = jpegmemsrcmgr_fill_input_buffer;
+       dinfo->src->skip_input_data = jpegmemsrcmgr_skip_input_data;
+       dinfo->src->resync_to_restart = jpeg_resync_to_restart;
+       dinfo->src->term_source = jpegmemsrcmgr_term_source;
        
-       dinfo->src->bytes_in_buffer= bufsize;
-       dinfo->src->next_input_byte= buffer;
+       dinfo->src->bytes_in_buffer = bufsize;
+       dinfo->src->next_input_byte = buffer;
 
-       numbytes= bufsize;
+       numbytes = bufsize;
 }
index db9719c171ddbb09216cd30fc10be664e66356dd..7de91318ecf9e90ddebe6668d1d986cada355680 100644 (file)
@@ -54,78 +54,78 @@ AviError AVI_set_compress_option(AviMovie *movie, int option_type, int stream, A
                return AVI_ERROR_OPTION;
 
        switch (option_type) {
-       case AVI_OPTION_TYPE_MAIN:
-               switch (option) {
-               case AVI_OPTION_WIDTH:
-                       movie->header->Width = *((int *) opt_data);
-                       movie->header->SuggestedBufferSize = movie->header->Width*movie->header->Height*3;
-
-                       for (i=0; i < movie->header->Streams; i++) {
-                               if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
-                                       ((AviBitmapInfoHeader *) movie->streams[i].sf)->Width = *((int *) opt_data);
-                                       movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize;
-                                       movie->streams[i].sh.right = *((int *) opt_data);
-                                       ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize;
-                                       fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
-                                       awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
-                               }
-                       }
-
-                       break;
+               case AVI_OPTION_TYPE_MAIN:
+                       switch (option) {
+                               case AVI_OPTION_WIDTH:
+                                       movie->header->Width = *((int *) opt_data);
+                                       movie->header->SuggestedBufferSize = movie->header->Width * movie->header->Height * 3;
+
+                                       for (i = 0; i < movie->header->Streams; i++) {
+                                               if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
+                                                       ((AviBitmapInfoHeader *) movie->streams[i].sf)->Width = *((int *) opt_data);
+                                                       movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize;
+                                                       movie->streams[i].sh.right = *((int *) opt_data);
+                                                       ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize;
+                                                       fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET);
+                                                       awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
+                                               }
+                                       }
+
+                                       break;
+
+                               case AVI_OPTION_HEIGHT:
+                                       movie->header->Height = *((int *) opt_data);
+                                       movie->header->SuggestedBufferSize = movie->header->Width * movie->header->Height * 3;
+
+                                       for (i = 0; i < movie->header->Streams; i++) {
+                                               if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
+                                                       ((AviBitmapInfoHeader *) movie->streams[i].sf)->Height = *((int *) opt_data);
+                                                       movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize;
+                                                       movie->streams[i].sh.bottom = *((int *) opt_data);
+                                                       ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize;
+                                                       fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET);
+                                                       awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
+                                               }
+                                       }
+
+                                       break;
+
+                               case AVI_OPTION_QUALITY:
+                                       for (i = 0; i < movie->header->Streams; i++) {
+                                               if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
+                                                       movie->streams[i].sh.Quality = (*((int *) opt_data)) * 100;
+                                                       fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET);
+                                                       awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
+                                               }
+                                       }
+                                       break;
+
+                               case AVI_OPTION_FRAMERATE:
+                                       useconds = (int)(1000000 / (*((double *) opt_data)));
+                                       if (useconds)
+                                               movie->header->MicroSecPerFrame = useconds;
+
+                                       for (i = 0; i < movie->header->Streams; i++) {
+                                               if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
+                                                       movie->streams[i].sh.Scale = movie->header->MicroSecPerFrame;
+                                                       fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET);
+                                                       awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
+                                               }
+                                       }
 
-               case AVI_OPTION_HEIGHT:
-                       movie->header->Height = *((int *) opt_data);
-                       movie->header->SuggestedBufferSize = movie->header->Width*movie->header->Height*3;
-
-                       for (i=0; i < movie->header->Streams; i++) {
-                               if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
-                                       ((AviBitmapInfoHeader *) movie->streams[i].sf)->Height = *((int *) opt_data);
-                                       movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize;
-                                       movie->streams[i].sh.bottom = *((int *) opt_data);
-                                       ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize;
-                                       fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
-                                       awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
-                               }
                        }
 
-                       break;
+                       fseek(movie->fp, movie->offset_table[0], SEEK_SET);
+                       awrite(movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH);
 
-               case AVI_OPTION_QUALITY:
-                       for (i=0; i < movie->header->Streams; i++) {
-                               if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
-                                       movie->streams[i].sh.Quality = (*((int *) opt_data))*100;
-                                       fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
-                                       awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
-                               }
-                       }
                        break;
-
-               case AVI_OPTION_FRAMERATE:
-                       useconds = (int)(1000000/(*((double *) opt_data)));
-                       if (useconds)
-                               movie->header->MicroSecPerFrame = useconds;
-
-                       for (i=0; i < movie->header->Streams; i++) {
-                               if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) {
-                                       movie->streams[i].sh.Scale = movie->header->MicroSecPerFrame;
-                                       fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET);
-                                       awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH);
-                               }
-                       }
-
-               }
-
-               fseek (movie->fp, movie->offset_table[0], SEEK_SET);
-               awrite (movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH);
-
-               break;
-       case AVI_OPTION_TYPE_STRH:
-               break;
-       case AVI_OPTION_TYPE_STRF:
-               break;
-       default:
-               return AVI_ERROR_OPTION;
-               break;
+               case AVI_OPTION_TYPE_STRH:
+                       break;
+               case AVI_OPTION_TYPE_STRF:
+                       break;
+               default:
+                       return AVI_ERROR_OPTION;
+                       break;
        }
 
        return AVI_ERROR_NONE;
index 7b4958ca02641b2e035872b1b9256d65240fb6db..84630f09fe58b3983cafb8204f3369c3a46bef1e 100644 (file)
 #include "MEM_guardedalloc.h"
 #include "rgb32.h"
 
-void *avi_converter_from_rgb32 (AviMovie *movie, int stream, unsigned char *buffer, int *size)
+void *avi_converter_from_rgb32(AviMovie *movie, int stream, unsigned char *buffer, int *size)
 {
        int y, x, rowstridea, rowstrideb;
        unsigned char *buf;
 
        (void)stream; /* unused */
 
-       buf = MEM_mallocN (movie->header->Height * movie->header->Width * 3, "fromrgb32buf");
+       buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromrgb32buf");
        *size = movie->header->Height * movie->header->Width * 3;
 
-       rowstridea = movie->header->Width*3;
-       rowstrideb = movie->header->Width*4;
+       rowstridea = movie->header->Width * 3;
+       rowstrideb = movie->header->Width * 4;
 
-       for (y=0; y < movie->header->Height; y++) {
-               for (x=0; x < movie->header->Width; x++) {
-                       buf[y*rowstridea + x*3 + 0] = buffer[y*rowstrideb + x*4 + 3];
-                       buf[y*rowstridea + x*3 + 1] = buffer[y*rowstrideb + x*4 + 2];
-                       buf[y*rowstridea + x*3 + 2] = buffer[y*rowstrideb + x*4 + 1];
+       for (y = 0; y < movie->header->Height; y++) {
+               for (x = 0; x < movie->header->Width; x++) {
+                       buf[y * rowstridea + x * 3 + 0] = buffer[y * rowstrideb + x * 4 + 3];
+                       buf[y * rowstridea + x * 3 + 1] = buffer[y * rowstrideb + x * 4 + 2];
+                       buf[y * rowstridea + x * 3 + 2] = buffer[y * rowstrideb + x * 4 + 1];
                }
        }
 
-       MEM_freeN (buffer);
+       MEM_freeN(buffer);
 
        return buf;
 }
 
-void *avi_converter_to_rgb32 (AviMovie *movie, int stream, unsigned char *buffer, int *size)
+void *avi_converter_to_rgb32(AviMovie *movie, int stream, unsigned char *buffer, int *size)
 {
        int i;
        unsigned char *buf;
@@ -73,20 +73,20 @@ void *avi_converter_to_rgb32 (AviMovie *movie, int stream, unsigned char *buffer
 
        (void)stream; /* unused */
 
-       buf= MEM_mallocN (movie->header->Height * movie->header->Width * 4, "torgb32buf");
-       *size= movie->header->Height * movie->header->Width * 4;
+       buf = MEM_mallocN(movie->header->Height * movie->header->Width * 4, "torgb32buf");
+       *size = movie->header->Height * movie->header->Width * 4;
 
        memset(buf, 255, *size);
 
-       to= buf; from= buffer;
-       i=movie->header->Height*movie->header->Width;
+       to = buf; from = buffer;
+       i = movie->header->Height * movie->header->Width;
        
        while (i--) {
                memcpy(to, from, 3);
-               to+=4; from+=3;
+               to += 4; from += 3;
        }
 
-       MEM_freeN (buffer);
+       MEM_freeN(buffer);
 
        return buf;
 }
index e7e1577c6b483afbf9d088ec66363c016b7b114a..fcb56bf8027507bc6637fc6f2084b15854949721 100644 (file)
@@ -508,9 +508,10 @@ struct ShadeResult;
 #define SH_NODE_LAYER_WEIGHT                   160
 #define SH_NODE_VOLUME_TRANSPARENT             161
 #define SH_NODE_VOLUME_ISOTROPIC               162
-#define SH_NODE_GAMMA                          163
-#define SH_NODE_TEX_CHECKER                    164
+#define SH_NODE_GAMMA                                  163
+#define SH_NODE_TEX_CHECKER                            164
 #define SH_NODE_BRIGHTCONTRAST                 165
+#define SH_NODE_LIGHT_FALLOFF                  166
 
 /* custom defines options for Material node */
 #define SH_NODE_MAT_DIFF   1
index 7832947be73f246de91859077f35f5407579add1..07122a1ec4deea7dc3da7dd6ed0d80d441def5b1 100644 (file)
@@ -1969,6 +1969,7 @@ static void registerShaderNodes(bNodeTreeType *ttype)
        register_node_type_sh_attribute(ttype);
        register_node_type_sh_geometry(ttype);
        register_node_type_sh_light_path(ttype);
+       register_node_type_sh_light_falloff(ttype);
        register_node_type_sh_fresnel(ttype);
        register_node_type_sh_layer_weight(ttype);
        register_node_type_sh_tex_coord(ttype);
index 80e20acbe4895635c82cbdcba8d0751089bb9793..41fa7e1ed38852c0e870a58fd21aa4a3f759f1b7 100644 (file)
@@ -31,6 +31,7 @@ struct ExportSettings
 {
  public:
  bool selected;
+ bool apply_modifiers;
  bool second_life;
  char *filepath;
 };
index 8e4fa057daf6649fa1db2f10457aafbf575df94c..05d4080dcb6db61e1f5a0c24a6421772a35dd2b9 100644 (file)
 #include "GeometryExporter.h"
 
 #include "DNA_meshdata_types.h"
+
+extern "C" {
+    #include "BKE_DerivedMesh.h"
+       #include "BKE_main.h"
+       #include "BKE_global.h"
+       #include "BKE_library.h"
+}
+
+
 #include "BKE_customdata.h"
 #include "BKE_material.h"
 #include "BKE_mesh.h"
-
 #include "collada_internal.h"
 
 // TODO: optimize UV sets by making indexed list with duplicates removed
@@ -57,6 +65,25 @@ void GeometryExporter::exportGeom(Scene *sce)
        closeLibrary();
 }
 
+Mesh * GeometryExporter::get_mesh(Object *ob, int apply_modifiers)
+{
+       Mesh *tmpmesh;
+       if (!apply_modifiers)
+       {
+               tmpmesh = (Mesh*)ob->data;
+       }
+       else
+       {
+               CustomDataMask mask = CD_MASK_MESH;
+               DerivedMesh *dm     = mesh_create_derived_view(mScene, ob, mask);
+               tmpmesh             = BKE_mesh_add("ColladaMesh"); // name is not important here
+               DM_to_mesh(dm, tmpmesh, ob);
+               dm->release(dm);
+       }
+       BKE_mesh_tessface_ensure(tmpmesh);
+       return tmpmesh;
+}
+
 void GeometryExporter::operator()(Object *ob)
 {
        // XXX don't use DerivedMesh, Mesh instead?
@@ -64,8 +91,8 @@ void GeometryExporter::operator()(Object *ob)
 #if 0          
        DerivedMesh *dm = mesh_get_derived_final(mScene, ob, CD_MASK_BAREMESH);
 #endif
-       Mesh *me = (Mesh*)ob->data;
-       BKE_mesh_tessface_ensure(me);
+
+       Mesh *me = get_mesh(ob, this->export_settings->apply_modifiers);
 
        std::string geom_id = get_geometry_id(ob);
        std::string geom_name = id_name(ob->data);
@@ -110,11 +137,11 @@ void GeometryExporter::operator()(Object *ob)
        // XXX slow             
        if (ob->totcol) {
                for (int a = 0; a < ob->totcol; a++)    {
-                       createPolylist(a, has_uvs, has_color, ob, geom_id, norind);
+                       createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind);
                }
        }
        else {
-               createPolylist(0, has_uvs, has_color, ob, geom_id, norind);
+               createPolylist(0, has_uvs, has_color, ob, me, geom_id, norind);
        }
        
        closeMesh();
@@ -124,7 +151,12 @@ void GeometryExporter::operator()(Object *ob)
        }
        
        closeGeometry();
-       
+
+       if (this->export_settings->apply_modifiers)
+       {
+               BKE_libblock_free_us(&(G.main->mesh), me);
+       }
+
 #if 0
        dm->release(dm);
 #endif
@@ -135,10 +167,10 @@ void GeometryExporter::createPolylist(short material_index,
                                        bool has_uvs,
                                        bool has_color,
                                        Object *ob,
+                                       Mesh *me,
                                        std::string& geom_id,
                                        std::vector<Face>& norind)
 {
-       Mesh *me = (Mesh*)ob->data;
        MFace *mfaces = me->mface;
        int totfaces = me->totface;
 
index 5d79fabb713c97b8b5223fd326db29c1e38caf14..55dc179e5e29a1702d8e21a4d90b83e884c3c585 100644 (file)
@@ -69,6 +69,7 @@ public:
                                                bool has_uvs,
                                                bool has_color,
                                                Object *ob,
+                                               Mesh   *me,
                                                std::string& geom_id,
                                                std::vector<Face>& norind);
        
@@ -98,6 +99,8 @@ private:
        std::set<std::string> exportedGeometry;
        
        const ExportSettings *export_settings;
+
+       Mesh * get_mesh(Object *ob, int apply_modifiers);
 };
 
 struct GeometryFunctor {
index 70bf0556b5b02bd97326a6b2086bbd275eff2c7a..ae024ec52a731e552bab9db840830a122e5c5a74 100644 (file)
@@ -49,13 +49,14 @@ extern "C"
                return 0;
        }
 
-       int collada_export(Scene *sce, const char *filepath, int selected, int second_life)
+       int collada_export(Scene *sce, const char *filepath, int selected, int apply_modifiers, int second_life)
        {
                ExportSettings export_settings;
                
-               export_settings.selected = selected != 0;
-               export_settings.second_life = second_life != 0;
-               export_settings.filepath = (char *)filepath;
+               export_settings.selected        = selected != 0;
+               export_settings.apply_modifiers = apply_modifiers != 0;
+               export_settings.second_life     = second_life != 0;
+               export_settings.filepath        = (char *)filepath;
 
                /* annoying, collada crashes if file cant be created! [#27162] */
                if (!BLI_exists(filepath)) {
index f8afc79744799cfdd37b725155182138d6b4eb96..f335796f7996fa139bfbbb6e4ad88a18a3c3167f 100644 (file)
@@ -37,7 +37,7 @@ extern "C" {
         * both return 1 on success, 0 on error
         */
        int collada_import(bContext *C, const char *filepath);
-       int collada_export(Scene *sce, const char *filepath, int selected, int second_life);
+       int collada_export(Scene *sce, const char *filepath, int selected, int apply_modifiers, int second_life);
 #ifdef __cplusplus
 }
 #endif
index e689c201b21ab7c77e3f14927e10c19fc2195207..eccc1e5ed1a40e5c145ce983d7a11a3e5d0d842a 100644 (file)
@@ -614,7 +614,7 @@ static int edbm_extrude_faces_exec(bContext *C, wmOperator *op)
 
        edbm_extrude_face_indiv(em, op, BM_ELEM_SELECT, nor);
        
-       WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit);
+       EDBM_update_generic(C, em, TRUE);
        
        return OPERATOR_FINISHED;
 }
index 5352bbd0e0fbee03e00008d32163948d9eed4efa..d7e55ae27df839ad8bb88a7463f4baddcb547368 100644 (file)
@@ -77,7 +77,8 @@ DefNode( ShaderNode,     SH_NODE_VOLUME_TRANSPARENT, 0,                      "VO
 DefNode( ShaderNode,     SH_NODE_VOLUME_ISOTROPIC,   0,                      "VOLUME_ISOTROPIC",   VolumeIsotropic,  "Isotropic Volume",  ""       )
 DefNode( ShaderNode,     SH_NODE_EMISSION,           0,                      "EMISSION",           Emission,         "Emission",          ""       )
 DefNode( ShaderNode,     SH_NODE_NEW_GEOMETRY,       0,                      "NEW_GEOMETRY",       NewGeometry,      "Geometry",          ""       )
-DefNode( ShaderNode,     SH_NODE_LIGHT_PATH,         0,                      "LIGHT_PATH",         Light_path,       "Light Path",        ""       )
+DefNode( ShaderNode,     SH_NODE_LIGHT_PATH,         0,                      "LIGHT_PATH",         LightPath,       "Light Path",         ""       )
+DefNode( ShaderNode,     SH_NODE_LIGHT_FALLOFF,      0,                      "LIGHT_FALLOFF",      LightFalloff,    "Light Falloff",      ""       )
 DefNode( ShaderNode,     SH_NODE_TEX_IMAGE,          def_sh_tex_image,       "TEX_IMAGE",          TexImage,         "Image Texture",     ""       )
 DefNode( ShaderNode,     SH_NODE_TEX_ENVIRONMENT,    def_sh_tex_environment, "TEX_ENVIRONMENT",    TexEnvironment,   "Environment Texture",""      )
 DefNode( ShaderNode,     SH_NODE_TEX_SKY,            def_sh_tex_sky,         "TEX_SKY",            TexSky,           "Sky Texture",       ""       )
index e3bb6e7b58ad04aa21a8b861afff6347904b1852..ca01d61f630d4caddebb80b7aa26ed0311dc34e6 100644 (file)
@@ -85,9 +85,9 @@ static void rna_SceneRender_get_frame_path(RenderData *rd, int frame, char *name
 /* don't remove this, as COLLADA exporting cannot be done through operators in render() callback. */
 #include "../../collada/collada.h"
 
-static void rna_Scene_collada_export(Scene *scene, const char *filepath, int selected, int second_life)
+static void rna_Scene_collada_export(Scene *scene, const char *filepath, int selected, int apply_modifiers, int second_life)
 {
-       collada_export(scene, filepath, selected, second_life);
+       collada_export(scene, filepath, selected, apply_modifiers, second_life);
 }
 
 #endif
@@ -115,7 +115,8 @@ void RNA_api_scene(StructRNA *srna)
        parm = RNA_def_string(func, "filepath", "", FILE_MAX, "File Path", "File path to write Collada file");
        RNA_def_property_flag(parm, PROP_REQUIRED);
        RNA_def_property_subtype(parm, PROP_FILEPATH); /* allow non utf8 */
-       parm = RNA_def_boolean(func, "selected", 0, "Export only selected", "Export only selected elements");
+       parm = RNA_def_boolean(func, "selected", 0, "Selection Only", "Export only selected elements");
+       parm = RNA_def_boolean(func, "apply_modifiers", 0, "Apply Modifiers", "Apply modifiers (in Preview resolution)");
        parm = RNA_def_boolean(func, "second_life", 0, "Export for Second Life", "Compatibility mode for Second Life");
        RNA_def_function_ui_description(func, "Export to collada file");
 #endif
index 7a32e7d208406c82c90b4cbf794d0ec50515fa74..e3e873deabd12ff3da8010f84892ee4ec896dce0 100644 (file)
@@ -451,8 +451,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
                /* same as EM_solidify() in editmesh_lib.c */
                float *vert_angles = MEM_callocN(sizeof(float) * numVerts * 2, "mod_solid_pair"); /* 2 in 1 */
                float *vert_accum = vert_angles + numVerts;
-               float *face_angles = NULL;
-               BLI_array_staticdeclare(face_angles, 16); /* BM_NGON_STACK_SIZE */
                int j, vidx;
 
                face_nors = CustomData_get_layer(&dm->polyData, CD_NORMAL);
@@ -473,28 +471,28 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
                                mesh_calc_poly_normal(mp, &mloop[mp->loopstart], mvert, face_nors[i]);
                        
                        /* just added, calc the normal */
-                       BLI_array_empty(face_angles);
-                       BLI_array_reserve(face_angles, mp->totloop);
                        for (j = 0, ml = mloop + mp->loopstart; j < mp->totloop; j++, ml++) {
                                MLoop *ml_prev = ME_POLY_LOOP_PREV(mloop, mp, j);
                                MLoop *ml_next = ME_POLY_LOOP_NEXT(mloop, mp, j);
 
                                float e1[3], e2[3];
+                               float angle;
 
+                               /* TODO - we could speed this up by _not_ normalizing both verts each time
+                                * and always re-usingthe last vector. */
                                sub_v3_v3v3(e1, mvert[ml_next->v].co, mvert[ml->v].co);
                                sub_v3_v3v3(e2, mvert[ml_prev->v].co, mvert[ml->v].co);
-                               face_angles[j] = (float)M_PI - angle_v3v3(e1, e2);
-                       }
-                       
-                       for (j = 0, ml = mloop + mp->loopstart; j < mp->totloop; j++, ml++) {
+
+                               angle = (float)M_PI - angle_v3v3(e1, e2);
+                               if (angle < FLT_EPSILON) {
+                                       angle = FLT_EPSILON;
+                               }
+
                                vidx = ml->v;
-                               vert_accum[vidx] += face_angles[j];
-                               vert_angles[vidx] += shell_angle_to_dist(angle_normalized_v3v3(vert_nors[vidx], face_nors[i])) *
-                                                    face_angles[j];
+                               vert_accum[vidx] += angle;
+                               vert_angles[vidx] += shell_angle_to_dist(angle_normalized_v3v3(vert_nors[vidx], face_nors[i])) * angle;
                        }
                }
-       
-               BLI_array_free(face_angles);
 
                /* vertex group support */
                if (dvert) {
index 9bcbc91265c607d00494fadd2fe880d468da6e38..be9dd10b71d2dcdcc6d11ecb6124806a2686cf9c 100644 (file)
@@ -149,6 +149,7 @@ set(SRC
        shader/nodes/node_shader_volume_transparent.c
        shader/nodes/node_shader_volume_isotropic.c
        shader/nodes/node_shader_light_path.c
+       shader/nodes/node_shader_light_falloff.c
        shader/nodes/node_shader_mix_shader.c
        shader/nodes/node_shader_add_shader.c
        shader/nodes/node_shader_output_lamp.c
index d2b3a61971b5595f38c3c4f5473145f8988557b6..3d93f41cfe54d23a53b2199b6b4b393f511c12ac 100644 (file)
@@ -73,6 +73,7 @@ void register_node_type_sh_hue_sat(struct bNodeTreeType *ttype);
 void register_node_type_sh_attribute(struct bNodeTreeType *ttype);
 void register_node_type_sh_geometry(struct bNodeTreeType *ttype);
 void register_node_type_sh_light_path(struct bNodeTreeType *ttype);
+void register_node_type_sh_light_falloff(struct bNodeTreeType *ttype);
 void register_node_type_sh_fresnel(struct bNodeTreeType *ttype);
 void register_node_type_sh_layer_weight(struct bNodeTreeType *ttype);
 void register_node_type_sh_tex_coord(struct bNodeTreeType *ttype);
index 01e5147d7883c357064eb421ba9cc7e62e0fc4b0..ed57e305fc93cda0f486341744d2310a53b60fef 100644 (file)
@@ -2148,7 +2148,7 @@ static int wm_collada_export_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED
 static int wm_collada_export_exec(bContext *C, wmOperator *op)
 {
        char filename[FILE_MAX];
-       int selected, second_life;
+       int selected, second_life, apply_modifiers;
        
        if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
                BKE_report(op->reports, RPT_ERROR, "No filename given");
@@ -2156,9 +2156,16 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
        }
 
        RNA_string_get(op->ptr, "filepath", filename);
-       selected = RNA_boolean_get(op->ptr, "selected");
-       second_life = RNA_boolean_get(op->ptr, "second_life");
-       if (collada_export(CTX_data_scene(C), filename, selected, second_life)) {
+
+       /* Options panel */
+       selected        = RNA_boolean_get(op->ptr, "selected");
+       second_life     = RNA_boolean_get(op->ptr, "second_life");
+       apply_modifiers = RNA_boolean_get(op->ptr, "apply_modifiers");
+
+       /* get editmode results */
+       ED_object_exit_editmode(C, 0);  /* 0 = does not exit editmode */
+
+       if (collada_export(CTX_data_scene(C), filename, selected, apply_modifiers, second_life)) {
                return OPERATOR_FINISHED;
        }
        else {
@@ -2177,8 +2184,10 @@ static void WM_OT_collada_export(wmOperatorType *ot)
        ot->poll = WM_operator_winactive;
        
        WM_operator_properties_filesel(ot, FOLDERFILE | COLLADAFILE, FILE_BLENDER, FILE_SAVE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY);
-       RNA_def_boolean(ot->srna, "selected", 0, "Export only selected",
+       RNA_def_boolean(ot->srna, "selected", 0, "Selection Only",
                        "Export only selected elements");
+       RNA_def_boolean(ot->srna, "apply_modifiers", 0, "Apply Modifiers",
+                       "Apply modifiers (Preview Resolution)");
        RNA_def_boolean(ot->srna, "second_life", 0, "Export for Second Life",
                        "Compatibility mode for Second Life");
 }