style cleanup: imbuf
authorCampbell Barton <ideasman42@gmail.com>
Wed, 16 May 2012 09:26:37 +0000 (09:26 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 16 May 2012 09:26:37 +0000 (09:26 +0000)
16 files changed:
source/blender/imbuf/intern/IMB_anim.h
source/blender/imbuf/intern/IMB_metadata.h
source/blender/imbuf/intern/anim_movie.c
source/blender/imbuf/intern/bmp.c
source/blender/imbuf/intern/cache.c
source/blender/imbuf/intern/indexer.c
source/blender/imbuf/intern/indexer_dv.c
source/blender/imbuf/intern/iris.c
source/blender/imbuf/intern/jp2.c
source/blender/imbuf/intern/moviecache.c
source/blender/imbuf/intern/openexr/openexr_multi.h
source/blender/imbuf/intern/radiance_hdr.c
source/blender/imbuf/intern/scaling.c
source/blender/imbuf/intern/thumbs.c
source/blender/imbuf/intern/thumbs_blend.c
source/blender/imbuf/intern/tiff.c

index 6920d49ff514a8c989b6e89d336a7acb5a9c39e6..7f4abd298902cc0e4fd0435f4591ba9599a6cbc0 100644 (file)
 #endif
 
 /* anim.curtype, runtime only */
-#define ANIM_NONE              0
-#define ANIM_SEQUENCE  (1 << 0)
-#define ANIM_MOVIE             (1 << 4)
-#define ANIM_AVI               (1 << 6)
-#define ANIM_QTIME             (1 << 7)
+#define ANIM_NONE       0
+#define ANIM_SEQUENCE   (1 << 0)
+#define ANIM_MOVIE      (1 << 4)
+#define ANIM_AVI        (1 << 6)
+#define ANIM_QTIME      (1 << 7)
 #define ANIM_FFMPEG     (1 << 8)
 #define ANIM_REDCODE    (1 << 9)
 
-#define MAXNUMSTREAMS          50
+#define MAXNUMSTREAMS       50
 
 struct _AviMovie;
 struct anim_index;
@@ -123,18 +123,18 @@ struct anim_index;
 struct anim {
        int ib_flags;
        int curtype;
-       int curposition;        /* index  0 = 1e,  1 = 2e, enz. */
+       int curposition;    /* index  0 = 1e,  1 = 2e, enz. */
        int duration;
        short frs_sec;
        float frs_sec_base;
        int x, y;
        
-               /* voor op nummer */
+       /* voor op nummer */
        char name[1024];
-               /* voor sequence */
+       /* voor sequence */
        char first[1024];
 
-               /* movie */
+       /* movie */
        void *movie;
        void *track;
        void *params;
@@ -144,21 +144,21 @@ struct anim {
        int preseek;
        int streamindex;
        
-               /* avi */
+       /* avi */
        struct _AviMovie *avi;
 
 #if defined(_WIN32) && !defined(FREE_WINDOWS)
-               /* windows avi */
+       /* windows avi */
        int avistreams;
        int firstvideo;
        int pfileopen;
-       PAVIFILE        pfile;
-       PAVISTREAM  pavi[MAXNUMSTREAMS];        // the current streams
-       PGETFRAME         pgf;
+       PAVIFILE pfile;
+       PAVISTREAM pavi[MAXNUMSTREAMS];     // the current streams
+       PGETFRAME pgf;
 #endif
 
 #ifdef WITH_QUICKTIME
-               /* quicktime */
+       /* quicktime */
        struct _QuicktimeMovie *qtime;
 #endif /* WITH_QUICKTIME */
 
@@ -173,14 +173,14 @@ struct anim {
        struct SwsContext *img_convert_ctx;
        int videoStream;
 
-       struct ImBuf * last_frame;
+       struct ImBuf *last_frame;
        int64_t last_pts;
        int64_t next_pts;
        AVPacket next_packet;
 #endif
 
 #ifdef WITH_REDCODE
-       struct redcode_handle * redcodeCtx;
+       struct redcode_handle *redcodeCtx;
 #endif
 
        char index_dir[768];
@@ -188,10 +188,9 @@ struct anim {
        int proxies_tried;
        int indices_tried;
        
-       struct anim * proxy_anim[IMB_PROXY_MAX_SLOT];
-       struct anim_index * curr_idx[IMB_TC_MAX_SLOT];
+       struct anim *proxy_anim[IMB_PROXY_MAX_SLOT];
+       struct anim_index *curr_idx[IMB_TC_MAX_SLOT];
 
 };
 
 #endif
-
index 336a5f95082ffb61bc387db2ca3d93d27c58bde9..4f512e04ef8287a59ddd65521ee7c04f4318530d 100644 (file)
@@ -37,8 +37,8 @@ struct ImBuf;
 
 typedef struct ImMetaData {
        struct ImMetaData *next, *prev;
-       charkey;
-       charvalue;
+       char *key;
+       char *value;
        int len;
 } ImMetaData;
 
@@ -52,7 +52,7 @@ typedef struct ImMetaData {
 
 
 /* free blender ImMetaData struct */
-void IMB_metadata_free(struct ImBufimg);
+void IMB_metadata_free(struct ImBuf *img);
 
 /** read the field from the image info into the field 
  *  \param img - the ImBuf that contains the image data
@@ -62,7 +62,7 @@ void IMB_metadata_free(struct ImBuf* img);
  *  \param len - length of value buffer allocated by user.
  *  \return    - 1 (true) if ImageInfo present and value for the key found, 0 (false) otherwise
  */
-int IMB_metadata_get_field(struct ImBuf* img, const char* key, char* value, int len);
+int IMB_metadata_get_field(struct ImBuf *img, const char *key, char *value, int len);
 
 /** set user data in the ImMetaData struct, which has to be allocated with IMB_metadata_create
  *  before calling this function.
@@ -71,7 +71,7 @@ int IMB_metadata_get_field(struct ImBuf* img, const char* key, char* value, int
  *  \param value - the data to be written to the field. zero terminated string
  *  \return    - 1 (true) if ImageInfo present, 0 (false) otherwise
  */
-int IMB_metadata_add_field(struct ImBuf* img, const char* key, const char* value);
+int IMB_metadata_add_field(struct ImBuf *img, const char *key, const char *value);
 
 /** delete the key/field par in the ImMetaData struct.
  * \param img - the ImBuf that contains the image data
index 5d8c65f79716b6656827a3d19a957678e32521f1..d8efdc3b870c158c6ebe2a9016567ab07e143cde 100644 (file)
@@ -119,10 +119,16 @@ int ismovie(const char *UNUSED(filepath))
        return 0;
 }
 
-       /* never called, just keep the linker happy */
-static int startmovie(struct anim *UNUSED(anim)) { return 1; }
-static ImBuf * movie_fetchibuf(struct anim *UNUSED(anim), int UNUSED(position)) { return NULL; }
-static void free_anim_movie(struct anim *UNUSED(anim)) { ; }
+/* never called, just keep the linker happy */
+static int startmovie(struct anim *UNUSED(anim)) {
+       return 1;
+}
+static ImBuf *movie_fetchibuf(struct anim *UNUSED(anim), int UNUSED(position)) {
+       return NULL;
+}
+static void free_anim_movie(struct anim *UNUSED(anim)) {
+       ;
+}
 
 
 #if defined(_WIN32)
@@ -131,24 +137,24 @@ static void free_anim_movie(struct anim *UNUSED(anim)) { ; }
 # define PATHSEPERATOR '/'
 #endif
 
-static int an_stringdec(const char *string, charhead, char *tail, unsigned short *numlen)
+static int an_stringdec(const char *string, char *head, char *tail, unsigned short *numlen)
 {
-       unsigned short len, nume, nums=0;
-       short i, found=FALSE;
+       unsigned short len, nume, nums = 0;
+       short i, found = FALSE;
 
-       len=strlen(string);
+       len = strlen(string);
        nume = len;
 
-       for (i=len-1;i>=0;i--) {
-               if (string[i]==PATHSEPERATOR) break;
+       for (i = len - 1; i >= 0; i--) {
+               if (string[i] == PATHSEPERATOR) break;
                if (isdigit(string[i])) {
                        if (found) {
-                               nums=i;
+                               nums = i;
                        }
                        else {
-                               nume=i;
-                               nums=i;
-                               found=TRUE;
+                               nume = i;
+                               nums = i;
+                               found = TRUE;
                        }
                }
                else {
@@ -156,15 +162,15 @@ static int an_stringdec(const char *string, char* head, char *tail, unsigned sho
                }
        }
        if (found) {
-               strcpy(tail, &string[nume+1]);
+               strcpy(tail, &string[nume + 1]);
                strcpy(head, string);
-               head[nums]= '\0';
-               *numlen=nume-nums+1;
+               head[nums] = '\0';
+               *numlen = nume - nums + 1;
                return ((int)atoi(&(string[nums])));
        }
-       tail[0]= '\0';
+       tail[0] = '\0';
        strcpy(head, string);
-       *numlen=0;
+       *numlen = 0;
        return TRUE;
 }
 
@@ -174,7 +180,7 @@ static void an_stringenc(char *string, const char *head, const char *tail, unsig
        BLI_stringenc(string, head, tail, numlen, pic);
 }
 
-static void free_anim_avi (struct anim *anim)
+static void free_anim_avi(struct anim *anim)
 {
 #if defined(_WIN32) && !defined(FREE_WINDOWS)
        int i;
@@ -183,8 +189,8 @@ static void free_anim_avi (struct anim *anim)
        if (anim == NULL) return;
        if (anim->avi == NULL) return;
 
-       AVI_close (anim->avi);
-       MEM_freeN (anim->avi);
+       AVI_close(anim->avi);
+       MEM_freeN(anim->avi);
        anim->avi = NULL;
 
 #if defined(_WIN32) && !defined(FREE_WINDOWS)
@@ -210,13 +216,13 @@ static void free_anim_avi (struct anim *anim)
 }
 
 #ifdef WITH_FFMPEG
-static void free_anim_ffmpeg(struct anim * anim);
+static void free_anim_ffmpeg(struct anim *anim);
 #endif
 #ifdef WITH_REDCODE
-static void free_anim_redcode(struct anim * anim);
+static void free_anim_redcode(struct anim *anim);
 #endif
 
-void IMB_free_anim(struct anim * anim)
+void IMB_free_anim(struct anim *anim)
 {
        if (anim == NULL) {
                printf("free anim, anim == NULL\n");
@@ -240,7 +246,7 @@ void IMB_free_anim(struct anim * anim)
        MEM_freeN(anim);
 }
 
-void IMB_close_anim(struct anim * anim)
+void IMB_close_anim(struct anim *anim)
 {
        if (anim == NULL) return;
 
@@ -255,11 +261,10 @@ void IMB_close_anim_proxies(struct anim *anim)
        IMB_free_indices(anim);
 }
 
-struct anim * IMB_open_anim(const char * name, int ib_flags, int streamindex)
-{
-       struct anim * anim;
+struct anim *IMB_open_anim(const char *name, int ib_flags, int streamindex){
+       struct anim *anim;
 
-       anim = (struct anim*)MEM_callocN(sizeof(struct anim), "anim struct");
+       anim = (struct anim *)MEM_callocN(sizeof(struct anim), "anim struct");
        if (anim != NULL) {
                BLI_strncpy(anim->name, name, sizeof(anim->name));
                anim->ib_flags = ib_flags;
@@ -269,12 +274,12 @@ struct anim * IMB_open_anim(const char * name, int ib_flags, int streamindex)
 }
 
 
-static int startavi (struct anim *anim)
+static int startavi(struct anim *anim)
 {
 
        AviError avierror;
 #if defined(_WIN32) && !defined(FREE_WINDOWS)
-       HRESULT hr;
+       HRESULT hr;
        int i, firstvideo = -1;
        int streamcount;
        BYTE abFormat[1024];
@@ -285,14 +290,14 @@ static int startavi (struct anim *anim)
        streamcount = anim->streamindex;
 #endif
 
-       anim->avi = MEM_callocN (sizeof(AviMovie), "animavi");
+       anim->avi = MEM_callocN(sizeof(AviMovie), "animavi");
 
        if (anim->avi == NULL) {
                printf("Can't open avi: %s\n", anim->name);
                return -1;
        }
 
-       avierror = AVI_open_movie (anim->name, anim->avi);
+       avierror = AVI_open_movie(anim->name, anim->avi);
 
 #if defined(_WIN32) && !defined(FREE_WINDOWS)
        if (avierror == AVI_ERROR_COMPRESSION) {
@@ -329,8 +334,8 @@ static int startavi (struct anim *anim)
                                                FIXCC(avis.fccHandler);
                                                FIXCC(avis.fccType);
                                                printf("Can't find AVI decoder for type : %4.4hs/%4.4hs\n",
-                                                       (LPSTR)&avis.fccType,
-                                                       (LPSTR)&avis.fccHandler);
+                                                      (LPSTR)&avis.fccType,
+                                                      (LPSTR)&avis.fccHandler);
                                        }
                                }
                        }
@@ -357,7 +362,7 @@ static int startavi (struct anim *anim)
 
        if (avierror != AVI_ERROR_NONE) {
                AVI_print_error(avierror);
-               printf ("Error loading avi: %s\n", anim->name);         
+               printf("Error loading avi: %s\n", anim->name);
                free_anim_avi(anim);
                return -1;
        }
@@ -379,7 +384,7 @@ static int startavi (struct anim *anim)
        return 0;
 }
 
-static ImBuf * avi_fetchibuf (struct anim *anim, int position)
+static ImBuf *avi_fetchibuf(struct anim *anim, int position)
 {
        ImBuf *ibuf = NULL;
        int *tmp;
@@ -403,23 +408,23 @@ static ImBuf * avi_fetchibuf (struct anim *anim, int position)
 #else
        if (1) {
 #endif
-               ibuf = IMB_allocImBuf (anim->x, anim->y, 24, IB_rect);
+               ibuf = IMB_allocImBuf(anim->x, anim->y, 24, IB_rect);
 
-               tmp = AVI_read_frame (anim->avi, AVI_FORMAT_RGB32, position,
-                       AVI_get_stream(anim->avi, AVIST_VIDEO, 0));
+               tmp = AVI_read_frame(anim->avi, AVI_FORMAT_RGB32, position,
+                                    AVI_get_stream(anim->avi, AVIST_VIDEO, 0));
                
                if (tmp == NULL) {
-                       printf ("Error reading frame from AVI");
-                       IMB_freeImBuf (ibuf);
+                       printf("Error reading frame from AVI");
+                       IMB_freeImBuf(ibuf);
                        return NULL;
                }
 
-               for (y=0; y < anim->y; y++) {
-                       memcpy (&(ibuf->rect)[((anim->y-y)-1)*anim->x],  &tmp[y*anim->x],  
-                               anim->x * 4);
+               for (y = 0; y < anim->y; y++) {
+                       memcpy(&(ibuf->rect)[((anim->y - y) - 1) * anim->x],  &tmp[y * anim->x],
+                              anim->x * 4);
                }
                
-               MEM_freeN (tmp);
+               MEM_freeN(tmp);
        }
        
        ibuf->profile = IB_PROFILE_SRGB;
@@ -431,9 +436,9 @@ static ImBuf * avi_fetchibuf (struct anim *anim, int position)
 
 extern void do_init_ffmpeg(void);
 
-static int startffmpeg(struct anim * anim)
+static int startffmpeg(struct anim *anim)
 {
-       int            i, videoStream;
+       int i, videoStream;
 
        AVCodec *pCodec;
        AVFormatContext *pFormatCtx;
@@ -455,11 +460,11 @@ static int startffmpeg(struct anim * anim)
 
        do_init_ffmpeg();
 
-       if (av_open_input_file(&pFormatCtx, anim->name, NULL, 0, NULL)!=0) {
+       if (av_open_input_file(&pFormatCtx, anim->name, NULL, 0, NULL) != 0) {
                return -1;
        }
 
-       if (av_find_stream_info(pFormatCtx)<0) {
+       if (av_find_stream_info(pFormatCtx) < 0) {
                av_close_input_file(pFormatCtx);
                return -1;
        }
@@ -480,7 +485,7 @@ static int startffmpeg(struct anim * anim)
                        break;
                }
 
-       if (videoStream==-1) {
+       if (videoStream == -1) {
                av_close_input_file(pFormatCtx);
                return -1;
        }
@@ -505,7 +510,7 @@ static int startffmpeg(struct anim * anim)
                              av_q2d(pFormatCtx->streams[videoStream]->r_frame_rate) /
                              AV_TIME_BASE);
 
-       frs_num = pFormatCtx->streams[videoStream]->r_frame_rate.num;
+       frs_num = pFormatCtx->streams[videoStream]->r_frame_rate.num;
        frs_den = pFormatCtx->streams[videoStream]->r_frame_rate.den;
 
        frs_den *= AV_TIME_BASE;
@@ -543,9 +548,10 @@ static int startffmpeg(struct anim * anim)
        anim->pFrameRGB = avcodec_alloc_frame();
 
        if (avpicture_get_size(PIX_FMT_RGBA, anim->x, anim->y)
-               != anim->x * anim->y * 4) {
-               fprintf (stderr,
-                        "ffmpeg has changed alloc scheme ... ARGHHH!\n");
+           != anim->x * anim->y * 4)
+       {
+               fprintf(stderr,
+                       "ffmpeg has changed alloc scheme ... ARGHHH!\n");
                avcodec_close(anim->pCodecCtx);
                av_close_input_file(anim->pFormatCtx);
                av_free(anim->pFrameRGB);
@@ -556,7 +562,7 @@ static int startffmpeg(struct anim * anim)
        }
 
        if (anim->ib_flags & IB_animdeinterlace) {
-               avpicture_fill((AVPicture*) anim->pFrameDeinterlaced,
+               avpicture_fill((AVPicture *) anim->pFrameDeinterlaced,
                               MEM_callocN(avpicture_get_size(
                                               anim->pCodecCtx->pix_fmt,
                                               anim->x, anim->y),
@@ -572,18 +578,18 @@ static int startffmpeg(struct anim * anim)
        }
        
        anim->img_convert_ctx = sws_getContext(
-               anim->pCodecCtx->width,
-               anim->pCodecCtx->height,
-               anim->pCodecCtx->pix_fmt,
-               anim->pCodecCtx->width,
-               anim->pCodecCtx->height,
-               PIX_FMT_RGBA,
-               SWS_FAST_BILINEAR | SWS_PRINT_INFO,
-               NULL, NULL, NULL);
+               anim->pCodecCtx->width,
+               anim->pCodecCtx->height,
+               anim->pCodecCtx->pix_fmt,
+               anim->pCodecCtx->width,
+               anim->pCodecCtx->height,
+               PIX_FMT_RGBA,
+               SWS_FAST_BILINEAR | SWS_PRINT_INFO,
+               NULL, NULL, NULL);
                
        if (!anim->img_convert_ctx) {
-               fprintf (stderr,
-                        "Can't transform color space??? Bailing out...\n");
+               fprintf(stderr,
+                       "Can't transform color space??? Bailing out...\n");
                avcodec_close(anim->pCodecCtx);
                av_close_input_file(anim->pFormatCtx);
                av_free(anim->pFrameRGB);
@@ -595,17 +601,17 @@ static int startffmpeg(struct anim * anim)
 
 #ifdef FFMPEG_SWSCALE_COLOR_SPACE_SUPPORT
        /* Try do detect if input has 0-255 YCbCR range (JFIF Jpeg MotionJpeg) */
-       if (!sws_getColorspaceDetails(anim->img_convert_ctx, (int**)&inv_table, &srcRange,
-               &table, &dstRange, &brightness, &contrast, &saturation)) {
+       if (!sws_getColorspaceDetails(anim->img_convert_ctx, (int **)&inv_table, &srcRange,
+                                     &table, &dstRange, &brightness, &contrast, &saturation)) {
 
                srcRange = srcRange || anim->pCodecCtx->color_range == AVCOL_RANGE_JPEG;
                inv_table = sws_getCoefficients(anim->pCodecCtx->colorspace);
 
                if (sws_setColorspaceDetails(anim->img_convert_ctx, (int *)inv_table, srcRange,
-                       table, dstRange, brightness, contrast, saturation)) {
+                                            table, dstRange, brightness, contrast, saturation)) {
 
                        printf("Warning: Could not set libswscale colorspace details.\n");
-                       }
+               }
        }
        else {
                printf("Warning: Could not set libswscale colorspace details.\n");
@@ -621,10 +627,10 @@ static int startffmpeg(struct anim * anim)
  * Output is anim->last_frame
  */
 
-static void ffmpeg_postprocess(struct anim * anim)
+static void ffmpeg_postprocess(struct anim *anim)
 {
-       AVFrame * input = anim->pFrame;
-       ImBuf * ibuf = anim->last_frame;
+       AVFrame *input = anim->pFrame;
+       ImBuf *ibuf = anim->last_frame;
        int filter_y = 0;
 
        ibuf->profile = IB_PROFILE_SRGB;
@@ -635,11 +641,11 @@ static void ffmpeg_postprocess(struct anim * anim)
 
        /* This means the data wasnt read properly, 
         * this check stops crashing */
-       if (input->data[0]==0 && input->data[1]==0 &&
-           input->data[2]==0 && input->data[3]==0)
+       if (input->data[0] == 0 && input->data[1] == 0 &&
+           input->data[2] == 0 && input->data[3] == 0)
        {
                fprintf(stderr, "ffmpeg_fetchibuf: "
-                       "data not read properly...\n");
+                       "data not read properly...\n");
                return;
        }
 
@@ -651,13 +657,13 @@ static void ffmpeg_postprocess(struct anim * anim)
 
        if (anim->ib_flags & IB_animdeinterlace) {
                if (avpicture_deinterlace(
-                           (AVPicture*) 
-                           anim->pFrameDeinterlaced,
-                           (const AVPicture*)
-                           anim->pFrame,
-                           anim->pCodecCtx->pix_fmt,
-                           anim->pCodecCtx->width,
-                           anim->pCodecCtx->height) < 0)
+                       (AVPicture *)
+                       anim->pFrameDeinterlaced,
+                       (const AVPicture *)
+                       anim->pFrame,
+                       anim->pCodecCtx->pix_fmt,
+                       anim->pCodecCtx->width,
+                       anim->pCodecCtx->height) < 0)
                {
                        filter_y = TRUE;
                }
@@ -666,37 +672,37 @@ static void ffmpeg_postprocess(struct anim * anim)
                }
        }
        
-       avpicture_fill((AVPicture*) anim->pFrameRGB,
-                      (unsigned char*) ibuf->rect,
+       avpicture_fill((AVPicture *) anim->pFrameRGB,
+                      (unsigned char *) ibuf->rect,
                       PIX_FMT_RGBA, anim->x, anim->y);
 
        if (ENDIAN_ORDER == B_ENDIAN) {
-               int * dstStride   = anim->pFrameRGB->linesize;
-               uint8_t** dst     = anim->pFrameRGB->data;
+               int *dstStride   = anim->pFrameRGB->linesize;
+               uint8_t **dst     = anim->pFrameRGB->data;
                int dstStride2[4] = { dstStride[0], 0, 0, 0 };
-               uint8_tdst2[4]  = { dst[0], 0, 0, 0 };
+               uint8_t *dst2[4]  = { dst[0], 0, 0, 0 };
                int x, y, h, w;
-               unsigned charbottom;
-               unsigned chartop;
+               unsigned char *bottom;
+               unsigned char *top;
                
                sws_scale(anim->img_convert_ctx,
-                         (const uint8_t * const *)input->data,
+                         (const uint8_t *const *)input->data,
                          input->linesize,
                          0,
                          anim->pCodecCtx->height,
                          dst2,
                          dstStride2);
                
-               bottom = (unsigned char*) ibuf->rect;
-               top = bottom + ibuf->x * (ibuf->y-1) * 4;
+               bottom = (unsigned char *) ibuf->rect;
+               top = bottom + ibuf->x * (ibuf->y - 1) * 4;
                
                h = (ibuf->y + 1) / 2;
                w = ibuf->x;
                
                for (y = 0; y < h; y++) {
                        unsigned char tmp[4];
-                       unsigned int * tmp_l =
-                               (unsigned int*) tmp;
+                       unsigned int *tmp_l =
+                           (unsigned int *) tmp;
                        
                        for (x = 0; x < w; x++) {
                                tmp[0] = bottom[0];
@@ -709,23 +715,23 @@ static void ffmpeg_postprocess(struct anim * anim)
                                bottom[2] = top[2];
                                bottom[3] = top[3];
                                
-                               *(unsigned int*) top = *tmp_l;
+                               *(unsigned int *) top = *tmp_l;
                                
-                               bottom +=4;
+                               bottom += 4;
                                top += 4;
                        }
                        top -= 8 * w;
                }
        }
        else {
-               int * dstStride   = anim->pFrameRGB->linesize;
-               uint8_t** dst     = anim->pFrameRGB->data;
+               int *dstStride   = anim->pFrameRGB->linesize;
+               uint8_t **dst     = anim->pFrameRGB->data;
                int dstStride2[4] = { -dstStride[0], 0, 0, 0 };
-               uint8_t* dst2[4]  = { dst[0] + (anim->y - 1)*dstStride[0],
-                                     0, 0, 0 };
+               uint8_t *dst2[4]  = { dst[0] + (anim->y - 1) * dstStride[0],
+                                         0, 0, 0 };
                
                sws_scale(anim->img_convert_ctx,
-                         (const uint8_t * const *)input->data,
+                         (const uint8_t *const *)input->data,
                          input->linesize,
                          0,
                          anim->pCodecCtx->height,
@@ -740,7 +746,7 @@ static void ffmpeg_postprocess(struct anim * anim)
 
 /* decode one video frame also considering the packet read into next_packet */
 
-static int ffmpeg_decode_video_frame(struct anim * anim)
+static int ffmpeg_decode_video_frame(struct anim *anim)
 {
        int rval = 0;
 
@@ -760,9 +766,9 @@ static int ffmpeg_decode_video_frame(struct anim * anim)
                       ? "->" : "  ",
                       anim->next_packet.stream_index, 
                       anim->videoStream,
-                      (anim->next_packet.dts == AV_NOPTS_VALUE) ? -1:
+                      (anim->next_packet.dts == AV_NOPTS_VALUE) ? -1 :
                       (long long int)anim->next_packet.dts,
-                      (anim->next_packet.pts == AV_NOPTS_VALUE) ? -1:
+                      (anim->next_packet.pts == AV_NOPTS_VALUE) ? -1 :
                       (long long int)anim->next_packet.pts,
                       (anim->next_packet.flags & AV_PKT_FLAG_KEY) ? 
                       " KEY" : "");
@@ -770,13 +776,13 @@ static int ffmpeg_decode_video_frame(struct anim * anim)
                        anim->pFrameComplete = 0;
 
                        avcodec_decode_video2(
-                               anim->pCodecCtx, 
-                               anim->pFrame, &anim->pFrameComplete, 
-                               &anim->next_packet);
+                           anim->pCodecCtx,
+                           anim->pFrame, &anim->pFrameComplete,
+                           &anim->next_packet);
 
                        if (anim->pFrameComplete) {
                                anim->next_pts = av_get_pts_from_frame(
-                                       anim->pFormatCtx, anim->pFrame);
+                                       anim->pFormatCtx, anim->pFrame);
 
                                av_log(anim->pFormatCtx,
                                       AV_LOG_DEBUG,
@@ -786,7 +792,7 @@ static int ffmpeg_decode_video_frame(struct anim * anim)
                                       -1 : (long long int)anim->pFrame->pts,
                                       (anim->pFrame->pkt_pts == AV_NOPTS_VALUE) ?
                                       -1 : (long long int)anim->pFrame->pkt_pts,
-                                       (long long int)anim->next_pts);
+                                      (long long int)anim->next_pts);
                                break;
                        }
                }
@@ -799,14 +805,14 @@ static int ffmpeg_decode_video_frame(struct anim * anim)
 
                av_log(anim->pFormatCtx,
                       AV_LOG_ERROR, "  DECODE READ FAILED: av_read_frame() "
-                      "returned error: %d\n",  rval);
+                      "returned error: %d\n",  rval);
        }
 
        return (rval >= 0);
 }
 
 static void ffmpeg_decode_video_frame_scan(
-       struct anim * anim, int64_t pts_to_search)
+        struct anim *anim, int64_t pts_to_search)
 {
        /* there seem to exist *very* silly GOP lengths out in the wild... */
        int count = 1000;
@@ -843,7 +849,7 @@ static void ffmpeg_decode_video_frame_scan(
        }
 }
 
-static int match_format(const char *name, AVFormatContext * pFormatCtx)
+static int match_format(const char *name, AVFormatContext *pFormatCtx)
 {
        const char *p;
        int len, namelen;
@@ -858,15 +864,15 @@ static int match_format(const char *name, AVFormatContext * pFormatCtx)
                len = MAX2(p - names, namelen);
                if (!BLI_strncasecmp(name, names, len))
                        return 1;
-               names = p+1;
+               names = p + 1;
        }
        return !BLI_strcasecmp(name, names);
 }
 
 static int ffmpeg_seek_by_byte(AVFormatContext *pFormatCtx)
 {
-       static const char * byte_seek_list [] = { "mpegts", 0 };
-       const char ** p;
+       static const char *byte_seek_list[] = { "mpegts", 0 };
+       const char **p;
 
        if (pFormatCtx->iformat->flags & AVFMT_TS_DISCONT) {
                return TRUE;
@@ -883,14 +889,14 @@ static int ffmpeg_seek_by_byte(AVFormatContext *pFormatCtx)
        return FALSE;
 }
 
-static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position,
-                               IMB_Timecode_Type tc) {
+static ImBuf *ffmpeg_fetchibuf(struct anim *anim, int position,
+                               IMB_Timecode_Type tc) {
        int64_t pts_to_search = 0;
        double frame_rate;
        double pts_time_base;
        long long st_time; 
-       struct anim_index * tc_index = 0;
-       AVStream * v_st;
+       struct anim_index *tc_index = 0;
+       AVStream *v_st;
        int new_frame_index = 0; /* To quite gcc barking... */
        int old_frame_index = 0; /* To quite gcc barking... */
 
@@ -911,16 +917,16 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position,
 
        if (tc_index) {
                new_frame_index = IMB_indexer_get_frame_index(
-                       tc_index, position);
+                       tc_index, position);
                old_frame_index = IMB_indexer_get_frame_index(
-                       tc_index, anim->curposition);
-               pts_to_search = IMB_indexer_get_pts(
-                       tc_index, new_frame_index);
+                       tc_index, anim->curposition);
+               pts_to_search = IMB_indexer_get_pts(
+                       tc_index, new_frame_index);
        }
        else {
                pts_to_search = (long long) 
-                       floor(((double) position) /
-                         pts_time_base / frame_rate + 0.5);
+                               floor(((double) position) /
+                                     pts_time_base / frame_rate + 0.5);
 
                if (st_time != AV_NOPTS_VALUE) {
                        pts_to_search += st_time / pts_time_base / AV_TIME_BASE;
@@ -954,9 +960,9 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position,
                ffmpeg_decode_video_frame_scan(anim, pts_to_search);
        }
        else if (tc_index &&
-                  IMB_indexer_can_scan(tc_index, old_frame_index,
-                                       new_frame_index)) {
-
+                IMB_indexer_can_scan(tc_index, old_frame_index,
+                                     new_frame_index))
+       {
                av_log(anim->pFormatCtx, AV_LOG_DEBUG, 
                       "FETCH: within preseek interval "
                       "(index tells us)\n");
@@ -971,9 +977,9 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position,
                        unsigned long long dts;
 
                        pos = IMB_indexer_get_seek_pos(
-                               tc_index, new_frame_index);
+                           tc_index, new_frame_index);
                        dts = IMB_indexer_get_seek_pos_dts(
-                               tc_index, new_frame_index);
+                           tc_index, new_frame_index);
 
                        av_log(anim->pFormatCtx, AV_LOG_DEBUG, 
                               "TC INDEX seek pos = %lld\n", pos);
@@ -985,21 +991,21 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position,
                                       "... using BYTE pos\n");
 
                                ret = av_seek_frame(anim->pFormatCtx, 
-                                                   -1,
-                                                   pos, AVSEEK_FLAG_BYTE);
+                                                   -1,
+                                                   pos, AVSEEK_FLAG_BYTE);
                                av_update_cur_dts(anim->pFormatCtx, v_st, dts);
                        }
                        else {
                                av_log(anim->pFormatCtx, AV_LOG_DEBUG, 
                                       "... using DTS pos\n");
                                ret = av_seek_frame(anim->pFormatCtx, 
-                                                   anim->videoStream, 
-                                                   dts, AVSEEK_FLAG_BACKWARD);
+                                                   anim->videoStream,
+                                                   dts, AVSEEK_FLAG_BACKWARD);
                        }
                }
                else {
                        pos = (long long) (position - anim->preseek) *
-                               AV_TIME_BASE / frame_rate;
+                             AV_TIME_BASE / frame_rate;
 
                        av_log(anim->pFormatCtx, AV_LOG_DEBUG, 
                               "NO INDEX seek pos = %lld, st_time = %lld\n", 
@@ -1017,7 +1023,7 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position,
                               "NO INDEX final seek pos = %lld\n", pos);
 
                        ret = av_seek_frame(anim->pFormatCtx, -1, 
-                                           pos, AVSEEK_FLAG_BACKWARD);
+                                           pos, AVSEEK_FLAG_BACKWARD);
                }
 
                if (ret < 0) {
@@ -1068,7 +1074,7 @@ static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position,
        return anim->last_frame;
 }
 
-static void free_anim_ffmpeg(struct anim * anim)
+static void free_anim_ffmpeg(struct anim *anim)
 {
        if (anim == NULL) return;
 
@@ -1095,7 +1101,7 @@ static void free_anim_ffmpeg(struct anim * anim)
 
 #ifdef WITH_REDCODE
 
-static int startredcode(struct anim * anim)
+static int startredcode(struct anim *anim)
 {
        anim->redcodeCtx = redcode_open(anim->name);
        if (!anim->redcodeCtx) {
@@ -1106,11 +1112,11 @@ static int startredcode(struct anim * anim)
        return 0;
 }
 
-static ImBuf * redcode_fetchibuf(struct anim * anim, int position)
+static ImBuf *redcode_fetchibuf(struct anim *anim, int position)
 {
-       struct ImBuf * ibuf;
-       struct redcode_frame * frame;
-       struct redcode_frame_raw * raw_frame;
+       struct ImBuf *ibuf;
+       struct redcode_frame *frame;
+       struct redcode_frame_raw *raw_frame;
 
        if (!anim->redcodeCtx) {
                return NULL;
@@ -1130,15 +1136,15 @@ static ImBuf * redcode_fetchibuf(struct anim * anim, int position)
                return NULL;
        }
        
-               ibuf = IMB_allocImBuf(raw_frame->width * 2, 
-                                     raw_frame->height * 2, 32, IB_rectfloat);
+       ibuf = IMB_allocImBuf(raw_frame->width * 2,
+                             raw_frame->height * 2, 32, IB_rectfloat);
 
        redcode_decode_video_float(raw_frame, ibuf->rect_float, 1);
 
        return ibuf;
 }
 
-static void free_anim_redcode(struct anim * anim)
+static void free_anim_redcode(struct anim *anim)
 {
        if (anim->redcodeCtx) {
                redcode_close(anim->redcodeCtx);
@@ -1153,7 +1159,7 @@ static void free_anim_redcode(struct anim * anim)
 /* Geen plaatje, probeer dan volgende animatie te openen */
 /* gelukt, haal dan eerste plaatje van animatie */
 
-static struct ImBuf * anim_getnew(struct anim * anim)
+static struct ImBuf *anim_getnew(struct anim *anim)
 {
        struct ImBuf *ibuf = NULL;
 
@@ -1176,49 +1182,48 @@ static struct ImBuf * anim_getnew(struct anim * anim)
        anim->curtype = imb_get_anim_type(anim->name);  
 
        switch (anim->curtype) {
-       case ANIM_SEQUENCE:
-               ibuf = IMB_loadiffname(anim->name, anim->ib_flags);
-               if (ibuf) {
-                       BLI_strncpy(anim->first, anim->name, sizeof(anim->first));
-                       anim->duration = 1;
-               }
-               break;
-       case ANIM_MOVIE:
-               if (startmovie(anim)) return (NULL);
-               ibuf = IMB_allocImBuf (anim->x, anim->y, 24, 0); /* fake */
-               break;
-       case ANIM_AVI:
-               if (startavi(anim)) {
-                       printf("couldnt start avi\n"); 
-                       return (NULL);
-               }
-               ibuf = IMB_allocImBuf (anim->x, anim->y, 24, 0);
-               break;
+               case ANIM_SEQUENCE:
+                       ibuf = IMB_loadiffname(anim->name, anim->ib_flags);
+                       if (ibuf) {
+                               BLI_strncpy(anim->first, anim->name, sizeof(anim->first));
+                               anim->duration = 1;
+                       }
+                       break;
+               case ANIM_MOVIE:
+                       if (startmovie(anim)) return (NULL);
+                       ibuf = IMB_allocImBuf(anim->x, anim->y, 24, 0); /* fake */
+                       break;
+               case ANIM_AVI:
+                       if (startavi(anim)) {
+                               printf("couldnt start avi\n");
+                               return (NULL);
+                       }
+                       ibuf = IMB_allocImBuf(anim->x, anim->y, 24, 0);
+                       break;
 #ifdef WITH_QUICKTIME
-       case ANIM_QTIME:
-               if (startquicktime(anim)) return (0);
-               ibuf = IMB_allocImBuf (anim->x, anim->y, 24, 0);
-               break;
+               case ANIM_QTIME:
+                       if (startquicktime(anim)) return (0);
+                       ibuf = IMB_allocImBuf(anim->x, anim->y, 24, 0);
+                       break;
 #endif
 #ifdef WITH_FFMPEG
-       case ANIM_FFMPEG:
-               if (startffmpeg(anim)) return (0);
-               ibuf = IMB_allocImBuf (anim->x, anim->y, 24, 0);
-               break;
+               case ANIM_FFMPEG:
+                       if (startffmpeg(anim)) return (0);
+                       ibuf = IMB_allocImBuf(anim->x, anim->y, 24, 0);
+                       break;
 #endif
 #ifdef WITH_REDCODE
-       case ANIM_REDCODE:
-               if (startredcode(anim)) return (0);
-               ibuf = IMB_allocImBuf (8, 8, 32, 0);
-               break;
+               case ANIM_REDCODE:
+                       if (startredcode(anim)) return (0);
+                       ibuf = IMB_allocImBuf(8, 8, 32, 0);
+                       break;
 #endif
        }
        return(ibuf);
 }
 
-struct ImBuf * IMB_anim_previewframe(struct anim * anim)
-{
-       struct ImBuf * ibuf = NULL;
+struct ImBuf *IMB_anim_previewframe(struct anim *anim){
+       struct ImBuf *ibuf = NULL;
        int position = 0;
        
        ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE);
@@ -1226,15 +1231,15 @@ struct ImBuf * IMB_anim_previewframe(struct anim * anim)
                IMB_freeImBuf(ibuf);
                position = anim->duration / 2;
                ibuf = IMB_anim_absolute(anim, position, IMB_TC_NONE,
-                                        IMB_PROXY_NONE);
+                                        IMB_PROXY_NONE);
        }
        return ibuf;
 }
 
-struct ImBuf * IMB_anim_absolute(struct anim * anim, int position,
-                                IMB_Timecode_Type tc,
-                                IMB_Proxy_Size preview_size) {
-       struct ImBuf * ibuf = NULL;
+struct ImBuf *IMB_anim_absolute(struct anim *anim, int position,
+                                IMB_Timecode_Type tc,
+                                IMB_Proxy_Size preview_size) {
+       struct ImBuf *ibuf = NULL;
        char head[256], tail[256];
        unsigned short digits;
        int pic;
@@ -1243,74 +1248,74 @@ struct ImBuf * IMB_anim_absolute(struct anim * anim, int position,
 
        filter_y = (anim->ib_flags & IB_animdeinterlace);
 
-       if (anim->curtype == 0) {
+       if (anim->curtype == 0) {
                ibuf = anim_getnew(anim);
                if (ibuf == NULL) {
                        return(NULL);
                }
 
                IMB_freeImBuf(ibuf); /* ???? */
-               ibuf= NULL;
+               ibuf = NULL;
        }
 
        if (position < 0) return(NULL);
        if (position >= anim->duration) return(NULL);
 
        if (preview_size != IMB_PROXY_NONE) {
-               struct anim * proxy = IMB_anim_open_proxy(anim, preview_size);
+               struct anim *proxy = IMB_anim_open_proxy(anim, preview_size);
 
                if (proxy) {
                        position = IMB_anim_index_get_frame_index(
-                               anim, tc, position);
+                           anim, tc, position);
                        return IMB_anim_absolute(
-                               proxy, position,
-                               IMB_TC_NONE, IMB_PROXY_NONE);
+                                  proxy, position,
+                                  IMB_TC_NONE, IMB_PROXY_NONE);
                }
        }
 
        switch (anim->curtype) {
-       case ANIM_SEQUENCE:
-               pic = an_stringdec(anim->first, head, tail, &digits);
-               pic += position;
-               an_stringenc(anim->name, head, tail, digits, pic);
-               ibuf = IMB_loadiffname(anim->name, IB_rect);
-               if (ibuf) {
-                       anim->curposition = position;
-               }
-               break;
-       case ANIM_MOVIE:
-               ibuf = movie_fetchibuf(anim, position);
-               if (ibuf) {
-                       anim->curposition = position;
-                       IMB_convert_rgba_to_abgr(ibuf);
-                       ibuf->profile = IB_PROFILE_SRGB;
-               }
-               break;
-       case ANIM_AVI:
-               ibuf = avi_fetchibuf(anim, position);
-               if (ibuf)
-                       anim->curposition = position;
-               break;
+               case ANIM_SEQUENCE:
+                       pic = an_stringdec(anim->first, head, tail, &digits);
+                       pic += position;
+                       an_stringenc(anim->name, head, tail, digits, pic);
+                       ibuf = IMB_loadiffname(anim->name, IB_rect);
+                       if (ibuf) {
+                               anim->curposition = position;
+                       }
+                       break;
+               case ANIM_MOVIE:
+                       ibuf = movie_fetchibuf(anim, position);
+                       if (ibuf) {
+                               anim->curposition = position;
+                               IMB_convert_rgba_to_abgr(ibuf);
+                               ibuf->profile = IB_PROFILE_SRGB;
+                       }
+                       break;
+               case ANIM_AVI:
+                       ibuf = avi_fetchibuf(anim, position);
+                       if (ibuf)
+                               anim->curposition = position;
+                       break;
 #ifdef WITH_QUICKTIME
-       case ANIM_QTIME:
-               ibuf = qtime_fetchibuf(anim, position);
-               if (ibuf)
-                       anim->curposition = position;
-               break;
+               case ANIM_QTIME:
+                       ibuf = qtime_fetchibuf(anim, position);
+                       if (ibuf)
+                               anim->curposition = position;
+                       break;
 #endif
 #ifdef WITH_FFMPEG
-       case ANIM_FFMPEG:
-               ibuf = ffmpeg_fetchibuf(anim, position, tc);
-               if (ibuf)
-                       anim->curposition = position;
-               filter_y = 0; /* done internally */
-               break;
+               case ANIM_FFMPEG:
+                       ibuf = ffmpeg_fetchibuf(anim, position, tc);
+                       if (ibuf)
+                               anim->curposition = position;
+                       filter_y = 0; /* done internally */
+                       break;
 #endif
 #ifdef WITH_REDCODE
-       case ANIM_REDCODE:
-               ibuf = redcode_fetchibuf(anim, position);
-               if (ibuf) anim->curposition = position;
-               break;
+               case ANIM_REDCODE:
+                       ibuf = redcode_fetchibuf(anim, position);
+                       if (ibuf) anim->curposition = position;
+                       break;
 #endif
        }
 
@@ -1326,7 +1331,7 @@ struct ImBuf * IMB_anim_absolute(struct anim * anim, int position,
 
 int IMB_anim_get_duration(struct anim *anim, IMB_Timecode_Type tc)
 {
-       struct anim_index * idx;
+       struct anim_index *idx;
        if (tc == IMB_TC_NONE) {
                return anim->duration;
        }
@@ -1339,8 +1344,8 @@ int IMB_anim_get_duration(struct anim *anim, IMB_Timecode_Type tc)
        return IMB_indexer_get_duration(idx);
 }
 
-int IMB_anim_get_fps(struct anim * anim, 
-                    short * frs_sec, float * frs_sec_base)
+int IMB_anim_get_fps(struct anim *anim,
+                     short *frs_sec, float *frs_sec_base)
 {
        if (anim->frs_sec) {
                *frs_sec = anim->frs_sec;
@@ -1350,12 +1355,12 @@ int IMB_anim_get_fps(struct anim * anim,
        return FALSE;
 }
 
-void IMB_anim_set_preseek(struct anim * anim, int preseek)
+void IMB_anim_set_preseek(struct anim *anim, int preseek)
 {
        anim->preseek = preseek;
 }
 
-int IMB_anim_get_preseek(struct anim * anim)
+int IMB_anim_get_preseek(struct anim *anim)
 {
        return anim->preseek;
 }
index bce3c70fd93672188a587784b2ecac88b8668751..8734ea90cb1c90a4ea1c0ddcc218703ea8315b4b 100644 (file)
  */
 
 typedef struct BMPINFOHEADER {
-       unsigned int    biSize;
-       unsigned int    biWidth;
-       unsigned int    biHeight;
-       unsigned short  biPlanes;
-       unsigned short  biBitCount;
-       unsigned int    biCompression;
-       unsigned int    biSizeImage;
-       unsigned int    biXPelsPerMeter;
-       unsigned int    biYPelsPerMeter;
-       unsigned int    biClrUsed;
-       unsigned int    biClrImportant;
+       unsigned int    biSize;
+       unsigned int    biWidth;
+       unsigned int    biHeight;
+       unsigned short  biPlanes;
+       unsigned short  biBitCount;
+       unsigned int    biCompression;
+       unsigned int    biSizeImage;
+       unsigned int    biXPelsPerMeter;
+       unsigned int    biYPelsPerMeter;
+       unsigned int    biClrUsed;
+       unsigned int    biClrImportant;
 } BMPINFOHEADER;
 
 typedef struct BMPHEADER {
@@ -160,7 +160,7 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags)
                else if (depth == 24) {
                        for (i = y; i > 0; i--) {
                                int j;
-                               for (j = x ; j > 0; j--) {
+                               for (j = x; j > 0; j--) {
                                        rect[0] = bmp[2];
                                        rect[1] = bmp[1];
                                        rect[2] = bmp[0];
@@ -194,16 +194,16 @@ struct ImBuf *imb_bmp_decode(unsigned char *mem, size_t size, int flags)
 /* Couple of helper functions for writing our data */
 static int putIntLSB(unsigned int ui, FILE *ofile)
 {
-       putc((ui>>0)&0xFF, ofile);
-       putc((ui>>8)&0xFF, ofile);
-       putc((ui>>16)&0xFF, ofile);
-       return putc((ui>>24)&0xFF, ofile);
+       putc((ui >> 0) & 0xFF, ofile);
+       putc((ui >> 8) & 0xFF, ofile);
+       putc((ui >> 16) & 0xFF, ofile);
+       return putc((ui >> 24) & 0xFF, ofile);
 }
 
 static int putShortLSB(unsigned short us, FILE *ofile)
 {
-       putc((us>>0)&0xFF, ofile);
-       return putc((us>>8)&0xFF, ofile);
+       putc((us >> 0) & 0xFF, ofile);
+       return putc((us >> 8) & 0xFF, ofile);
 } 
 
 /* Found write info at http://users.ece.gatech.edu/~slabaugh/personal/c/bitmapUnix.c */
@@ -216,12 +216,12 @@ int imb_savebmp(struct ImBuf *ibuf, const char *name, int flags)
        
        (void)flags; /* unused */
 
-       extrabytes = (4 - ibuf->x*3 % 4) % 4;
+       extrabytes = (4 - ibuf->x * 3 % 4) % 4;
        bytesize = (ibuf->x * 3 + extrabytes) * ibuf->y;
 
        data = (uchar *) ibuf->rect;
        ofile = BLI_fopen(name, "wb");
-               if (!ofile) return 0;
+       if (!ofile) return 0;
 
        putShortLSB(19778, ofile); /* "BM" */
        putIntLSB(0, ofile); /* This can be 0 for BI_RGB bitmaps */
@@ -242,15 +242,15 @@ int imb_savebmp(struct ImBuf *ibuf, const char *name, int flags)
        putIntLSB(0, ofile);
 
        /* Need to write out padded image data in bgr format */
-       for (y=0;y<ibuf->y;y++) {
-               for (x=0;x<ibuf->x;x++) {
-                       ptr=(x + y * ibuf->x) * 4;
-                       if (putc(data[ptr+2], ofile) == EOF) return 0;
-                       if (putc(data[ptr+1], ofile) == EOF) return 0;
+       for (y = 0; y < ibuf->y; y++) {
+               for (x = 0; x < ibuf->x; x++) {
+                       ptr = (x + y * ibuf->x) * 4;
+                       if (putc(data[ptr + 2], ofile) == EOF) return 0;
+                       if (putc(data[ptr + 1], ofile) == EOF) return 0;
                        if (putc(data[ptr], ofile) == EOF) return 0;
                }
                /* add padding here */
-               for (t=0;t<extrabytes;t++) if (putc(0, ofile) == EOF) return 0;
+               for (t = 0; t < extrabytes; t++) if (putc(0, ofile) == EOF) return 0;
        }
        if (ofile) {
                fflush(ofile);
index ba9b118d185d0be3fb7d55ff2e8b34aa3071d867..4be521218f1a94a6f859f92a3649ba44dbfdaabd 100644 (file)
@@ -48,7 +48,7 @@
  * back to the global cache every pixel, but not to big to keep too many tiles
  * locked and using memory. */
 
-#define IB_THREAD_CACHE_SIZE   100
+#define IB_THREAD_CACHE_SIZE    100
 
 typedef struct ImGlobalTile {
        struct ImGlobalTile *next, *prev;
@@ -82,7 +82,7 @@ typedef struct ImGlobalTileCache {
        MemArena *memarena;
        uintptr_t totmem, maxmem;
 
-       ImThreadTileCache thread_cache[BLENDER_MAX_THREADS+1];
+       ImThreadTileCache thread_cache[BLENDER_MAX_THREADS + 1];
        int totthread;
 
        ThreadMutex mutex;
@@ -96,15 +96,15 @@ static ImGlobalTileCache GLOBAL_CACHE;
 
 static unsigned int imb_global_tile_hash(const void *gtile_p)
 {
-       const ImGlobalTile *gtile= gtile_p;
+       const ImGlobalTile *gtile = gtile_p;
 
-       return ((unsigned int)(intptr_t)gtile->ibuf)*769 + gtile->tx*53 + gtile->ty*97;
+       return ((unsigned int)(intptr_t)gtile->ibuf) * 769 + gtile->tx * 53 + gtile->ty * 97;
 }
 
 static int imb_global_tile_cmp(const void *a_p, const void *b_p)
 {
-       const ImGlobalTile *a= a_p;
-       const ImGlobalTile *b= b_p;
+       const ImGlobalTile *a = a_p;
+       const ImGlobalTile *b = b_p;
 
        if (a->ibuf == b->ibuf && a->tx == b->tx && a->ty == b->ty) return 0;
        else if (a->ibuf < b->ibuf || a->tx < b->tx || a->ty < b->ty) return -1;
@@ -113,15 +113,15 @@ static int imb_global_tile_cmp(const void *a_p, const void *b_p)
 
 static unsigned int imb_thread_tile_hash(const void *ttile_p)
 {
-       const ImThreadTile *ttile= ttile_p;
+       const ImThreadTile *ttile = ttile_p;
 
-       return ((unsigned int)(intptr_t)ttile->ibuf)*769 + ttile->tx*53 + ttile->ty*97;
+       return ((unsigned int)(intptr_t)ttile->ibuf) * 769 + ttile->tx * 53 + ttile->ty * 97;
 }
 
 static int imb_thread_tile_cmp(const void *a_p, const void *b_p)
 {
-       const ImThreadTile *a= a_p;
-       const ImThreadTile *b= b_p;
+       const ImThreadTile *a = a_p;
+       const ImThreadTile *b = b_p;
 
        if (a->ibuf == b->ibuf && a->tx == b->tx && a->ty == b->ty) return 0;
        else if (a->ibuf < b->ibuf || a->tx < b->tx || a->ty < b->ty) return -1;
@@ -132,24 +132,24 @@ static int imb_thread_tile_cmp(const void *a_p, const void *b_p)
 
 static void imb_global_cache_tile_load(ImGlobalTile *gtile)
 {
-       ImBuf *ibuf= gtile->ibuf;
-       int toffs= ibuf->xtiles*gtile->ty + gtile->tx;
+       ImBuf *ibuf = gtile->ibuf;
+       int toffs = ibuf->xtiles * gtile->ty + gtile->tx;
        unsigned int *rect;
 
-       rect = MEM_callocN(sizeof(unsigned int)*ibuf->tilex*ibuf->tiley, "imb_tile");
+       rect = MEM_callocN(sizeof(unsigned int) * ibuf->tilex * ibuf->tiley, "imb_tile");
        imb_loadtile(ibuf, gtile->tx, gtile->ty, rect);
-       ibuf->tiles[toffs]= rect;
+       ibuf->tiles[toffs] = rect;
 }
 
 static void imb_global_cache_tile_unload(ImGlobalTile *gtile)
 {
-       ImBuf *ibuf= gtile->ibuf;
-       int toffs= ibuf->xtiles*gtile->ty + gtile->tx;
+       ImBuf *ibuf = gtile->ibuf;
+       int toffs = ibuf->xtiles * gtile->ty + gtile->tx;
 
        MEM_freeN(ibuf->tiles[toffs]);
-       ibuf->tiles[toffs]= NULL;
+       ibuf->tiles[toffs] = NULL;
 
-       GLOBAL_CACHE.totmem -= sizeof(unsigned int)*ibuf->tilex*ibuf->tiley;
+       GLOBAL_CACHE.totmem -= sizeof(unsigned int) * ibuf->tilex * ibuf->tiley;
 }
 
 /* external free */
@@ -162,7 +162,7 @@ void imb_tile_cache_tile_free(ImBuf *ibuf, int tx, int ty)
        lookuptile.ibuf = ibuf;
        lookuptile.tx = tx;
        lookuptile.ty = ty;
-       gtile= BLI_ghash_lookup(GLOBAL_CACHE.tilehash, &lookuptile);
+       gtile = BLI_ghash_lookup(GLOBAL_CACHE.tilehash, &lookuptile);
 
        if (gtile) {
                /* in case another thread is loading this */
@@ -186,11 +186,11 @@ static void imb_thread_cache_init(ImThreadTileCache *cache)
 
        memset(cache, 0, sizeof(ImThreadTileCache));
 
-       cache->tilehash= BLI_ghash_new(imb_thread_tile_hash, imb_thread_tile_cmp, "imb_thread_cache_init gh");
+       cache->tilehash = BLI_ghash_new(imb_thread_tile_hash, imb_thread_tile_cmp, "imb_thread_cache_init gh");
 
        /* pre-allocate all thread local tiles in unused list */
-       for (a=0; a<IB_THREAD_CACHE_SIZE; a++) {
-               ttile= BLI_memarena_alloc(GLOBAL_CACHE.memarena, sizeof(ImThreadTile));
+       for (a = 0; a < IB_THREAD_CACHE_SIZE; a++) {
+               ttile = BLI_memarena_alloc(GLOBAL_CACHE.memarena, sizeof(ImThreadTile));
                BLI_addtail(&cache->unused, ttile);
        }
 }
@@ -219,10 +219,10 @@ void imb_tile_cache_exit(void)
        int a;
 
        if (GLOBAL_CACHE.initialized) {
-               for (gtile=GLOBAL_CACHE.tiles.first; gtile; gtile=gtile->next)
+               for (gtile = GLOBAL_CACHE.tiles.first; gtile; gtile = gtile->next)
                        imb_global_cache_tile_unload(gtile);
 
-               for (a=0; a<GLOBAL_CACHE.totthread; a++)
+               for (a = 0; a < GLOBAL_CACHE.totthread; a++)
                        imb_thread_cache_exit(&GLOBAL_CACHE.thread_cache[a]);
 
                if (GLOBAL_CACHE.memarena)
@@ -253,15 +253,15 @@ void IMB_tile_cache_params(int totthread, int maxmem)
 
        memset(&GLOBAL_CACHE, 0, sizeof(ImGlobalTileCache));
 
-       GLOBAL_CACHE.tilehash= BLI_ghash_new(imb_global_tile_hash, imb_global_tile_cmp, "tile_cache_params gh");
+       GLOBAL_CACHE.tilehash = BLI_ghash_new(imb_global_tile_hash, imb_global_tile_cmp, "tile_cache_params gh");
 
-       GLOBAL_CACHE.memarena= BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "ImTileCache arena");
+       GLOBAL_CACHE.memarena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "ImTileCache arena");
        BLI_memarena_use_calloc(GLOBAL_CACHE.memarena);
 
-       GLOBAL_CACHE.maxmem= maxmem*1024*1024;
+       GLOBAL_CACHE.maxmem = maxmem * 1024 * 1024;
 
-       GLOBAL_CACHE.totthread= totthread;
-       for (a=0; a<totthread; a++)
+       GLOBAL_CACHE.totthread = totthread;
+       for (a = 0; a < totthread; a++)
                imb_thread_cache_init(&GLOBAL_CACHE.thread_cache[a]);
 
        BLI_mutex_init(&GLOBAL_CACHE.mutex);
@@ -282,7 +282,7 @@ static ImGlobalTile *imb_global_cache_get_tile(ImBuf *ibuf, int tx, int ty, ImGl
        lookuptile.ibuf = ibuf;
        lookuptile.tx = tx;
        lookuptile.ty = ty;
-       gtile= BLI_ghash_lookup(GLOBAL_CACHE.tilehash, &lookuptile);
+       gtile = BLI_ghash_lookup(GLOBAL_CACHE.tilehash, &lookuptile);
        
        if (gtile) {
                /* found tile. however it may be in the process of being loaded
@@ -301,7 +301,7 @@ static ImGlobalTile *imb_global_cache_get_tile(ImBuf *ibuf, int tx, int ty, ImGl
                /* first check if we hit the memory limit */
                if (GLOBAL_CACHE.maxmem && GLOBAL_CACHE.totmem > GLOBAL_CACHE.maxmem) {
                        /* find an existing tile to unload */
-                       for (gtile=GLOBAL_CACHE.tiles.last; gtile; gtile=gtile->prev)
+                       for (gtile = GLOBAL_CACHE.tiles.last; gtile; gtile = gtile->prev)
                                if (gtile->refcount == 0 && gtile->loading == 0)
                                        break;
                }
@@ -315,25 +315,25 @@ static ImGlobalTile *imb_global_cache_get_tile(ImBuf *ibuf, int tx, int ty, ImGl
                else {
                        /* allocate a new tile or reuse unused */
                        if (GLOBAL_CACHE.unused.first) {
-                               gtile= GLOBAL_CACHE.unused.first;
+                               gtile = GLOBAL_CACHE.unused.first;
                                BLI_remlink(&GLOBAL_CACHE.unused, gtile);
                        }
                        else
-                               gtile= BLI_memarena_alloc(GLOBAL_CACHE.memarena, sizeof(ImGlobalTile));
+                               gtile = BLI_memarena_alloc(GLOBAL_CACHE.memarena, sizeof(ImGlobalTile));
                }
 
                /* setup new tile */
-               gtile->ibuf= ibuf;
-               gtile->tx= tx;
-               gtile->ty= ty;
-               gtile->refcount= 1;
-               gtile->loading= 1;
+               gtile->ibuf = ibuf;
+               gtile->tx = tx;
+               gtile->ty = ty;
+               gtile->refcount = 1;
+               gtile->loading = 1;
 
                BLI_ghash_insert(GLOBAL_CACHE.tilehash, gtile, gtile);
                BLI_addhead(&GLOBAL_CACHE.tiles, gtile);
 
                /* mark as being loaded and unlock to allow other threads to load too */
-               GLOBAL_CACHE.totmem += sizeof(unsigned int)*ibuf->tilex*ibuf->tiley;
+               GLOBAL_CACHE.totmem += sizeof(unsigned int) * ibuf->tilex * ibuf->tiley;
 
                BLI_mutex_unlock(&GLOBAL_CACHE.mutex);
 
@@ -341,7 +341,7 @@ static ImGlobalTile *imb_global_cache_get_tile(ImBuf *ibuf, int tx, int ty, ImGl
                imb_global_cache_tile_load(gtile);
 
                /* mark as done loading */
-               gtile->loading= 0;
+               gtile->loading = 0;
        }
 
        return gtile;
@@ -353,10 +353,10 @@ static unsigned int *imb_thread_cache_get_tile(ImThreadTileCache *cache, ImBuf *
 {
        ImThreadTile *ttile, lookuptile;
        ImGlobalTile *gtile, *replacetile;
-       int toffs= ibuf->xtiles*ty + tx;
+       int toffs = ibuf->xtiles * ty + tx;
 
        /* test if it is already in our thread local cache */
-       if ((ttile=cache->tiles.first)) {
+       if ((ttile = cache->tiles.first)) {
                /* check last used tile before going to hash */
                if (ttile->ibuf == ibuf && ttile->tx == tx && ttile->ty == ty)
                        return ibuf->tiles[toffs];
@@ -366,7 +366,7 @@ static unsigned int *imb_thread_cache_get_tile(ImThreadTileCache *cache, ImBuf *
                lookuptile.tx = tx;
                lookuptile.ty = ty;
 
-               if ((ttile=BLI_ghash_lookup(cache->tilehash, &lookuptile))) {
+               if ((ttile = BLI_ghash_lookup(cache->tilehash, &lookuptile))) {
                        BLI_remlink(&cache->tiles, ttile);
                        BLI_addhead(&cache->tiles, ttile);
 
@@ -376,33 +376,33 @@ static unsigned int *imb_thread_cache_get_tile(ImThreadTileCache *cache, ImBuf *
 
        /* not found, have to do slow lookup in global cache */
        if (cache->unused.first == NULL) {
-               ttile= cache->tiles.last;
-               replacetile= ttile->global;
+               ttile = cache->tiles.last;
+               replacetile = ttile->global;
                BLI_remlink(&cache->tiles, ttile);
                BLI_ghash_remove(cache->tilehash, ttile, NULL, NULL);
        }
        else {
-               ttile= cache->unused.first;
-               replacetile= NULL;
+               ttile = cache->unused.first;
+               replacetile = NULL;
                BLI_remlink(&cache->unused, ttile);
        }
 
        BLI_addhead(&cache->tiles, ttile);
        BLI_ghash_insert(cache->tilehash, ttile, ttile);
 
-       gtile= imb_global_cache_get_tile(ibuf, tx, ty, replacetile);
+       gtile = imb_global_cache_get_tile(ibuf, tx, ty, replacetile);
 
-       ttile->ibuf= gtile->ibuf;
-       ttile->tx= gtile->tx;
-       ttile->ty= gtile->ty;
-       ttile->global= gtile;
+       ttile->ibuf = gtile->ibuf;
+       ttile->tx = gtile->tx;
+       ttile->ty = gtile->ty;
+       ttile->global = gtile;
 
        return ibuf->tiles[toffs];
 }
 
 unsigned int *IMB_gettile(ImBuf *ibuf, int tx, int ty, int thread)
 {
-       return imb_thread_cache_get_tile(&GLOBAL_CACHE.thread_cache[thread+1], ibuf, tx, ty);
+       return imb_thread_cache_get_tile(&GLOBAL_CACHE.thread_cache[thread + 1], ibuf, tx, ty);
 }
 
 void IMB_tiles_to_rect(ImBuf *ibuf)
@@ -412,12 +412,12 @@ void IMB_tiles_to_rect(ImBuf *ibuf)
        unsigned int *to, *from;
        int a, tx, ty, y, w, h;
 
-       for (a=0; a<ibuf->miptot; a++) {
-               mipbuf= IMB_getmipmap(ibuf, a);
+       for (a = 0; a < ibuf->miptot; a++) {
+               mipbuf = IMB_getmipmap(ibuf, a);
 
                /* don't call imb_addrectImBuf, it frees all mipmaps */
                if (!mipbuf->rect) {
-                       if ((mipbuf->rect = MEM_mapallocN(ibuf->x*ibuf->y*sizeof(unsigned int), "imb_addrectImBuf"))) {
+                       if ((mipbuf->rect = MEM_mapallocN(ibuf->x * ibuf->y * sizeof(unsigned int), "imb_addrectImBuf"))) {
                                mipbuf->mall |= IB_rect;
                                mipbuf->flags |= IB_rect;
                        }
@@ -425,22 +425,22 @@ void IMB_tiles_to_rect(ImBuf *ibuf)
                                break;
                }
 
-               for (ty=0; ty<mipbuf->ytiles; ty++) {
-                       for (tx=0; tx<mipbuf->xtiles; tx++) {
+               for (ty = 0; ty < mipbuf->ytiles; ty++) {
+                       for (tx = 0; tx < mipbuf->xtiles; tx++) {
                                /* acquire tile through cache, this assumes cache is initialized,
                                 * which it is always now but it's a weak assumption ... */
-                               gtile= imb_global_cache_get_tile(mipbuf, tx, ty, NULL);
+                               gtile = imb_global_cache_get_tile(mipbuf, tx, ty, NULL);
 
                                /* setup pointers */
-                               from= mipbuf->tiles[mipbuf->xtiles*ty + tx];
-                               to= mipbuf->rect + mipbuf->x*ty*mipbuf->tiley + tx*mipbuf->tilex;
+                               from = mipbuf->tiles[mipbuf->xtiles * ty + tx];
+                               to = mipbuf->rect + mipbuf->x * ty * mipbuf->tiley + tx * mipbuf->tilex;
 
                                /* exception in tile width/height for tiles at end of image */
-                               w= (tx == mipbuf->xtiles-1)? mipbuf->x - tx*mipbuf->tilex: mipbuf->tilex;
-                               h= (ty == mipbuf->ytiles-1)? mipbuf->y - ty*mipbuf->tiley: mipbuf->tiley;
+                               w = (tx == mipbuf->xtiles - 1) ? mipbuf->x - tx * mipbuf->tilex : mipbuf->tilex;
+                               h = (ty == mipbuf->ytiles - 1) ? mipbuf->y - ty * mipbuf->tiley : mipbuf->tiley;
 
-                               for (y=0; y<h; y++) {
-                                       memcpy(to, from, sizeof(unsigned int)*w);
+                               for (y = 0; y < h; y++) {
+                                       memcpy(to, from, sizeof(unsigned int) * w);
                                        from += mipbuf->tilex;
                                        to += mipbuf->x;
                                }
index d823df11e36fd5b1bf06f916e386861dda1701d4..74fa7c5987e48813e289864e86a847c2b6c8b492 100644 (file)
 
 
 static char magic[] = "BlenMIdx";
-static char temp_ext [] = "_part";
+static char temp_ext[] = "_part";
 
 static int proxy_sizes[] = { IMB_PROXY_25, IMB_PROXY_50, IMB_PROXY_75,
-                             IMB_PROXY_100 };
+                                IMB_PROXY_100 };
 static float proxy_fac[] = { 0.25, 0.50, 0.75, 1.00 };
 
 #ifdef WITH_FFMPEG
-static int tc_types[] = { IMB_TC_RECORD_RUN,
-                          IMB_TC_FREE_RUN,
-                          IMB_TC_INTERPOLATED_REC_DATE_FREE_RUN,
-                          IMB_TC_RECORD_RUN_NO_GAPS,
-                        };
+static int tc_types[] = {IMB_TC_RECORD_RUN,
+                         IMB_TC_FREE_RUN,
+                         IMB_TC_INTERPOLATED_REC_DATE_FREE_RUN,
+                         IMB_TC_RECORD_RUN_NO_GAPS};
 #endif
 
 #define INDEX_FILE_VERSION 1
@@ -65,11 +64,11 @@ static int tc_types[] = { IMB_TC_RECORD_RUN,
  * - time code index functions
  * ---------------------------------------------------------------------- */
 
-anim_index_builder * IMB_index_builder_create(const char * name)
+anim_index_builder *IMB_index_builder_create(const char *name)
 {
 
-       anim_index_builder * rv = MEM_callocN(sizeof(struct anim_index_builder),
-                                             "index builder");
+       anim_index_builder *rv = MEM_callocN(sizeof(struct anim_index_builder),
+                                            "index builder");
 
        fprintf(stderr, "Starting work on index: %s\n", name);
 
@@ -84,21 +83,21 @@ anim_index_builder * IMB_index_builder_create(const char * name)
 
        if (!rv->fp) {
                fprintf(stderr, "Couldn't open index target: %s! "
-                       "Index build broken!\n", rv->temp_name);
+                       "Index build broken!\n", rv->temp_name);
                MEM_freeN(rv);
                return NULL;
        }
 
-       fprintf(rv->fp, "%s%c%.3d", magic, (ENDIAN_ORDER==B_ENDIAN)?'V':'v',
-               INDEX_FILE_VERSION);
+       fprintf(rv->fp, "%s%c%.3d", magic, (ENDIAN_ORDER == B_ENDIAN) ? 'V' : 'v',
+               INDEX_FILE_VERSION);
 
        return rv;
 }
 
-void IMB_index_builder_add_entry(anim_index_builder * fp, 
-                                int frameno, unsigned long long seek_pos,
-                                unsigned long long seek_pos_dts,
-                                unsigned long long pts)
+void IMB_index_builder_add_entry(anim_index_builder *fp,
+                                 int frameno, unsigned long long seek_pos,
+                                 unsigned long long seek_pos_dts,
+                                 unsigned long long pts)
 {
        fwrite(&frameno, sizeof(int), 1, fp->fp);
        fwrite(&seek_pos, sizeof(unsigned long long), 1, fp->fp);
@@ -106,12 +105,12 @@ void IMB_index_builder_add_entry(anim_index_builder * fp,
        fwrite(&pts, sizeof(unsigned long long), 1, fp->fp);
 }
 
-void IMB_index_builder_proc_frame(anim_index_builder * fp, 
-                                 unsigned char * buffer,
-                                 int data_size,
-                                 int frameno, unsigned long long seek_pos,
-                                 unsigned long long seek_pos_dts,
-                                 unsigned long long pts)
+void IMB_index_builder_proc_frame(anim_index_builder *fp,
+                                  unsigned char *buffer,
+                                  int data_size,
+                                  int frameno, unsigned long long seek_pos,
+                                  unsigned long long seek_pos_dts,
+                                  unsigned long long pts)
 {
        if (fp->proc_frame) {
                anim_index_entry e;
@@ -124,11 +123,11 @@ void IMB_index_builder_proc_frame(anim_index_builder * fp,
        }
        else {
                IMB_index_builder_add_entry(fp, frameno, seek_pos,
-                                           seek_pos_dts, pts);
+                                           seek_pos_dts, pts);
        }
 }
 
-void IMB_index_builder_finish(anim_index_builder * fp, int rollback)
+void IMB_index_builder_finish(anim_index_builder *fp, int rollback)
 {
        if (fp->delete_priv_data) {
                fp->delete_priv_data(fp);
@@ -147,11 +146,11 @@ void IMB_index_builder_finish(anim_index_builder * fp, int rollback)
        MEM_freeN(fp);
 }
 
-struct anim_index * IMB_indexer_open(const char * name)
+struct anim_index *IMB_indexer_open(const char *name)
 {
        char header[13];
-       struct anim_index * idx;
-       FILE * fp = BLI_fopen(name, "rb");
+       struct anim_index *idx;
+       FILE *fp = BLI_fopen(name, "rb");
        int i;
 
        if (!fp) {
@@ -170,7 +169,7 @@ struct anim_index * IMB_indexer_open(const char * name)
                return NULL;
        }
 
-       if (atoi(header+9) != INDEX_FILE_VERSION) {
+       if (atoi(header + 9) != INDEX_FILE_VERSION) {
                fclose(fp);
                return NULL;
        }
@@ -182,11 +181,11 @@ struct anim_index * IMB_indexer_open(const char * name)
        fseek(fp, 0, SEEK_END);
 
        idx->num_entries = (ftell(fp) - 12) /
-               (sizeof(int) + // framepos
-                sizeof(unsigned long long) + // seek_pos
-                sizeof(unsigned long long) + // seek_pos_dts
-                sizeof(unsigned long long) // pts
-                );
+                          (sizeof(int) + // framepos
+                           sizeof(unsigned long long) + // seek_pos
+                           sizeof(unsigned long long) + // seek_pos_dts
+                           sizeof(unsigned long long) // pts
+                          );
        
        fseek(fp, 12, SEEK_SET);
 
@@ -219,7 +218,7 @@ struct anim_index * IMB_indexer_open(const char * name)
 }
 
 unsigned long long IMB_indexer_get_seek_pos(
-       struct anim_index * idx, int frame_index)
+    struct anim_index *idx, int frame_index)
 {
        if (frame_index < 0) {
                frame_index = 0;
@@ -231,7 +230,7 @@ unsigned long long IMB_indexer_get_seek_pos(
 }
 
 unsigned long long IMB_indexer_get_seek_pos_dts(
-       struct anim_index * idx, int frame_index)
+    struct anim_index *idx, int frame_index)
 {
        if (frame_index < 0) {
                frame_index = 0;
@@ -242,7 +241,7 @@ unsigned long long IMB_indexer_get_seek_pos_dts(
        return idx->entries[frame_index].seek_pos_dts;
 }
 
-int IMB_indexer_get_frame_index(struct anim_index * idx, int frameno)
+int IMB_indexer_get_frame_index(struct anim_index *idx, int frameno)
 {
        int len = idx->num_entries;
        int half;
@@ -275,8 +274,8 @@ int IMB_indexer_get_frame_index(struct anim_index * idx, int frameno)
        }
 }
 
-unsigned long long IMB_indexer_get_pts(struct anim_index * idx, 
-                                      int frame_index)
+unsigned long long IMB_indexer_get_pts(struct anim_index *idx,
+                                       int frame_index)
 {
        if (frame_index < 0) {
                frame_index = 0;
@@ -287,16 +286,16 @@ unsigned long long IMB_indexer_get_pts(struct anim_index * idx,
        return idx->entries[frame_index].pts;
 }
 
-int IMB_indexer_get_duration(struct anim_index * idx)
+int IMB_indexer_get_duration(struct anim_index *idx)
 {
        if (idx->num_entries == 0) {
                return 0;
        }
-       return idx->entries[idx->num_entries-1].frameno + 1;
+       return idx->entries[idx->num_entries - 1].frameno + 1;
 }
 
-int IMB_indexer_can_scan(struct anim_index * idx, 
-                        int old_frame_index, int new_frame_index)
+int IMB_indexer_can_scan(struct anim_index *idx,
+                         int old_frame_index, int new_frame_index)
 {
        /* makes only sense, if it is the same I-Frame and we are not
         * trying to run backwards in time... */
@@ -304,7 +303,7 @@ int IMB_indexer_can_scan(struct anim_index * idx,
                old_frame_index < new_frame_index);
 }
 
-void IMB_indexer_close(struct anim_index * idx)
+void IMB_indexer_close(struct anim_index *idx)
 {
        MEM_freeN(idx->entries);
        MEM_freeN(idx);
@@ -313,19 +312,19 @@ void IMB_indexer_close(struct anim_index * idx)
 int IMB_proxy_size_to_array_index(IMB_Proxy_Size pr_size)
 {
        switch (pr_size) {
-       case IMB_PROXY_NONE: /* if we got here, something is broken anyways,
-                               so sane defaults... */
-               return 0;
-       case IMB_PROXY_25:
-               return 0;
-       case IMB_PROXY_50:
-               return 1;
-       case IMB_PROXY_75:
-               return 2;
-       case IMB_PROXY_100:
-               return 3;
-       default:
-               return 0;
+               case IMB_PROXY_NONE: /* if we got here, something is broken anyways,
+                                       so sane defaults... */
+                       return 0;
+               case IMB_PROXY_25:
+                       return 0;
+               case IMB_PROXY_50:
+                       return 1;
+               case IMB_PROXY_75:
+                       return 2;
+               case IMB_PROXY_100:
+                       return 3;
+               default:
+                       return 0;
        };
        return 0;
 }
@@ -333,19 +332,19 @@ int IMB_proxy_size_to_array_index(IMB_Proxy_Size pr_size)
 int IMB_timecode_to_array_index(IMB_Timecode_Type tc)
 {
        switch (tc) {
-       case IMB_TC_NONE: /* if we got here, something is broken anyways,
-                               so sane defaults... */
-               return 0;
-       case IMB_TC_RECORD_RUN:
-               return 0;
-       case IMB_TC_FREE_RUN:
-               return 1;
-       case IMB_TC_INTERPOLATED_REC_DATE_FREE_RUN:
-               return 2;
-       case IMB_TC_RECORD_RUN_NO_GAPS:
-               return 3;
-       default:
-               return 0;
+               case IMB_TC_NONE: /* if we got here, something is broken anyways,
+                                    so sane defaults... */
+                       return 0;
+               case IMB_TC_RECORD_RUN:
+                       return 0;
+               case IMB_TC_FREE_RUN:
+                       return 1;
+               case IMB_TC_INTERPOLATED_REC_DATE_FREE_RUN:
+                       return 2;
+               case IMB_TC_RECORD_RUN_NO_GAPS:
+                       return 3;
+               default:
+                       return 0;
        };
        return 0;
 }
@@ -355,7 +354,7 @@ int IMB_timecode_to_array_index(IMB_Timecode_Type tc)
  * - rebuild helper functions
  * ---------------------------------------------------------------------- */
 
-static void get_index_dir(struct anim * anim, char * index_dir)
+static void get_index_dir(struct anim *anim, char *index_dir)
 {
        if (!anim->index_dir[0]) {
                char fname[FILE_MAXFILE];
@@ -369,8 +368,8 @@ static void get_index_dir(struct anim * anim, char * index_dir)
        }
 }
 
-static void get_proxy_filename(struct anim * anim, IMB_Proxy_Size preview_size,
-                              char * fname, int temp)
+static void get_proxy_filename(struct anim *anim, IMB_Proxy_Size preview_size,
+                               char *fname, int temp)
 {
        char index_dir[FILE_MAXDIR];
        int i = IMB_proxy_size_to_array_index(preview_size);
@@ -386,9 +385,9 @@ static void get_proxy_filename(struct anim * anim, IMB_Proxy_Size preview_size,
        }
 
        BLI_snprintf(proxy_name, sizeof(proxy_name), "proxy_%d%s.avi",
-                    (int) (proxy_fac[i] * 100), stream_suffix);
+                    (int) (proxy_fac[i] * 100), stream_suffix);
        BLI_snprintf(proxy_temp_name, sizeof(proxy_temp_name), "proxy_%d%s_part.avi",
-                    (int) (proxy_fac[i] * 100), stream_suffix);
+                    (int) (proxy_fac[i] * 100), stream_suffix);
 
        get_index_dir(anim, index_dir);
 
@@ -396,16 +395,17 @@ static void get_proxy_filename(struct anim * anim, IMB_Proxy_Size preview_size,
                         temp ? proxy_temp_name : proxy_name);
 }
 
-static void get_tc_filename(struct anim * anim, IMB_Timecode_Type tc,
-                           char * fname)
+static void get_tc_filename(struct anim *anim, IMB_Timecode_Type tc,
+                            char *fname)
 {
        char index_dir[FILE_MAXDIR];
        int i = IMB_timecode_to_array_index(tc);
-       const char * index_names[] = {
+       const char *index_names[] = {
                "record_run%s.blen_tc",
                "free_run%s.blen_tc",
                "interp_free_run%s.blen_tc",
-               "record_run_no_gaps%s.blen_tc"};
+               "record_run_no_gaps%s.blen_tc"
+       };
 
        char stream_suffix[20];
        char index_name[256];
@@ -440,18 +440,18 @@ typedef struct IndexBuildContext {
 #ifdef WITH_FFMPEG
 
 struct proxy_output_ctx {
-       AVFormatContextof;
-       AVStreamst;
-       AVCodecContextc;
-       AVCodeccodec;
-       struct SwsContext * sws_ctx;
-       AVFrameframe;
-       uint8_tvideo_buffer;
+       AVFormatContext *of;
+       AVStream *st;
+       AVCodecContext *c;
+       AVCodec *codec;
+       struct SwsContext *sws_ctx;
+       AVFrame *frame;
+       uint8_t *video_buffer;
        int video_buffersize;
        int cfra;
        int proxy_size;
        int orig_height;
-       struct anim * anim;
+       struct anim *anim;
 };
 
 // work around stupid swscaler 16 bytes alignment bug...
@@ -461,13 +461,13 @@ static int round_up(int x, int mod)
        return x + ((mod - (x % mod)) % mod);
 }
 
-static struct proxy_output_ctx * alloc_proxy_output_ffmpeg(
-       struct anim * anim,
-       AVStream * st, int proxy_size, int width, int height,
-       int quality)
+static struct proxy_output_ctx *alloc_proxy_output_ffmpeg(
+        struct anim *anim,
+        AVStream *st, int proxy_size, int width, int height,
+        int quality)
 {
-       struct proxy_output_ctx * rv = MEM_callocN(
-               sizeof(struct proxy_output_ctx), "alloc_proxy_output");
+       struct proxy_output_ctx *rv = MEM_callocN(
+               sizeof(struct proxy_output_ctx), "alloc_proxy_output");
        
        char fname[FILE_MAX];
        int ffmpeg_quality;
@@ -501,7 +501,7 @@ static struct proxy_output_ctx * alloc_proxy_output_ffmpeg(
 
        if (!rv->codec) {
                fprintf(stderr, "No ffmpeg MJPEG encoder available? "
-                       "Proxy not built!\n");
+                       "Proxy not built!\n");
                av_free(rv->of);
                return NULL;
        }
@@ -514,7 +514,7 @@ static struct proxy_output_ctx * alloc_proxy_output_ffmpeg(
        }
 
        rv->c->sample_aspect_ratio =
-               rv->st->sample_aspect_ratio =
+           rv->st->sample_aspect_ratio =
                st->codec->sample_aspect_ratio;
 
        rv->c->time_base.den = 25;
@@ -533,14 +533,14 @@ static struct proxy_output_ctx * alloc_proxy_output_ffmpeg(
 
        if (av_set_parameters(rv->of, NULL) < 0) {
                fprintf(stderr, "Couldn't set output parameters? "
-                       "Proxy not built!\n");
+                       "Proxy not built!\n");
                av_free(rv->of);
                return 0;
        }
 
        if (avio_open(&rv->of->pb, fname, AVIO_FLAG_WRITE) < 0) {
                fprintf(stderr, "Couldn't open outputfile! "
-                       "Proxy not built!\n");
+                       "Proxy not built!\n");
                av_free(rv->of);
                return 0;
        }
@@ -548,16 +548,16 @@ static struct proxy_output_ctx * alloc_proxy_output_ffmpeg(
        avcodec_open(rv->c, rv->codec);
 
        rv->video_buffersize = 2000000;
-       rv->video_buffer = (uint8_t*)MEM_mallocN(
-               rv->video_buffersize, "FFMPEG video buffer");
+       rv->video_buffer = (uint8_t *)MEM_mallocN(
+               rv->video_buffersize, "FFMPEG video buffer");
 
        rv->orig_height = st->codec->height;
 
        if (st->codec->width != width || st->codec->height != height ||
-               st->codec->pix_fmt != rv->c->pix_fmt)
+           st->codec->pix_fmt != rv->c->pix_fmt)
        {
                rv->frame = avcodec_alloc_frame();
-               avpicture_fill((AVPicture*) rv->frame,
+               avpicture_fill((AVPicture *) rv->frame,
                               MEM_mallocN(avpicture_get_size(
                                               rv->c->pix_fmt,
                                               round_up(width, 16), height),
@@ -565,13 +565,13 @@ static struct proxy_output_ctx * alloc_proxy_output_ffmpeg(
                               rv->c->pix_fmt, round_up(width, 16), height);
 
                rv->sws_ctx = sws_getContext(
-                       st->codec->width,
-                       st->codec->height,
-                       st->codec->pix_fmt,
-                       width, height,
-                       rv->c->pix_fmt,
-                       SWS_FAST_BILINEAR | SWS_PRINT_INFO,
-                       NULL, NULL, NULL);
+                       st->codec->width,
+                       st->codec->height,
+                       st->codec->pix_fmt,
+                       width, height,
+                       rv->c->pix_fmt,
+                       SWS_FAST_BILINEAR | SWS_PRINT_INFO,
+                       NULL, NULL, NULL);
        }
 
        av_write_header(rv->of);
@@ -580,7 +580,7 @@ static struct proxy_output_ctx * alloc_proxy_output_ffmpeg(
 }
 
 static int add_to_proxy_output_ffmpeg(
-       struct proxy_output_ctx * ctx, AVFrame * frame)
+    struct proxy_output_ctx *ctx, AVFrame *frame)
 {
        int outsize = 0;
 
@@ -588,11 +588,11 @@ static int add_to_proxy_output_ffmpeg(
                return 0;
        }
 
-       if (    ctx->sws_ctx && frame &&
-               (frame->data[0] || frame->data[1] ||
-                frame->data[2] || frame->data[3]))
+       if (ctx->sws_ctx && frame &&
+           (frame->data[0] || frame->data[1] ||
+            frame->data[2] || frame->data[3]))
        {
-               sws_scale(ctx->sws_ctx, (const uint8_t * const*) frame->data,
+               sws_scale(ctx->sws_ctx, (const uint8_t *const *) frame->data,
                          frame->linesize, 0, ctx->orig_height,
                          ctx->frame->data, ctx->frame->linesize);
        }
@@ -604,12 +604,12 @@ static int add_to_proxy_output_ffmpeg(
        }
 
        outsize = avcodec_encode_video(
-               ctx->c, ctx->video_buffer, ctx->video_buffersize, 
-               frame);
+               ctx->c, ctx->video_buffer, ctx->video_buffersize,
+               frame);
 
        if (outsize < 0) {
                fprintf(stderr, "Error encoding proxy frame %d for '%s'\n", 
-                       ctx->cfra - 1, ctx->of->filename);
+                       ctx->cfra - 1, ctx->of->filename);
                return 0;
        }
 
@@ -619,8 +619,8 @@ static int add_to_proxy_output_ffmpeg(
 
                if (ctx->c->coded_frame->pts != AV_NOPTS_VALUE) {
                        packet.pts = av_rescale_q(ctx->c->coded_frame->pts,
-                                                 ctx->c->time_base,
-                                                 ctx->st->time_base);
+                                                 ctx->c->time_base,
+                                                 ctx->st->time_base);
                }
                if (ctx->c->coded_frame->key_frame)
                        packet.flags |= AV_PKT_FLAG_KEY;
@@ -631,8 +631,8 @@ static int add_to_proxy_output_ffmpeg(
 
                if (av_interleaved_write_frame(ctx->of, &packet) != 0) {
                        fprintf(stderr, "Error writing proxy frame %d "
-                               "into '%s'\n", ctx->cfra - 1, 
-                               ctx->of->filename);
+                               "into '%s'\n", ctx->cfra - 1,
+                               ctx->of->filename);
                        return 0;
                }
 
@@ -643,8 +643,8 @@ static int add_to_proxy_output_ffmpeg(
        }
 }
 
-static void free_proxy_output_ffmpeg(struct proxy_output_ctx * ctx,
-                                    int rollback)
+static void free_proxy_output_ffmpeg(struct proxy_output_ctx *ctx,
+                                     int rollback)
 {
        int i;
        char fname[FILE_MAX];
@@ -714,8 +714,8 @@ typedef struct FFmpegIndexBuilderContext {
        int num_proxy_sizes;
        int num_indexers;
 
-       struct proxy_output_ctx * proxy_ctx[IMB_PROXY_MAX_SLOT];
-       anim_index_builder * indexer [IMB_TC_MAX_SLOT];
+       struct proxy_output_ctx *proxy_ctx[IMB_PROXY_MAX_SLOT];
+       anim_index_builder *indexer[IMB_TC_MAX_SLOT];
 
        IMB_Timecode_Type tcs_in_use;
        IMB_Proxy_Size proxy_sizes_in_use;
@@ -790,10 +790,10 @@ static IndexBuildContext *index_ffmpeg_create_context(struct anim *anim, IMB_Tim
        for (i = 0; i < num_proxy_sizes; i++) {
                if (proxy_sizes_in_use & proxy_sizes[i]) {
                        context->proxy_ctx[i] = alloc_proxy_output_ffmpeg(
-                               anim, context->iStream, proxy_sizes[i],
-                               context->iCodecCtx->width * proxy_fac[i],
-                               context->iCodecCtx->height * proxy_fac[i],
-                               quality);
+                               anim, context->iStream, proxy_sizes[i],
+                               context->iCodecCtx->width * proxy_fac[i],
+                               context->iCodecCtx->height * proxy_fac[i],
+                               quality);
                        if (!context->proxy_ctx[i]) {
                                proxy_sizes_in_use &= ~proxy_sizes[i];
                        }
@@ -849,7 +849,7 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context,
        double pts_time_base;
        int frameno = 0, frameno_gapless = 0;
        int start_pts_set = FALSE;
-       AVFramein_frame = 0;
+       AVFrame *in_frame = 0;
        AVPacket next_packet;
        uint64_t stream_size;
 
@@ -863,7 +863,7 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context,
        while (av_read_frame(context->iFormatCtx, &next_packet) >= 0) {
                int frame_finished = 0;
                float next_progress =  (float)((int)floor(((double) next_packet.pos) * 100 /
-                                                  ((double) stream_size)+0.5)) / 100;
+                                                         ((double) stream_size) + 0.5)) / 100;
 
                if (*progress != next_progress) {
                        *progress = next_progress;
@@ -885,8 +885,8 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context,
                        }
 
                        avcodec_decode_video2(
-                               context->iCodecCtx, in_frame, &frame_finished,
-                               &next_packet);
+                               context->iCodecCtx, in_frame, &frame_finished,
+                               &next_packet);
                }
 
                if (frame_finished) {
@@ -896,7 +896,7 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context,
 
                        for (i = 0; i < context->num_proxy_sizes; i++) {
                                add_to_proxy_output_ffmpeg(
-                                       context->proxy_ctx[i], in_frame);
+                                       context->proxy_ctx[i], in_frame);
                        }
 
                        if (!start_pts_set) {
@@ -927,11 +927,11 @@ static int index_rebuild_ffmpeg(FFmpegIndexBuilderContext *context,
                                                tc_frameno = frameno_gapless;
 
                                        IMB_index_builder_proc_frame(
-                                               context->indexer[i],
-                                               next_packet.data, 
-                                               next_packet.size,
-                                               tc_frameno,
-                                               s_pos, s_dts, pts);
+                                               context->indexer[i],
+                                               next_packet.data,
+                                               next_packet.size,
+                                               tc_frameno,
+                                               s_pos, s_dts, pts);
                                }
                        }
 
@@ -959,16 +959,16 @@ typedef struct FallbackIndexBuilderContext {
        IMB_Proxy_Size proxy_sizes_in_use;
 } FallbackIndexBuilderContext;
 
-static AviMovie * alloc_proxy_output_avi(
-       struct anim * anim, char * filename, int width, int height,
-       int quality)
+static AviMovie *alloc_proxy_output_avi(
+        struct anim *anim, char *filename, int width, int height,
+        int quality)
 {
        int x, y;
        AviFormat format;
        double framerate;
-       AviMovie * avi;
+       AviMovie *avi;
        short frs_sec = 25;      /* it doesn't really matter for proxies,
-                                   but sane defaults help anyways...*/
+                                   but sane defaults help anyways...*/
        float frs_sec_base = 1.0;
 
        IMB_anim_get_fps(anim, &frs_sec, &frs_sec_base);
@@ -976,24 +976,24 @@ static AviMovie * alloc_proxy_output_avi(
        x = width;
        y = height;
 
-       framerate= (double) frs_sec / (double) frs_sec_base;
+       framerate = (double) frs_sec / (double) frs_sec_base;
        
-       avi = MEM_mallocN (sizeof(AviMovie), "avimovie");
+       avi = MEM_mallocN(sizeof(AviMovie), "avimovie");
 
        format = AVI_FORMAT_MJPEG;
 
-       if (AVI_open_compress (filename, avi, 1, format) != AVI_ERROR_NONE) {
+       if (AVI_open_compress(filename, avi, 1, format) != AVI_ERROR_NONE) {
                MEM_freeN(avi);
                return NULL;
        }
                        
-       AVI_set_compress_option (avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_WIDTH, &x);
-       AVI_set_compress_option (avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_HEIGHT, &y);
-       AVI_set_compress_option (avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_QUALITY, &quality);           
-       AVI_set_compress_option (avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_FRAMERATE, &framerate);
+       AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_WIDTH, &x);
+       AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_HEIGHT, &y);
+       AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_QUALITY, &quality);
+       AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_FRAMERATE, &framerate);
 
-       avi->interlace= 0;
-       avi->odd_fields= 0;
+       avi->interlace = 0;
+       avi->odd_fields = 0;
 
        return avi;
 }
@@ -1005,10 +1005,10 @@ static IndexBuildContext *index_fallback_create_context(struct anim *anim, IMB_T
        int i;
 
        /* since timecode indices only work with ffmpeg right now,
-          don't know a sensible fallback here...
-
-          so no proxies, no game to play...
-       */
+        * don't know a sensible fallback here...
+        *
+        * so no proxies, no game to play...
+        */
        if (proxy_sizes_in_use == IMB_PROXY_NONE) {
                return NULL;
        }
@@ -1028,7 +1028,7 @@ static IndexBuildContext *index_fallback_create_context(struct anim *anim, IMB_T
                        BLI_make_existing_file(fname);
 
                        context->proxy_ctx[i] = alloc_proxy_output_avi(anim, fname,
-                               anim->x * proxy_fac[i], anim->y * proxy_fac[i], quality);
+                                                                      anim->x * proxy_fac[i], anim->y * proxy_fac[i], quality);
                }
        }
 
@@ -1089,15 +1089,15 @@ static void index_rebuild_fallback(FallbackIndexBuilderContext *context,
                                int x = anim->x * proxy_fac[i];
                                int y = anim->y * proxy_fac[i];
 
-                               struct ImBuf * s_ibuf = IMB_dupImBuf(tmp_ibuf);
+                               struct ImBuf *s_ibuf = IMB_dupImBuf(tmp_ibuf);
 
                                IMB_scalefastImBuf(s_ibuf, x, y);
 
                                IMB_convert_rgba_to_abgr(s_ibuf);
        
-                               AVI_write_frame (context->proxy_ctx[i], pos, 
-                                                AVI_FORMAT_RGB32, 
-                                                s_ibuf->rect, x * y * 4);
+                               AVI_write_frame(context->proxy_ctx[i], pos,
+                                               AVI_FORMAT_RGB32,
+                                               s_ibuf->rect, x * y * 4);
 
                                /* note that libavi free's the buffer... */
                                s_ibuf->rect = NULL;
@@ -1116,19 +1116,19 @@ static void index_rebuild_fallback(FallbackIndexBuilderContext *context,
  * ---------------------------------------------------------------------- */
 
 IndexBuildContext *IMB_anim_index_rebuild_context(struct anim *anim, IMB_Timecode_Type tcs_in_use,
-                                                         IMB_Proxy_Size proxy_sizes_in_use, int quality)
+                                                  IMB_Proxy_Size proxy_sizes_in_use, int quality)
 {
        IndexBuildContext *context = NULL;
 
        switch (anim->curtype) {
 #ifdef WITH_FFMPEG
-       case ANIM_FFMPEG:
-               context = index_ffmpeg_create_context(anim, tcs_in_use, proxy_sizes_in_use, quality);
-               break;
+               case ANIM_FFMPEG:
+                       context = index_ffmpeg_create_context(anim, tcs_in_use, proxy_sizes_in_use, quality);
+                       break;
 #endif
-       default:
-               context = index_fallback_create_context(anim, tcs_in_use, proxy_sizes_in_use, quality);
-               break;
+               default:
+                       context = index_fallback_create_context(anim, tcs_in_use, proxy_sizes_in_use, quality);
+                       break;
        }
 
        if (context)
@@ -1142,13 +1142,13 @@ void IMB_anim_index_rebuild(struct IndexBuildContext *context,
 {
        switch (context->anim_type) {
 #ifdef WITH_FFMPEG
-       case ANIM_FFMPEG:
-               index_rebuild_ffmpeg((FFmpegIndexBuilderContext*)context, stop, do_update, progress);
-               break;
+               case ANIM_FFMPEG:
+                       index_rebuild_ffmpeg((FFmpegIndexBuilderContext *)context, stop, do_update, progress);
+                       break;
 #endif
-       default:
-               index_rebuild_fallback((FallbackIndexBuilderContext*)context, stop, do_update, progress);
-               break;
+               default:
+                       index_rebuild_fallback((FallbackIndexBuilderContext *)context, stop, do_update, progress);
+                       break;
        }
 }
 
@@ -1156,18 +1156,18 @@ void IMB_anim_index_rebuild_finish(IndexBuildContext *context, short stop)
 {
        switch (context->anim_type) {
 #ifdef WITH_FFMPEG
-       case ANIM_FFMPEG:
-               index_rebuild_ffmpeg_finish((FFmpegIndexBuilderContext*)context, stop);
-               break;
+               case ANIM_FFMPEG:
+                       index_rebuild_ffmpeg_finish((FFmpegIndexBuilderContext *)context, stop);
+                       break;
 #endif
-       default:
-               index_rebuild_fallback_finish((FallbackIndexBuilderContext*)context, stop);
-               break;
+               default:
+                       index_rebuild_fallback_finish((FallbackIndexBuilderContext *)context, stop);
+                       break;
        }
 }
 
 
-void IMB_free_indices(struct anim * anim)
+void IMB_free_indices(struct anim *anim)
 {
        int i;
 
@@ -1190,7 +1190,7 @@ void IMB_free_indices(struct anim * anim)
        anim->indices_tried = 0;
 }
 
-void IMB_anim_set_index_dir(struct anim * anim, const char * dir)
+void IMB_anim_set_index_dir(struct anim *anim, const char *dir)
 {
        if (strcmp(anim->index_dir, dir) == 0) {
                return;
@@ -1200,8 +1200,8 @@ void IMB_anim_set_index_dir(struct anim * anim, const char * dir)
        IMB_free_indices(anim);
 }
 
-struct anim * IMB_anim_open_proxy(
-       struct anim * anim, IMB_Proxy_Size preview_size)
+struct anim *IMB_anim_open_proxy(
+        struct anim *anim, IMB_Proxy_Size preview_size)
 {
        char fname[FILE_MAX];
        int i = IMB_proxy_size_to_array_index(preview_size);
@@ -1223,8 +1223,8 @@ struct anim * IMB_anim_open_proxy(
        return anim->proxy_anim[i];
 }
 
-struct anim_index * IMB_anim_open_index(
-       struct anim * anim, IMB_Timecode_Type tc)
+struct anim_index *IMB_anim_open_index(
+        struct anim *anim, IMB_Timecode_Type tc)
 {
        char fname[FILE_MAX];
        int i = IMB_timecode_to_array_index(tc);
@@ -1246,10 +1246,10 @@ struct anim_index * IMB_anim_open_index(
        return anim->curr_idx[i];
 }
 
-int IMB_anim_index_get_frame_index(struct anim * anim, IMB_Timecode_Type tc,
-                                  int position)
+int IMB_anim_index_get_frame_index(struct anim *anim, IMB_Timecode_Type tc,
+                                   int position)
 {
-       struct anim_index * idx = IMB_anim_open_index(anim, tc);
+       struct anim_index *idx = IMB_anim_open_index(anim, tc);
 
        if (!idx) {
                return position;
index 8dc03ae708dbe1332ed7bc7ca538e7d9f0a288fe..460ca93435eedf7127662a3144f44b6c234b17f8 100644 (file)
 #include <time.h>
 
 typedef struct indexer_dv_bitstream {
-       unsigned charbuffer;
+       unsigned char *buffer;
        int bit_pos;
 } indexer_dv_bitstream;
 
-static indexer_dv_bitstream bitstream_new(unsigned char* buffer_) 
+static indexer_dv_bitstream bitstream_new(unsigned char *buffer_)
 {
        indexer_dv_bitstream rv;
 
@@ -42,27 +42,27 @@ static indexer_dv_bitstream bitstream_new(unsigned char* buffer_)
        return rv;
 }
 
-static unsigned long bitstream_get_bits(indexer_dv_bitstream * This, int num) 
+static unsigned long bitstream_get_bits(indexer_dv_bitstream *This, int num)
 {
        int byte_pos = This->bit_pos >> 3;
        unsigned long i = 
-               This->buffer[byte_pos] | (This->buffer[byte_pos + 1] << 8) |
-               (This->buffer[byte_pos + 2] << 16) | 
-               (This->buffer[byte_pos + 3] << 24);
+               This->buffer[byte_pos] | (This->buffer[byte_pos + 1] << 8) |
+               (This->buffer[byte_pos + 2] << 16) |
+               (This->buffer[byte_pos + 3] << 24);
        int rval = (i >> (This->bit_pos & 0x7)) & ((1 << num) - 1);
        This->bit_pos += num;
        return rval;
 }
 
-static int parse_num(indexer_dv_bitstream * b, int numbits)
+static int parse_num(indexer_dv_bitstream *b, int numbits)
 {
        return bitstream_get_bits(b, numbits);
 }
 
-static int parse_bcd(indexer_dv_bitstream * b, int n) 
+static int parse_bcd(indexer_dv_bitstream *b, int n)
 {
        char s[256];
-       char * p = s + (n+3)/4;
+       char *p = s + (n + 3) / 4;
 
        *p-- = 0;
 
@@ -93,8 +93,7 @@ static int parse_bcd(indexer_dv_bitstream * b, int n)
        return atol(s);
 }
 
-typedef struct indexer_dv_context
-{
+typedef struct indexer_dv_context {
        int rec_curr_frame;
        int rec_curr_second;
        int rec_curr_minute;
@@ -119,10 +118,10 @@ typedef struct indexer_dv_context
        anim_index_entry backbuffer[31];
        int fsize;
 
-       anim_index_builder * idx;
+       anim_index_builder *idx;
 } indexer_dv_context;
 
-static void parse_packet(indexer_dv_context * This, unsigned char * p)
+static void parse_packet(indexer_dv_context *This, unsigned char *p)
 {
        indexer_dv_bitstream b;
        int type = p[0];
@@ -158,7 +157,7 @@ static void parse_packet(indexer_dv_context * This, unsigned char * p)
        }
 }
 
-static void parse_header_block(indexer_dv_context * This, unsigned char* target)
+static void parse_header_block(indexer_dv_context *This, unsigned char *target)
 {
        int i;
        for (i = 3; i < 80; i += 5) {
@@ -169,7 +168,7 @@ static void parse_header_block(indexer_dv_context * This, unsigned char* target)
 }
 
 static void parse_subcode_blocks(
-        indexer_dv_context * This, unsigned char* target)
+        indexer_dv_context *This, unsigned char *target)
 {
        int i, j;
 
@@ -183,7 +182,7 @@ static void parse_subcode_blocks(
 }
 
 static void parse_vaux_blocks(
-        indexer_dv_context * This, unsigned char* target)
+        indexer_dv_context *This, unsigned char *target)
 {
        int i, j;
 
@@ -198,7 +197,7 @@ static void parse_vaux_blocks(
 }
 
 static void parse_audio_headers(
-        indexer_dv_context * This, unsigned char* target)
+        indexer_dv_context *This, unsigned char *target)
 {
        int i;
 
@@ -210,11 +209,11 @@ static void parse_audio_headers(
        }
 }
 
-static void parse_frame(indexer_dv_context * This, 
-                        unsigned char * framebuffer, int isPAL)
+static void parse_frame(indexer_dv_context *This,
+                        unsigned char *framebuffer, int isPAL)
 {
        int numDIFseq = isPAL ? 12 : 10;
-       unsigned chartarget = framebuffer;
+       unsigned char *target = framebuffer;
        int ds;
 
        for (ds = 0; ds < numDIFseq; ds++) {
@@ -229,7 +228,7 @@ static void parse_frame(indexer_dv_context * This,
        }
 }
 
-static void inc_frame(int * frame, time_t * t, int isPAL)
+static void inc_frame(int *frame, time_t *t, int isPAL)
 {
        if ((isPAL && *frame >= 25) || (!isPAL && *frame >= 30)) {
                fprintf(stderr, "Ouchie: inc_frame: invalid_frameno: %d\n",
@@ -246,20 +245,21 @@ static void inc_frame(int * frame, time_t * t, int isPAL)
        }
 }
 
-static void write_index(indexer_dv_context * This, anim_index_entry * entry)
+static void write_index(indexer_dv_context *This, anim_index_entry *entry)
 {
        IMB_index_builder_add_entry(
-               This->idx, entry->frameno + This->frameno_offset, 
-               entry->seek_pos, entry->seek_pos_dts, entry->pts);
+               This->idx, entry->frameno + This->frameno_offset,
+               entry->seek_pos, entry->seek_pos_dts, entry->pts);
 }
 
-static void fill_gap(indexer_dv_context * This, int isPAL)
+static void fill_gap(indexer_dv_context *This, int isPAL)
 {
        int i;
 
        for (i = 0; i < This->fsize; i++) {
                if (This->gap_start == This->ref_time_read &&
-                       This->gap_frame == This->curr_frame) {
+                   This->gap_frame == This->curr_frame)
+               {
                        fprintf(stderr,
                                "indexer_dv::fill_gap: "
                                "can't seek backwards !\n");
@@ -280,8 +280,8 @@ static void fill_gap(indexer_dv_context * This, int isPAL)
        This->fsize = 0;
 }
 
-static void proc_frame(indexer_dv_context * This,
-                       unsigned charUNUSED(framebuffer), int isPAL)
+static void proc_frame(indexer_dv_context *This,
+                       unsigned char *UNUSED(framebuffer), int isPAL)
 {
        struct tm recDate;
        time_t t;
@@ -332,14 +332,14 @@ static void proc_frame(indexer_dv_context * This,
        }
 }
 
-static void indexer_dv_proc_frame(anim_index_builder * idx, 
-                                  unsigned char * buffer,
+static void indexer_dv_proc_frame(anim_index_builder *idx,
+                                  unsigned char *buffer,
                                   int UNUSED(data_size),
-                                  struct anim_index_entry * entry)
+                                  struct anim_index_entry *entry)
 {
        int isPAL;
        
-       indexer_dv_context * This = (indexer_dv_context *) idx->private_data;
+       indexer_dv_context *This = (indexer_dv_context *) idx->private_data;
 
        isPAL = (buffer[3] & 0x80);
 
@@ -362,29 +362,29 @@ static void indexer_dv_proc_frame(anim_index_builder * idx,
                                "backbuffer overrun, emergency flush");
 
                        for (i = 0; i < This->fsize; i++) {
-                               write_index(This, This->backbuffer+i);
+                               write_index(This, This->backbuffer + i);
                        }
                        This->fsize = 0;
                }
        }
 }
 
-static void indexer_dv_delete(anim_index_builder * idx)
+static void indexer_dv_delete(anim_index_builder *idx)
 {
        int i = 0;
-       indexer_dv_context * This = (indexer_dv_context *) idx->private_data;
+       indexer_dv_context *This = (indexer_dv_context *) idx->private_data;
 
        for (i = 0; i < This->fsize; i++) {
-               write_index(This, This->backbuffer+i);
+               write_index(This, This->backbuffer + i);
        }
 
        MEM_freeN(This);
 }
 
-void IMB_indexer_dv_new(anim_index_builder * idx)
+void IMB_indexer_dv_new(anim_index_builder *idx)
 {
-       indexer_dv_context * rv = MEM_callocN(
-                   sizeof(indexer_dv_context), "index_dv builder context");
+       indexer_dv_context *rv = MEM_callocN(
+               sizeof(indexer_dv_context), "index_dv builder context");
 
        rv->ref_time_read = -1;
        rv->curr_frame = -1;
index 430361dbb53ef3ea50520904bce3010a45386bd5..10c6a0fd012823a9fc40c799a65f33279fe1ba2a 100644 (file)
 #include "IMB_filetype.h"
 
 typedef struct {
-       unsigned short  imagic;         /* stuff saved on disk . . */
-       unsigned short  type;
-       unsigned short  dim;
-       unsigned short  xsize;
-       unsigned short  ysize;
-       unsigned short  zsize;
-       unsigned int    min;
-       unsigned int    max;
-       unsigned int    wastebytes;     
-       char            name[80];
-       unsigned int    colormap;
-
-       int             file;           /* stuff used in core only */
-       unsigned short  flags;
-       short           dorev;
-       short           x;
-       short           y;
-       short           z;
-       short           cnt;
-       unsigned short  *ptr;
-       unsigned short  *base;
-       unsigned short  *tmpbuf;
-       unsigned int    offset;
-       unsigned int    rleend;         /* for rle images */
-       unsigned int    *rowstart;      /* for rle images */
-       int             *rowsize;       /* for rle images */
+       unsigned short  imagic;      /* stuff saved on disk . . */
+       unsigned short  type;
+       unsigned short  dim;
+       unsigned short  xsize;
+       unsigned short  ysize;
+       unsigned short  zsize;
+       unsigned int    min;
+       unsigned int    max;
+       unsigned int    wastebytes;
+       char name[80];
+       unsigned int    colormap;
+
+       int file;               /* stuff used in core only */
+       unsigned short  flags;
+       short           dorev;
+       short           x;
+       short           y;
+       short           z;
+       short           cnt;
+       unsigned short *ptr;
+       unsigned short *base;
+       unsigned short *tmpbuf;
+       unsigned int    offset;
+       unsigned int    rleend;        /* for rle images */
+       unsigned int   *rowstart;  /* for rle images */
+       int            *rowsize;   /* for rle images */
 } IMAGE;
 
 #define RINTLUM (79)
 #define GINTLUM (156)
 #define BINTLUM (21)
 
-#define ILUM(r, g, b)  ((int)(RINTLUM * (r) + GINTLUM * (g) + BINTLUM * (b)) >> 8)
+#define ILUM(r, g, b)   ((int)(RINTLUM * (r) + GINTLUM * (g) + BINTLUM * (b)) >> 8)
 
-#define OFFSET_R       0       /* this is byte order dependent */
-#define OFFSET_G       1
-#define OFFSET_B       2
-#define OFFSET_A       3
+#define OFFSET_R    0   /* this is byte order dependent */
+#define OFFSET_G    1
+#define OFFSET_B    2
+#define OFFSET_A    3
 
-#define CHANOFFSET(z)  (3-(z)) /* this is byte order dependent */
+#define CHANOFFSET(z)   (3 - (z)) /* this is byte order dependent */
 
-#define TYPEMASK               0xff00
-#define BPPMASK                        0x00ff
-#define ITYPE_VERBATIM         0x0000
-#define ITYPE_RLE              0x0100
-#define ISRLE(type)            (((type) & 0xff00) == ITYPE_RLE)
-#define ISVERBATIM(type)       (((type) & 0xff00) == ITYPE_VERBATIM)
-#define BPP(type)              ((type) & BPPMASK)
-#define RLE(bpp)               (ITYPE_RLE | (bpp))
-#define VERBATIM(bpp)          (ITYPE_VERBATIM | (bpp))
-#define        IBUFSIZE(pixels)        ((pixels+(pixels>>6))<<2)
-#define        RLE_NOP                 0x00
+#define TYPEMASK        0xff00
+#define BPPMASK         0x00ff
+#define ITYPE_VERBATIM      0x0000
+#define ITYPE_RLE       0x0100
+#define ISRLE(type)     (((type) & 0xff00) == ITYPE_RLE)
+#define ISVERBATIM(type)    (((type) & 0xff00) == ITYPE_VERBATIM)
+#define BPP(type)       ((type) & BPPMASK)
+#define RLE(bpp)        (ITYPE_RLE | (bpp))
+#define VERBATIM(bpp)       (ITYPE_VERBATIM | (bpp))
+#define IBUFSIZE(pixels)    ((pixels + (pixels >> 6)) << 2)
+#define RLE_NOP         0x00
 
 /* funcs */
 static void readheader(FILE *inf, IMAGE *image);
@@ -118,37 +118,37 @@ static void lumrow(unsigned char *rgbptr, unsigned char *lumptr, int n);
  *
  */
 
-static uchar * file_data;
+static uchar *file_data;
 static int file_offset;
 
 static unsigned short getshort(FILE *inf)
 {
-       unsigned char * buf;
+       unsigned char *buf;
        (void)inf; /* unused */
 
        buf = file_data + file_offset;
        file_offset += 2;
        
-       return (buf[0]<<8)+(buf[1]<<0);
+       return (buf[0] << 8) + (buf[1] << 0);
 }
 
 static unsigned int getlong(FILE *inf)
 {
-       unsigned char * buf;
+       unsigned char *buf;
        (void)inf; /* unused */
        
        buf = file_data + file_offset;
        file_offset += 4;
        
-       return (buf[0]<<24)+(buf[1]<<16)+(buf[2]<<8)+(buf[3]<<0);
+       return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + (buf[3] << 0);
 }
 
 static void putshort(FILE *outf, unsigned short val)
 {
        unsigned char buf[2];
 
-       buf[0] = (val>>8);
-       buf[1] = (val>>0);
+       buf[0] = (val >> 8);
+       buf[1] = (val >> 0);
        fwrite(buf, 2, 1, outf);
 }
 
@@ -156,10 +156,10 @@ static int putlong(FILE *outf, unsigned int val)
 {
        unsigned char buf[4];
 
-       buf[0] = (val>>24);
-       buf[1] = (val>>16);
-       buf[2] = (val>>8);
-       buf[3] = (val>>0);
+       buf[0] = (val >> 24);
+       buf[1] = (val >> 16);
+       buf[2] = (val >> 8);
+       buf[3] = (val >> 0);
        return fwrite(buf, 4, 1, outf);
 }
 
@@ -176,7 +176,7 @@ static void readheader(FILE *inf, IMAGE *image)
 
 static int writeheader(FILE *outf, IMAGE *image)
 {
-       IMAGE t= {0};
+       IMAGE t = {0};
 
        fwrite(&t, sizeof(IMAGE), 1, outf);
        fseek(outf, 0, SEEK_SET);
@@ -216,14 +216,14 @@ static void test_endian_zbuf(struct ImBuf *ibuf)
        int len;
        int *zval;
        
-       if ( BIG_LONG(1) == 1 ) return;
+       if (BIG_LONG(1) == 1) return;
        if (ibuf->zbuf == NULL) return;
        
-       len= ibuf->x*ibuf->y;
-       zval= ibuf->zbuf;
+       len = ibuf->x * ibuf->y;
+       zval = ibuf->zbuf;
        
        while (len--) {
-               zval[0]= BIG_LONG(zval[0]);
+               zval[0] = BIG_LONG(zval[0]);
                zval++;
        }
 }
@@ -258,7 +258,7 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags)
        int x, y, z, tablen;
        int xsize, ysize, zsize;
        int bpp, rle, cur, badorder;
-       ImBuf * ibuf;
+       ImBuf *ibuf;
 
        (void)size; /* unused */
        
@@ -294,7 +294,7 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags)
        
        if (rle) {
                
-               tablen = ysize*zsize*sizeof(int);
+               tablen = ysize * zsize * sizeof(int);
                starttab = (unsigned int *)MEM_mallocN(tablen, "iris starttab");
                lengthtab = (unsigned int *)MEM_mallocN(tablen, "iris endtab");
                file_offset = 512;
@@ -305,13 +305,13 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags)
                /* check data order */
                cur = 0;
                badorder = 0;
-               for (y = 0; y<ysize; y++) {
-                       for (z = 0; z<zsize; z++) {
-                               if (starttab[y+z*ysize]<cur) {
+               for (y = 0; y < ysize; y++) {
+                       for (z = 0; z < zsize; z++) {
+                               if (starttab[y + z * ysize] < cur) {
                                        badorder = 1;
                                        break;
                                }
-                               cur = starttab[y+z*ysize];
+                               cur = starttab[y + z * ysize];
                        }
                        if (badorder)
                                break;
@@ -325,15 +325,15 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags)
                        zbase = (unsigned int *)ibuf->zbuf;
                        
                        if (badorder) {
-                               for (z=0; z<zsize; z++) {
+                               for (z = 0; z < zsize; z++) {
                                        lptr = base;
-                                       for (y=0; y<ysize; y++) {
-                                               file_offset = starttab[y+z*ysize];
+                                       for (y = 0; y < ysize; y++) {
+                                               file_offset = starttab[y + z * ysize];
                                                
                                                rledat = file_data + file_offset;
-                                               file_offset += lengthtab[y+z*ysize];
+                                               file_offset += lengthtab[y + z * ysize];
                                                
-                                               expandrow((uchar *)lptr, rledat, 3-z);
+                                               expandrow((uchar *)lptr, rledat, 3 - z);
                                                lptr += xsize;
                                        }
                                }
@@ -341,17 +341,17 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags)
                        else {
                                lptr = base;
                                zptr = zbase;
-                               for (y=0; y<ysize; y++) {
+                               for (y = 0; y < ysize; y++) {
                                
-                                       for (z=0; z<zsize; z++) {
+                                       for (z = 0; z < zsize; z++) {
                                                
-                                               file_offset = starttab[y+z*ysize];
+                                               file_offset = starttab[y + z * ysize];
 
                                                rledat = file_data + file_offset;
-                                               file_offset += lengthtab[y+z*ysize];
+                                               file_offset += lengthtab[y + z * ysize];
                                                
-                                               if (z<4) expandrow((uchar *)lptr, rledat, 3-z);
-                                               else if (z<8) expandrow((uchar *)zptr, rledat, 7-z);
+                                               if (z < 4) expandrow((uchar *)lptr, rledat, 3 - z);
+                                               else if (z < 8) expandrow((uchar *)zptr, rledat, 7 - z);
                                        }
                                        lptr += xsize;
                                        zptr += xsize;
@@ -360,22 +360,22 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags)
                        
 
                }
-               else {  /* bpp == 2 */
+               else {  /* bpp == 2 */
                        
-                       ibuf = IMB_allocImBuf(xsize, ysize, 32, (flags & IB_rect)|IB_rectfloat);
+                       ibuf = IMB_allocImBuf(xsize, ysize, 32, (flags & IB_rect) | IB_rectfloat);
                        
                        fbase = ibuf->rect_float;
                        
                        if (badorder) {
-                               for (z=0; z<zsize; z++) {
+                               for (z = 0; z < zsize; z++) {
                                        fptr = fbase;
-                                       for (y=0; y<ysize; y++) {
-                                               file_offset = starttab[y+z*ysize];
+                                       for (y = 0; y < ysize; y++) {
+                                               file_offset = starttab[y + z * ysize];
                                                
                                                rledat = file_data + file_offset;
-                                               file_offset += lengthtab[y+z*ysize];
+                                               file_offset += lengthtab[y + z * ysize];
                                                
-                                               expandrow2(fptr, rledat, 3-z);
+                                               expandrow2(fptr, rledat, 3 - z);
                                                fptr += xsize * 4;
                                        }
                                }
@@ -383,16 +383,16 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags)
                        else {
                                fptr = fbase;
 
-                               for (y=0; y<ysize; y++) {
+                               for (y = 0; y < ysize; y++) {
                                
-                                       for (z=0; z<zsize; z++) {
+                                       for (z = 0; z < zsize; z++) {
                                                
-                                               file_offset = starttab[y+z*ysize];
+                                               file_offset = starttab[y + z * ysize];
 
                                                rledat = file_data + file_offset;
-                                               file_offset += lengthtab[y+z*ysize];
+                                               file_offset += lengthtab[y + z * ysize];
                                                
-                                               expandrow2(fptr, rledat, 3-z);
+                                               expandrow2(fptr, rledat, 3 - z);
                                                
                                        }
                                        fptr += xsize * 4;
@@ -418,12 +418,12 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags)
                        
                        for (z = 0; z < zsize; z++) {
                                
-                               if (z<4) lptr = base;
-                               else if (z<8) lptr= zbase;
+                               if (z < 4) lptr = base;
+                               else if (z < 8) lptr = zbase;
                                
                                for (y = 0; y < ysize; y++) {
 
-                                       interleaverow((uchar *)lptr, rledat, 3-z, xsize);
+                                       interleaverow((uchar *)lptr, rledat, 3 - z, xsize);
                                        rledat += xsize;
                                        
                                        lptr += xsize;
@@ -431,9 +431,9 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags)
                        }
                        
                }
-               else {  /* bpp == 2 */
+               else {  /* bpp == 2 */
                        
-                       ibuf = IMB_allocImBuf(xsize, ysize, 32, (flags & IB_rect)|IB_rectfloat);
+                       ibuf = IMB_allocImBuf(xsize, ysize, 32, (flags & IB_rect) | IB_rectfloat);
 
                        fbase = ibuf->rect_float;
 
@@ -446,7 +446,7 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags)
                                
                                for (y = 0; y < ysize; y++) {
 
-                                       interleaverow2(fptr, rledat, 3-z, xsize);
+                                       interleaverow2(fptr, rledat, 3 - z, xsize);
                                        rledat += xsize * 2;
                                        
                                        fptr += xsize * 4;
@@ -458,7 +458,7 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags)
        
        
        if (bpp == 1) {
-               uchar * rect;
+               uchar *rect;
                
                if (image.zsize == 1) {
                        rect = (uchar *) ibuf->rect;
@@ -487,7 +487,7 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags)
                }
                
        }
-       else {  /* bpp == 2 */
+       else {  /* bpp == 2 */
                
                if (image.zsize == 1) {
                        fbase = ibuf->rect_float;
@@ -550,7 +550,7 @@ static void interleaverow2(float *lptr, unsigned char *cptr, int z, int n)
 {
        lptr += z;
        while (n--) {
-               *lptr = ((cptr[0]<<8) | (cptr[1]<<0)) / (float)0xFFFF;          
+               *lptr = ((cptr[0] << 8) | (cptr[1] << 0)) / (float)0xFFFF;
                cptr += 2;
                lptr += 4;
        }
@@ -563,50 +563,50 @@ static void expandrow2(float *optr, unsigned char *iptr, int z)
 
        optr += z;
        while (1) {
-               pixel = (iptr[0]<<8) | (iptr[1]<<0);
+               pixel = (iptr[0] << 8) | (iptr[1] << 0);
                iptr += 2;
                
-               if ( !(count = (pixel & 0x7f)) )
+               if (!(count = (pixel & 0x7f)) )
                        return;
                if (pixel & 0x80) {
-                       while (count>=8) {
-                               optr[0*4] = ((iptr[0]<<8) | (iptr[1]<<0))/(float)0xFFFF;
-                               optr[1*4] = ((iptr[2]<<8) | (iptr[3]<<0))/(float)0xFFFF;
-                               optr[2*4] = ((iptr[4]<<8) | (iptr[5]<<0))/(float)0xFFFF;
-                               optr[3*4] = ((iptr[6]<<8) | (iptr[7]<<0))/(float)0xFFFF;
-                               optr[4*4] = ((iptr[8]<<8) | (iptr[9]<<0))/(float)0xFFFF;
-                               optr[5*4] = ((iptr[10]<<8) | (iptr[11]<<0))/(float)0xFFFF;
-                               optr[6*4] = ((iptr[12]<<8) | (iptr[13]<<0))/(float)0xFFFF;
-                               optr[7*4] = ((iptr[14]<<8) | (iptr[15]<<0))/(float)0xFFFF;
-                               optr += 8*4;
-                               iptr += 8*2;
+                       while (count >= 8) {
+                               optr[0 * 4] = ((iptr[0] << 8) | (iptr[1] << 0)) / (float)0xFFFF;
+                               optr[1 * 4] = ((iptr[2] << 8) | (iptr[3] << 0)) / (float)0xFFFF;
+                               optr[2 * 4] = ((iptr[4] << 8) | (iptr[5] << 0)) / (float)0xFFFF;
+                               optr[3 * 4] = ((iptr[6] << 8) | (iptr[7] << 0)) / (float)0xFFFF;
+                               optr[4 * 4] = ((iptr[8] << 8) | (iptr[9] << 0)) / (float)0xFFFF;
+                               optr[5 * 4] = ((iptr[10] << 8) | (iptr[11] << 0)) / (float)0xFFFF;
+                               optr[6 * 4] = ((iptr[12] << 8) | (iptr[13] << 0)) / (float)0xFFFF;
+                               optr[7 * 4] = ((iptr[14] << 8) | (iptr[15] << 0)) / (float)0xFFFF;
+                               optr += 8 * 4;
+                               iptr += 8 * 2;
                                count -= 8;
                        }
                        while (count--) {
-                               *optr = ((iptr[0]<<8) | (iptr[1]<<0))/(float)0xFFFF;
-                               iptr+=2;
-                               optr+=4;
+                               *optr = ((iptr[0] << 8) | (iptr[1] << 0)) / (float)0xFFFF;
+                               iptr += 2;
+                               optr += 4;
                        }
                }
                else {
-                       pixel_f = ((iptr[0]<<8) | (iptr[1]<<0))/(float)0xFFFF;
+                       pixel_f = ((iptr[0] << 8) | (iptr[1] << 0)) / (float)0xFFFF;
                        iptr += 2;
 
-                       while (count>=8) {
-                               optr[0*4] = pixel_f;
-                               optr[1*4] = pixel_f;
-                               optr[2*4] = pixel_f;
-                               optr[3*4] = pixel_f;
-                               optr[4*4] = pixel_f;
-                               optr[5*4] = pixel_f;
-                               optr[6*4] = pixel_f;
-                               optr[7*4] = pixel_f;
-                               optr += 8*4;
+                       while (count >= 8) {
+                               optr[0 * 4] = pixel_f;
+                               optr[1 * 4] = pixel_f;
+                               optr[2 * 4] = pixel_f;
+                               optr[3 * 4] = pixel_f;
+                               optr[4 * 4] = pixel_f;
+                               optr[5 * 4] = pixel_f;
+                               optr[6 * 4] = pixel_f;
+                               optr[7 * 4] = pixel_f;
+                               optr += 8 * 4;
                                count -= 8;
                        }
                        while (count--) {
                                *optr = pixel_f;
-                               optr+=4;
+                               optr += 4;
                        }
                }
        }       
@@ -619,44 +619,44 @@ static void expandrow(unsigned char *optr, unsigned char *iptr, int z)
        optr += z;
        while (1) {
                pixel = *iptr++;
-               if ( !(count = (pixel & 0x7f)) )
+               if (!(count = (pixel & 0x7f)) )
                        return;
                if (pixel & 0x80) {
-                       while (count>=8) {
-                               optr[0*4] = iptr[0];
-                               optr[1*4] = iptr[1];
-                               optr[2*4] = iptr[2];
-                               optr[3*4] = iptr[3];
-                               optr[4*4] = iptr[4];
-                               optr[5*4] = iptr[5];
-                               optr[6*4] = iptr[6];
-                               optr[7*4] = iptr[7];
-                               optr += 8*4;
+                       while (count >= 8) {
+                               optr[0 * 4] = iptr[0];
+                               optr[1 * 4] = iptr[1];
+                               optr[2 * 4] = iptr[2];
+                               optr[3 * 4] = iptr[3];
+                               optr[4 * 4] = iptr[4];
+                               optr[5 * 4] = iptr[5];
+                               optr[6 * 4] = iptr[6];
+                               optr[7 * 4] = iptr[7];
+                               optr += 8 * 4;
                                iptr += 8;
                                count -= 8;
                        }
                        while (count--) {
                                *optr = *iptr++;
-                               optr+=4;
+                               optr += 4;
                        }
                }
                else {
                        pixel = *iptr++;
-                       while (count>=8) {
-                               optr[0*4] = pixel;
-                               optr[1*4] = pixel;
-                               optr[2*4] = pixel;
-                               optr[3*4] = pixel;
-                               optr[4*4] = pixel;
-                               optr[5*4] = pixel;
-                               optr[6*4] = pixel;
-                               optr[7*4] = pixel;
-                               optr += 8*4;
+                       while (count >= 8) {
+                               optr[0 * 4] = pixel;
+                               optr[1 * 4] = pixel;
+                               optr[2 * 4] = pixel;
+                               optr[3 * 4] = pixel;
+                               optr[4 * 4] = pixel;
+                               optr[5 * 4] = pixel;
+                               optr[6 * 4] = pixel;
+                               optr[7 * 4] = pixel;
+                               optr += 8 * 4;
                                count -= 8;
                        }
                        while (count--) {
                                *optr = pixel;
-                               optr+=4;
+                               optr += 4;
                        }
                }
        }
@@ -689,19 +689,19 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, cons
        outf = BLI_fopen(name, "wb");
        if (!outf) return 0;
 
-       tablen = ysize*zsize*sizeof(int);
+       tablen = ysize * zsize * sizeof(int);
 
        image = (IMAGE *)MEM_mallocN(sizeof(IMAGE), "iris image");
        starttab = (unsigned int *)MEM_mallocN(tablen, "iris starttab");
        lengthtab = (unsigned int *)MEM_mallocN(tablen, "iris lengthtab");
-       rlebuflen = 1.05*xsize+10;
+       rlebuflen = 1.05 * xsize + 10;
        rlebuf = (unsigned char *)MEM_mallocN(rlebuflen, "iris rlebuf");
-       lumbuf = (unsigned int *)MEM_mallocN(xsize*sizeof(int), "iris lumbuf");
+       lumbuf = (unsigned int *)MEM_mallocN(xsize * sizeof(int), "iris lumbuf");
 
        memset(image, 0, sizeof(IMAGE));
        image->imagic = IMAGIC;
        image->type = RLE(1);
-       if (zsize>1)
+       if (zsize > 1)
                image->dim = 3;
        else
                image->dim = 2;
@@ -711,8 +711,8 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, cons
        image->min = 0;
        image->max = 255;
        goodwrite *= writeheader(outf, image);
-       fseek(outf, 512+2*tablen, SEEK_SET);
-       pos = 512+2*tablen;
+       fseek(outf, 512 + 2 * tablen, SEEK_SET);
+       pos = 512 + 2 * tablen;
        
        for (y = 0; y < ysize; y++) {
                for (z = 0; z < zsize; z++) {
@@ -722,20 +722,20 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, cons
                                len = compressrow((uchar *)lumbuf, rlebuf, CHANOFFSET(z), xsize);
                        }
                        else {
-                               if (z<4) {
+                               if (z < 4) {
                                        len = compressrow((uchar *)lptr, rlebuf, CHANOFFSET(z), xsize);
                                }
-                               else if (z<8 && zptr) {
-                                       len = compressrow((uchar *)zptr, rlebuf, CHANOFFSET(z-4), xsize);
+                               else if (z < 8 && zptr) {
+                                       len = compressrow((uchar *)zptr, rlebuf, CHANOFFSET(z - 4), xsize);
                                }
                        }
-                       if (len>rlebuflen) {
+                       if (len > rlebuflen) {
                                fprintf(stderr, "output_iris: rlebuf is too small - bad poop\n");
                                exit(1);
                        }
                        goodwrite *= fwrite(rlebuf, len, 1, outf);
-                       starttab[y+z*ysize] = pos;
-                       lengthtab[y+z*ysize] = len;
+                       starttab[y + z * ysize] = pos;
+                       lengthtab[y + z * ysize] = len;
                        pos += len;
                }
                lptr += xsize;
@@ -779,32 +779,32 @@ static int compressrow(unsigned char *lbuf, unsigned char *rlebuf, int z, int cn
 
        lbuf += z;
        iptr = lbuf;
-       ibufend = iptr+cnt*4;
+       ibufend = iptr + cnt * 4;
        optr = rlebuf;
 
-       while (iptr<ibufend) {
+       while (iptr < ibufend) {
                sptr = iptr;
                iptr += 8;
-               while ((iptr<ibufend)&& ((iptr[-8]!=iptr[-4])||(iptr[-4]!=iptr[0])))
-                       iptr+=4;
+               while ((iptr < ibufend) && ((iptr[-8] != iptr[-4]) || (iptr[-4] != iptr[0])))
+                       iptr += 4;
                iptr -= 8;
-               count = (iptr-sptr)/4;
+               count = (iptr - sptr) / 4;
                while (count) {
-                       todo = count>126 ? 126:count;
+                       todo = count > 126 ? 126 : count;
                        count -= todo;
-                       *optr++ = 0x80|todo;
-                       while (todo>8) {
-                               optr[0] = sptr[0*4];
-                               optr[1] = sptr[1*4];
-                               optr[2] = sptr[2*4];
-                               optr[3] = sptr[3*4];
-                               optr[4] = sptr[4*4];
-                               optr[5] = sptr[5*4];
-                               optr[6] = sptr[6*4];
-                               optr[7] = sptr[7*4];
+                       *optr++ = 0x80 | todo;
+                       while (todo > 8) {
+                               optr[0] = sptr[0 * 4];
+                               optr[1] = sptr[1 * 4];
+                               optr[2] = sptr[2 * 4];
+                               optr[3] = sptr[3 * 4];
+                               optr[4] = sptr[4 * 4];
+                               optr[5] = sptr[5 * 4];
+                               optr[6] = sptr[6 * 4];
+                               optr[7] = sptr[7 * 4];
 
                                optr += 8;
-                               sptr += 8*4;
+                               sptr += 8 * 4;
                                todo -= 8;
                        }
                        while (todo--) {
@@ -815,11 +815,11 @@ static int compressrow(unsigned char *lbuf, unsigned char *rlebuf, int z, int cn
                sptr = iptr;
                cc = *iptr;
                iptr += 4;
-               while ( (iptr<ibufend) && (*iptr == cc) )
+               while ( (iptr < ibufend) && (*iptr == cc) )
                        iptr += 4;
-               count = (iptr-sptr)/4;
+               count = (iptr - sptr) / 4;
                while (count) {
-                       todo = count>126 ? 126:count;
+                       todo = count > 126 ? 126 : count;
                        count -= todo;
                        *optr++ = todo;
                        *optr++ = cc;
@@ -829,7 +829,7 @@ static int compressrow(unsigned char *lbuf, unsigned char *rlebuf, int z, int cn
        return optr - (unsigned char *)rlebuf;
 }
 
-int imb_saveiris(struct ImBuf * ibuf, const char *name, int flags)
+int imb_saveiris(struct ImBuf *ibuf, const char *name, int flags)
 {
        short zsize;
        int ret;
index c71763b245d98383395222ebf8f2fd1fe394adf5..4f71f296caadeb8c6611ec66ce4fde68d88e9f9d 100644 (file)
@@ -40,7 +40,7 @@
 
 #define JP2_FILEHEADER_SIZE 14
 
-static char JP2_HEAD[]= {0x0, 0x0, 0x0, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A};
+static char JP2_HEAD[] = {0x0, 0x0, 0x0, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A};
 
 /* We only need this because of how the presets are set */
 typedef struct img_folder {
@@ -72,7 +72,7 @@ int imb_is_a_jp2(unsigned char *buf)
  */
 static void error_callback(const char *msg, void *client_data)
 {
-       FILE *stream = (FILE*)client_data;
+       FILE *stream = (FILE *)client_data;
        fprintf(stream, "[ERROR] %s", msg);
 }
 /**
@@ -80,7 +80,7 @@ static void error_callback(const char *msg, void *client_data)
  */
 static void warning_callback(const char *msg, void *client_data)
 {
-       FILE *stream = (FILE*)client_data;
+       FILE *stream = (FILE *)client_data;
        fprintf(stream, "[WARNING] %s", msg);
 }
 /**
@@ -99,21 +99,21 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags)
        struct ImBuf *ibuf = NULL;
        int use_float = 0; /* for precision higher then 8 use float */
        
-       long signed_offsets[4]= {0, 0, 0, 0};
-       int float_divs[4]= {1, 1, 1, 1};
+       long signed_offsets[4] = {0, 0, 0, 0};
+       int float_divs[4] = {1, 1, 1, 1};
 
        int index;
        
        int w, h, planes;
        
-       opj_dparameters_t parameters;   /* decompression parameters */
+       opj_dparameters_t parameters;   /* decompression parameters */
        
-       opj_event_mgr_t event_mgr;              /* event manager */
+       opj_event_mgr_t event_mgr;      /* event manager */
        opj_image_t *image = NULL;
        
        int i;
        
-       opj_dinfo_t* dinfo = NULL;      /* handle to a decompressor */
+       opj_dinfo_t *dinfo = NULL;  /* handle to a decompressor */
        opj_cio_t *cio = NULL;
 
        if (check_jp2(mem) == 0) return(NULL);
@@ -166,18 +166,18 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags)
        h = image->comps[0].h;
        
        switch (image->numcomps) {
-       case 1: /* Greyscale */
-       case 3: /* Color */
-               planes= 24;
-               break;
-       default: /* 2 or 4 - Greyscale or Color + alpha */
-               planes= 32; /* greyscale + alpha */
-               break;
+               case 1: /* Greyscale */
+               case 3: /* Color */
+                       planes = 24;
+                       break;
+               default: /* 2 or 4 - Greyscale or Color + alpha */
+                       planes = 32; /* greyscale + alpha */
+                       break;
        }
        
        
        i = image->numcomps;
-       if (i>4) i= 4;
+       if (i > 4) i = 4;
        
        while (i) {
                i--;
@@ -186,15 +186,15 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags)
                        use_float = 1;
                
                if (image->comps[i].sgnd)
-                       signed_offsets[i]=  1 << (image->comps[i].prec - 1); 
+                       signed_offsets[i] =  1 << (image->comps[i].prec - 1);
                
                /* only needed for float images but dosnt hurt to calc this */
-               float_divs[i]= (1<<image->comps[i].prec)-1;
+               float_divs[i] = (1 << image->comps[i].prec) - 1;
        }
        
-       ibuf= IMB_allocImBuf(w, h, planes, use_float ? IB_rectfloat : IB_rect);
+       ibuf = IMB_allocImBuf(w, h, planes, use_float ? IB_rectfloat : IB_rect);
        
-       if (ibuf==NULL) {
+       if (ibuf == NULL) {
                if (dinfo)
                        opj_destroy_decompress(dinfo);
                return NULL;
@@ -203,67 +203,67 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags)
        ibuf->ftype = JP2;
        
        if (use_float) {
-               float *rect_float= ibuf->rect_float;
+               float *rect_float = ibuf->rect_float;
 
                if (image->numcomps < 3) {
                        /* greyscale 12bits+ */
-                       for (i = 0; i < w * h; i++, rect_float+=4) {
+                       for (i = 0; i < w * h; i++, rect_float += 4) {
                                index = w * h - ((i) / (w) + 1) * w + (i) % (w);
                                
-                               rect_float[0]= rect_float[1]= rect_float[2]= (float)(image->comps[0].data[index] + signed_offsets[0]) / float_divs[0];
+                               rect_float[0] = rect_float[1] = rect_float[2] = (float)(image->comps[0].data[index] + signed_offsets[0]) / float_divs[0];
                                
                                if (image->numcomps == 2)
-                                       rect_float[3]= (image->comps[1].data[index] + signed_offsets[1]) / float_divs[1];
+                                       rect_float[3] = (image->comps[1].data[index] + signed_offsets[1]) / float_divs[1];
                                else
-                                       rect_float[3]= 1.0f;
+                                       rect_float[3] = 1.0f;
                        }
                }
                else {
                        /* rgb or rgba 12bits+ */
-                       for (i = 0; i < w * h; i++, rect_float+=4) {
+                       for (i = 0; i < w * h; i++, rect_float += 4) {
                                index = w * h - ((i) / (w) + 1) * w + (i) % (w);
                                
-                               rect_float[0]= (float)(image->comps[0].data[index] + signed_offsets[0]) / float_divs[0];
-                               rect_float[1]= (float)(image->comps[1].data[index] + signed_offsets[1]) / float_divs[1];
-                               rect_float[2]= (float)(image->comps[2].data[index] + signed_offsets[2]) / float_divs[2];
+                               rect_float[0] = (float)(image->comps[0].data[index] + signed_offsets[0]) / float_divs[0];
+                               rect_float[1] = (float)(image->comps[1].data[index] + signed_offsets[1]) / float_divs[1];
+                               rect_float[2] = (float)(image->comps[2].data[index] + signed_offsets[2]) / float_divs[2];
                                
                                if (image->numcomps >= 4)
-                                       rect_float[3]= (float)(image->comps[3].data[index] + signed_offsets[3]) / float_divs[3];
+                                       rect_float[3] = (float)(image->comps[3].data[index] + signed_offsets[3]) / float_divs[3];
                                else
-                                       rect_float[3]= 1.0f;
+                                       rect_float[3] = 1.0f;
                        }
                }
                
        }
        else {
-               unsigned char *rect= (unsigned char *)ibuf->rect;
+               unsigned char *rect = (unsigned char *)ibuf->rect;
 
                if (image->numcomps < 3) {
                        /* greyscale */
-                       for (i = 0; i < w * h; i++, rect+=4) {
+                       for (i = 0; i < w * h; i++, rect += 4) {
                                index = w * h - ((i) / (w) + 1) * w + (i) % (w);
                                
-                               rect[0]= rect[1]= rect[2]= (image->comps[0].data[index] + signed_offsets[0]);
+                               rect[0] = rect[1] = rect[2] = (image->comps[0].data[index] + signed_offsets[0]);
                                
                                if (image->numcomps == 2)
-                                       rect[3]= image->comps[1].data[index] + signed_offsets[1];
+                                       rect[3] = image->comps[1].data[index] + signed_offsets[1];
                                else
-                                       rect[3]= 255;
+                                       rect[3] = 255;
                        }
                }
                else {
                        /* 8bit rgb or rgba */
-                       for (i = 0; i < w * h; i++, rect+=4) {
+                       for (i = 0; i < w * h; i++, rect += 4) {
                                int index = w * h - ((i) / (w) + 1) * w + (i) % (w);
                                
-                               rect[0]= image->comps[0].data[index] + signed_offsets[0];
-                               rect[1]= image->comps[1].data[index] + signed_offsets[1];
-                               rect[2]= image->comps[2].data[index] + signed_offsets[2];
+                               rect[0] = image->comps[0].data[index] + signed_offsets[0];
+                               rect[1] = image->comps[1].data[index] + signed_offsets[1];
+                               rect[2] = image->comps[2].data[index] + signed_offsets[2];
                                
                                if (image->numcomps >= 4)
-                                       rect[3]= image->comps[3].data[index] + signed_offsets[3];
+                                       rect[3] = image->comps[3].data[index] + signed_offsets[3];
                                else
-                                       rect[3]= 255;
+                                       rect[3] = 255;
                        }
                }
        }
@@ -286,12 +286,12 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags)
 //static opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw_cparameters_t *raw_cp) {
 /* prec can be 8, 12, 16 */
 
-#define UPSAMPLE_8_TO_12(_val) ((_val<<4) | (_val & ((1<<4)-1)))
-#define UPSAMPLE_8_TO_16(_val) ((_val<<8)+_val)
+#define UPSAMPLE_8_TO_12(_val) ((_val << 4) | (_val & ((1 << 4) - 1)))
+#define UPSAMPLE_8_TO_16(_val) ((_val << 8) + _val)
 
-#define DOWNSAMPLE_FLOAT_TO_8BIT(_val) (_val)<=0.0f?0: ((_val)>=1.0f?255: (int)(255.0f*(_val)))
-#define DOWNSAMPLE_FLOAT_TO_12BIT(_val)        (_val)<=0.0f?0: ((_val)>=1.0f?4095: (int)(4095.0f*(_val)))
-#define DOWNSAMPLE_FLOAT_TO_16BIT(_val)        (_val)<=0.0f?0: ((_val)>=1.0f?65535: (int)(65535.0f*(_val)))
+#define DOWNSAMPLE_FLOAT_TO_8BIT(_val)  (_val) <= 0.0f ? 0 : ((_val) >= 1.0f ? 255 : (int)(255.0f * (_val)))
+#define DOWNSAMPLE_FLOAT_TO_12BIT(_val) (_val) <= 0.0f ? 0 : ((_val) >= 1.0f ? 4095 : (int)(4095.0f * (_val)))
+#define DOWNSAMPLE_FLOAT_TO_16BIT(_val) (_val) <= 0.0f ? 0 : ((_val) >= 1.0f ? 65535 : (int)(65535.0f * (_val)))
 
 
 /*
@@ -304,10 +304,10 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags)
 /* ****************************** COPIED FROM image_to_j2k.c */
 
 /* ----------------------------------------------------------------------- */
-#define CINEMA_24_CS 1302083   /*Codestream length for 24fps*/
-#define CINEMA_48_CS 651041            /*Codestream length for 48fps*/
-#define COMP_24_CS 1041666             /*Maximum size per color component for 2K & 4K @ 24fps*/
-#define COMP_48_CS 520833              /*Maximum size per color component for 2K @ 48fps*/
+#define CINEMA_24_CS 1302083    /*Codestream length for 24fps*/
+#define CINEMA_48_CS 651041     /*Codestream length for 48fps*/
+#define COMP_24_CS 1041666      /*Maximum size per color component for 2K & 4K @ 24fps*/
+#define COMP_48_CS 520833       /*Maximum size per color component for 2K @ 48fps*/
 
 
 static int initialise_4K_poc(opj_poc_t *POC, int numres)
@@ -316,11 +316,11 @@ static int initialise_4K_poc(opj_poc_t *POC, int numres)
        POC[0].resno0  = 0; 
        POC[0].compno0 = 0;
        POC[0].layno1  = 1;
-       POC[0].resno1  = numres-1;
+       POC[0].resno1  = numres - 1;
        POC[0].compno1 = 3;
        POC[0].prg1 = CPRL;
        POC[1].tile  = 1;
-       POC[1].resno0  = numres-1; 
+       POC[1].resno0  = numres - 1;
        POC[1].compno0 = 0;
        POC[1].layno1  = 1;
        POC[1].resno1  = numres;
@@ -332,8 +332,8 @@ static int initialise_4K_poc(opj_poc_t *POC, int numres)
 static void cinema_parameters(opj_cparameters_t *parameters)
 {
        parameters->tile_size_on = 0; /* FALSE */
-       parameters->cp_tdx=1;
-       parameters->cp_tdy=1;
+       parameters->cp_tdx = 1;
+       parameters->cp_tdy = 1;
        
        /*Tile part*/
        parameters->tp_flag = 'C';
@@ -356,7 +356,7 @@ static void cinema_parameters(opj_cparameters_t *parameters)
        /* No ROI */
        parameters->roi_compno = -1;
 
-       parameters->subsampling_dx = 1;         parameters->subsampling_dy = 1;
+       parameters->subsampling_dx = 1;     parameters->subsampling_dy = 1;
 
        /* 9-7 transform */
        parameters->irreversible = 1;
@@ -369,93 +369,93 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters, opj_image_t *ima
        float temp_rate;
 
        switch (parameters->cp_cinema) {
-       case CINEMA2K_24:
-       case CINEMA2K_48:
-               if (parameters->numresolution > 6) {
-                       parameters->numresolution = 6;
-               }
-               if (!((image->comps[0].w == 2048) || (image->comps[0].h == 1080))) {
-                       fprintf(stdout, "Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3 "
-                               "(2K profile) compliance requires that at least one of coordinates match 2048 x 1080\n",
-                               image->comps[0].w, image->comps[0].h);
-                       parameters->cp_rsiz = STD_RSIZ;
-               }
-       break;
+               case CINEMA2K_24:
+               case CINEMA2K_48:
+                       if (parameters->numresolution > 6) {
+                               parameters->numresolution = 6;
+                       }
+                       if (!((image->comps[0].w == 2048) || (image->comps[0].h == 1080))) {
+                               fprintf(stdout, "Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3 "
+                                       "(2K profile) compliance requires that at least one of coordinates match 2048 x 1080\n",
+                                       image->comps[0].w, image->comps[0].h);
+                               parameters->cp_rsiz = STD_RSIZ;
+                       }
+                       break;
        
-       case CINEMA4K_24:
-               if (parameters->numresolution < 1) {
-                       parameters->numresolution = 1;
-               }
-               else if (parameters->numresolution > 7) {
-                       parameters->numresolution = 7;
-               }
-               if (!((image->comps[0].w == 4096) || (image->comps[0].h == 2160))) {
-                       fprintf(stdout, "Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4"
-                                       "(4K profile) compliance requires that at least one of coordinates match 4096 x 2160\n",
-                                       image->comps[0].w, image->comps[0].h);
-                       parameters->cp_rsiz = STD_RSIZ;
-               }
-               parameters->numpocs = initialise_4K_poc(parameters->POC, parameters->numresolution);
-               break;
-       case OFF:
-               /* do nothing */
-               break;
+               case CINEMA4K_24:
+                       if (parameters->numresolution < 1) {
+                               parameters->numresolution = 1;
+                       }
+                       else if (parameters->numresolution > 7) {
+                               parameters->numresolution = 7;
+                       }
+                       if (!((image->comps[0].w == 4096) || (image->comps[0].h == 2160))) {
+                               fprintf(stdout, "Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4"
+                                       "(4K profile) compliance requires that at least one of coordinates match 4096 x 2160\n",
+                                       image->comps[0].w, image->comps[0].h);
+                               parameters->cp_rsiz = STD_RSIZ;
+                       }
+                       parameters->numpocs = initialise_4K_poc(parameters->POC, parameters->numresolution);
+                       break;
+               case OFF:
+                       /* do nothing */
+                       break;
        }
 
        switch (parameters->cp_cinema) {
-       case CINEMA2K_24:
-       case CINEMA4K_24:
-               for (i=0 ; i<parameters->tcp_numlayers ; i++) {
-                       temp_rate = 0;
-                       if (img_fol->rates[i]== 0) {
-                               parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ 
-                                       (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
-                       }
-                       else {
-                               temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ 
-                                       (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
-                               if (temp_rate > CINEMA_24_CS ) {
-                                       parameters->tcp_rates[i]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ 
-                                               (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
+               case CINEMA2K_24:
+               case CINEMA4K_24:
+                       for (i = 0; i < parameters->tcp_numlayers; i++) {
+                               temp_rate = 0;
+                               if (img_fol->rates[i] == 0) {
+                                       parameters->tcp_rates[0] = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) /
+                                                                  (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
                                }
                                else {
-                                       parameters->tcp_rates[i]= img_fol->rates[i];
+                                       temp_rate = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) /
+                                                   (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
+                                       if (temp_rate > CINEMA_24_CS) {
+                                               parameters->tcp_rates[i] = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) /
+                                                                          (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
+                                       }
+                                       else {
+                                               parameters->tcp_rates[i] = img_fol->rates[i];
+                                       }
                                }
                        }
-               }
-               parameters->max_comp_size = COMP_24_CS;
-               break;
+                       parameters->max_comp_size = COMP_24_CS;
+                       break;
                
-       case CINEMA2K_48:
-               for (i=0 ; i<parameters->tcp_numlayers ; i++) {
-                       temp_rate = 0;
-                       if (img_fol->rates[i]== 0) {
-                               parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ 
-                                       (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
-                       }
-                       else {
-                               temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ 
-                                       (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
-                               if (temp_rate > CINEMA_48_CS ) {
-                                       parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ 
-                                               (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
+               case CINEMA2K_48:
+                       for (i = 0; i < parameters->tcp_numlayers; i++) {
+                               temp_rate = 0;
+                               if (img_fol->rates[i] == 0) {
+                                       parameters->tcp_rates[0] = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) /
+                                                                  (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
                                }
                                else {
-                                       parameters->tcp_rates[i]= img_fol->rates[i];
+                                       temp_rate = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) /
+                                                   (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
+                                       if (temp_rate > CINEMA_48_CS) {
+                                               parameters->tcp_rates[0] = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) /
+                                                                          (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
+                                       }
+                                       else {
+                                               parameters->tcp_rates[i] = img_fol->rates[i];
+                                       }
                                }
                        }
-               }
-               parameters->max_comp_size = COMP_48_CS;
-               break;
-       case OFF:
-               /* do nothing */
-               break;
+                       parameters->max_comp_size = COMP_48_CS;
+                       break;
+               case OFF:
+                       /* do nothing */
+                       break;
        }
        parameters->cp_disto_alloc = 1;
 }
 
 
-static opj_image_tibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
+static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
 {
        unsigned char *rect;
        float *rect_float;
@@ -467,51 +467,51 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
        int i, numcomps, w, h, prec;
        int x, y, y_row;
        OPJ_COLOR_SPACE color_space;
-       opj_image_cmptparm_t cmptparm[4];       /* maximum of 4 components */
-       opj_image_t * image = NULL;
+       opj_image_cmptparm_t cmptparm[4];   /* maximum of 4 components */
+       opj_image_t *image = NULL;
        
        img_fol_t img_fol; /* only needed for cinema presets */
        memset(&img_fol, 0, sizeof(img_fol_t));
        
        if (ibuf->ftype & JP2_CINE) {
                
-               if (ibuf->x==4096 || ibuf->y==2160)
-                       parameters->cp_cinema= CINEMA4K_24;
+               if (ibuf->x == 4096 || ibuf->y == 2160)
+                       parameters->cp_cinema = CINEMA4K_24;
                else {
                        if (ibuf->ftype & JP2_CINE_48FPS) {
-                               parameters->cp_cinema= CINEMA2K_48;
+                               parameters->cp_cinema = CINEMA2K_48;
                        }
                        else {
-                               parameters->cp_cinema= CINEMA2K_24;
+                               parameters->cp_cinema = CINEMA2K_24;
                        }
                }
                if (parameters->cp_cinema) {
-                       img_fol.rates = (float*)MEM_mallocN(parameters->tcp_numlayers * sizeof(float), "jp2_rates");
-                       for (i=0; i< parameters->tcp_numlayers; i++) {
+                       img_fol.rates = (float *)MEM_mallocN(parameters->tcp_numlayers * sizeof(float), "jp2_rates");
+                       for (i = 0; i < parameters->tcp_numlayers; i++) {
                                img_fol.rates[i] = parameters->tcp_rates[i];
                        }
                        cinema_parameters(parameters);
                }
                
-               color_space= CLRSPC_SYCC;
-               prec= 12;
-               numcomps= 3;
+               color_space = CLRSPC_SYCC;
+               prec = 12;
+               numcomps = 3;
        }
        else { 
                /* Get settings from the imbuf */
                color_space = (ibuf->ftype & JP2_YCC) ? CLRSPC_SYCC : CLRSPC_SRGB;
                
-               if (ibuf->ftype & JP2_16BIT)            prec= 16;
-               else if (ibuf->ftype & JP2_12BIT)       prec= 12;
-               else                                            prec= 8;
+               if (ibuf->ftype & JP2_16BIT) prec = 16;
+               else if (ibuf->ftype & JP2_12BIT) prec = 12;
+               else prec = 8;
                
                /* 32bit images == alpha channel */
                /* grayscale not supported yet */
-               numcomps= (ibuf->planes==32) ? 4 : 3;
+               numcomps = (ibuf->planes == 32) ? 4 : 3;
        }
        
-       w= ibuf->x;
-       h= ibuf->y;
+       w = ibuf->x;
+       h = ibuf->y;
        
        
        /* initialize image components */
@@ -535,16 +535,16 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
        /* set image offset and reference grid */
        image->x0 = parameters->image_offset_x0;
        image->y0 = parameters->image_offset_y0;
-       image->x1 = parameters->image_offset_x0 + (w - 1) *     subsampling_dx + 1;
-       image->y1 = parameters->image_offset_y0 + (h - 1) *     subsampling_dy + 1;
+       image->x1 = parameters->image_offset_x0 + (w - 1) * subsampling_dx + 1;
+       image->y1 = parameters->image_offset_y0 + (h - 1) * subsampling_dy + 1;
        
        /* set image data */
-       rect = (unsigned char*) ibuf->rect;
-       rect_float= ibuf->rect_float;
+       rect = (unsigned char *) ibuf->rect;
+       rect_float = ibuf->rect_float;
        
-       if (rect_float && rect && prec==8) {
+       if (rect_float && rect && prec == 8) {
                /* No need to use the floating point buffer, just write the 8 bits from the char buffer */
-               rect_float= NULL;
+               rect_float = NULL;
        }
        
        
@@ -552,112 +552,112 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
                float rgb[3];
                
                switch (prec) {
-               case 8: /* Convert blenders float color channels to 8, 12 or 16bit ints */
-                       for (y=h-1; y>=0; y--) {
-                               y_row = y*w;
-                               for (x=0; x<w; x++, rect_float+=4) {
-                                       i = y_row + x;
-                                       
-                                       if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
-                                               linearrgb_to_srgb_v3_v3(rgb, rect_float);
-                                       else
-                                               copy_v3_v3(rgb, rect_float);
-                               
-                                       image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rgb[0]);
-                                       image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rgb[1]);
-                                       image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rgb[2]);
-                                       if (numcomps>3)
-                                               image->comps[3].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[3]);
+                       case 8: /* Convert blenders float color channels to 8, 12 or 16bit ints */
+                               for (y = h - 1; y >= 0; y--) {
+                                       y_row = y * w;
+                                       for (x = 0; x < w; x++, rect_float += 4) {
+                                               i = y_row + x;
+
+                                               if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
+                                                       linearrgb_to_srgb_v3_v3(rgb, rect_float);
+                                               else
+                                                       copy_v3_v3(rgb, rect_float);
+
+                                               image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rgb[0]);
+                                               image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rgb[1]);
+                                               image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rgb[2]);
+                                               if (numcomps > 3)
+                                                       image->comps[3].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[3]);
+                                       }
                                }
-                       }
-                       break;
+                               break;
                        
-               case 12:
-                       for (y=h-1; y>=0; y--) {
-                               y_row = y*w;
-                               for (x=0; x<w; x++, rect_float+=4) {
-                                       i = y_row + x;
-                                       
-                                       if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
-                                               linearrgb_to_srgb_v3_v3(rgb, rect_float);
-                                       else
-                                               copy_v3_v3(rgb, rect_float);
-                               
-                                       image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rgb[0]);
-                                       image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rgb[1]);
-                                       image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rgb[2]);
-                                       if (numcomps>3)
-                                               image->comps[3].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[3]);
+                       case 12:
+                               for (y = h - 1; y >= 0; y--) {
+                                       y_row = y * w;
+                                       for (x = 0; x < w; x++, rect_float += 4) {
+                                               i = y_row + x;
+
+                                               if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
+                                                       linearrgb_to_srgb_v3_v3(rgb, rect_float);
+                                               else
+                                                       copy_v3_v3(rgb, rect_float);
+
+                                               image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rgb[0]);
+                                               image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rgb[1]);
+                                               image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rgb[2]);
+                                               if (numcomps > 3)
+                                                       image->comps[3].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[3]);
+                                       }
                                }
-                       }
-                       break;
-               case 16:
-                       for (y=h-1; y>=0; y--) {
-                               y_row = y*w;
-                               for (x=0; x<w; x++, rect_float+=4) {
-                                       i = y_row + x;
-                                       
-                                       if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
-                                               linearrgb_to_srgb_v3_v3(rgb, rect_float);
-                                       else
-                                               copy_v3_v3(rgb, rect_float);
-                               
-                                       image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rgb[0]);
-                                       image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rgb[1]);
-                                       image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rgb[2]);
-                                       if (numcomps>3)
-                                               image->comps[3].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[3]);
+                               break;
+                       case 16:
+                               for (y = h - 1; y >= 0; y--) {
+                                       y_row = y * w;
+                                       for (x = 0; x < w; x++, rect_float += 4) {
+                                               i = y_row + x;
+
+                                               if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
+                                                       linearrgb_to_srgb_v3_v3(rgb, rect_float);
+                                               else
+                                                       copy_v3_v3(rgb, rect_float);
+
+                                               image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rgb[0]);
+                                               image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rgb[1]);
+                                               image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rgb[2]);
+                                               if (numcomps > 3)
+                                                       image->comps[3].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[3]);
+                                       }
                                }
-                       }
-                       break;
+                               break;
                }
        }
        else {
                /* just use rect*/
                switch (prec) {
-               case 8:
-                       for (y=h-1; y>=0; y--) {
-                               y_row = y*w;
-                               for (x=0; x<w; x++, rect+=4) {
-                                       i = y_row + x;
-                               
-                                       image->comps[0].data[i] = rect[0];
-                                       image->comps[1].data[i] = rect[1];
-                                       image->comps[2].data[i] = rect[2];
-                                       if (numcomps>3)
-                                               image->comps[3].data[i] = rect[3];
+                       case 8:
+                               for (y = h - 1; y >= 0; y--) {
+                                       y_row = y * w;
+                                       for (x = 0; x < w; x++, rect += 4) {
+                                               i = y_row + x;
+
+                                               image->comps[0].data[i] = rect[0];
+                                               image->comps[1].data[i] = rect[1];
+                                               image->comps[2].data[i] = rect[2];
+                                               if (numcomps > 3)
+                                                       image->comps[3].data[i] = rect[3];
+                                       }
                                }
-                       }
-                       break;
+                               break;
                        
-               case 12: /* Up Sampling, a bit pointless but best write the bit depth requested */
-                       for (y=h-1; y>=0; y--) {
-                               y_row = y*w;
-                               for (x=0; x<w; x++, rect+=4) {
-                                       i = y_row + x;
-                               
-                                       image->comps[0].data[i]= UPSAMPLE_8_TO_12(rect[0]);
-                                       image->comps[1].data[i]= UPSAMPLE_8_TO_12(rect[1]);
-                                       image->comps[2].data[i]= UPSAMPLE_8_TO_12(rect[2]);
-                                       if (numcomps>3)
-                                               image->comps[3].data[i]= UPSAMPLE_8_TO_12(rect[3]);
+                       case 12: /* Up Sampling, a bit pointless but best write the bit depth requested */
+                               for (y = h - 1; y >= 0; y--) {
+                                       y_row = y * w;
+                                       for (x = 0; x < w; x++, rect += 4) {
+                                               i = y_row + x;
+
+                                               image->comps[0].data[i] = UPSAMPLE_8_TO_12(rect[0]);
+                                               image->comps[1].data[i] = UPSAMPLE_8_TO_12(rect[1]);
+                                               image->comps[2].data[i] = UPSAMPLE_8_TO_12(rect[2]);
+                                               if (numcomps > 3)
+                                                       image->comps[3].data[i] = UPSAMPLE_8_TO_12(rect[3]);
+                                       }
                                }
-                       }
-                       break;
-               case 16:
-                       for (y=h-1; y>=0; y--) {
-                               y_row = y*w;
-                               for (x=0; x<w; x++, rect+=4) {
-                                       i = y_row + x;
-                               
-                                       image->comps[0].data[i]= UPSAMPLE_8_TO_16(rect[0]);
-                                       image->comps[1].data[i]= UPSAMPLE_8_TO_16(rect[1]);
-                                       image->comps[2].data[i]= UPSAMPLE_8_TO_16(rect[2]);
-                                       if (numcomps>3)
-                                               image->comps[3].data[i]= UPSAMPLE_8_TO_16(rect[3]);
+                               break;
+                       case 16:
+                               for (y = h - 1; y >= 0; y--) {
+                                       y_row = y * w;
+                                       for (x = 0; x < w; x++, rect += 4) {
+                                               i = y_row + x;
+
+                                               image->comps[0].data[i] = UPSAMPLE_8_TO_16(rect[0]);
+                                               image->comps[1].data[i] = UPSAMPLE_8_TO_16(rect[1]);
+                                               image->comps[2].data[i] = UPSAMPLE_8_TO_16(rect[2]);
+                                               if (numcomps > 3)
+                                                       image->comps[3].data[i] = UPSAMPLE_8_TO_16(rect[3]);
+                                       }
                                }
-                       }
-                       break;
+                               break;
                }
        }
        
@@ -681,8 +681,8 @@ int imb_savejp2(struct ImBuf *ibuf, const char *name, int flags)
        int quality = ibuf->ftype & 0xff;
        
        int bSuccess;
-       opj_cparameters_t parameters;   /* compression parameters */
-       opj_event_mgr_t event_mgr;              /* event manager */
+       opj_cparameters_t parameters;   /* compression parameters */
+       opj_event_mgr_t event_mgr;      /* event manager */
        opj_image_t *image = NULL;
        
        (void)flags; /* unused */
@@ -702,22 +702,22 @@ int imb_savejp2(struct ImBuf *ibuf, const char *name, int flags)
        /* compression ratio */
        /* invert range, from 10-100, 100-1
         * where jpeg see's 1 and highest quality (lossless) and 100 is very low quality*/
-       parameters.tcp_rates[0]= ((100-quality)/90.0f*99.0f) + 1;
+       parameters.tcp_rates[0] = ((100 - quality) / 90.0f * 99.0f) + 1;
 
        
        parameters.tcp_numlayers = 1; // only one resolution
        parameters.cp_disto_alloc = 1;
 
-       image= ibuftoimage(ibuf, &parameters);
+       image = ibuftoimage(ibuf, &parameters);
        
        
-       {                       /* JP2 format output */
+       {   /* JP2 format output */
                int codestream_length;
                opj_cio_t *cio = NULL;
                FILE *f = NULL;
 
                /* get a JP2 compressor handle */
-               opj_cinfo_tcinfo = opj_create_compress(CODEC_JP2);
+               opj_cinfo_t *cinfo = opj_create_compress(CODEC_JP2);
 
                /* catch events using our callbacks and give a local context */
                opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);                   
index 485f593a8fbdb05c438657d89a11592f9947f36f..ee358f6e4ba8036a1bcdccbb63951be6b954cf22 100644 (file)
@@ -59,7 +59,7 @@ typedef struct MovieCache {
        int keysize;
        unsigned long curtime;
 
-       int totseg, *points, proxy, render_flags;       /* for visual statistics optimization */
+       int totseg, *points, proxy, render_flags;  /* for visual statistics optimization */
        int pad;
 } MovieCache;
 
@@ -71,35 +71,35 @@ typedef struct MovieCacheKey {
 typedef struct MovieCacheItem {
        MovieCache *cache_owner;
        ImBuf *ibuf;
-       MEM_CacheLimiterHandleC * c_handle;
+       MEM_CacheLimiterHandleC *c_handle;
        unsigned long last_access;
 } MovieCacheItem;
 
 static unsigned int moviecache_hashhash(const void *keyv)
 {
-       MovieCacheKey *key = (MovieCacheKey*)keyv;
+       MovieCacheKey *key = (MovieCacheKey *)keyv;
 
        return key->cache_owner->hashfp(key->userkey);
 }
 
 static int moviecache_hashcmp(const void *av, const void *bv)
 {
-       const MovieCacheKey *a = (MovieCacheKey*)av;
-       const MovieCacheKey *b = (MovieCacheKey*)bv;
+       const MovieCacheKey *a = (MovieCacheKey *)av;
+       const MovieCacheKey *b = (MovieCacheKey *)bv;
 
        return a->cache_owner->cmpfp(a->userkey, b->userkey);
 }
 
 static void moviecache_keyfree(void *val)
 {
-       MovieCacheKey *key = (MovieCacheKey*)val;
+       MovieCacheKey *key = (MovieCacheKey *)val;
 
        BLI_mempool_free(key->cache_owner->keys_pool, key);
 }
 
 static void moviecache_valfree(void *val)
 {
-       MovieCacheItem *item = (MovieCacheItem*)val;
+       MovieCacheItem *item = (MovieCacheItem *)val;
 
        if (item->ibuf) {
                MEM_CacheLimiter_unmanage(item->c_handle);
@@ -160,7 +160,7 @@ static size_t IMB_get_size_in_memory(ImBuf *ibuf)
        if (ibuf->rect_float)
                channel_size += sizeof(float);
 
-        size += channel_size * ibuf->x * ibuf->y * ibuf->channels;
+       size += channel_size * ibuf->x * ibuf->y * ibuf->channels;
 
        if (ibuf->miptot) {
                for (a = 0; a < ibuf->miptot; a++) {
@@ -170,13 +170,13 @@ static size_t IMB_get_size_in_memory(ImBuf *ibuf)
        }
 
        if (ibuf->tiles) {
-               size += sizeof(unsigned int)*ibuf->ytiles*ibuf->xtiles;
+               size += sizeof(unsigned int) * ibuf->ytiles * ibuf->xtiles;
        }
 
        return size;
 }
 
-static size_t get_item_size (void *p)
+static size_t get_item_size(void *p)
 {
        size_t size = sizeof(MovieCacheItem);
        MovieCacheItem *item = (MovieCacheItem *) p;
@@ -199,8 +199,7 @@ void IMB_moviecache_destruct(void)
 }
 
 struct MovieCache *IMB_moviecache_create(int keysize, GHashHashFP hashfp, GHashCmpFP cmpfp,
-               MovieCacheGetKeyDataFP getdatafp)
-{
+                                         MovieCacheGetKeyDataFP getdatafp){
        MovieCache *cache;
 
        cache = MEM_callocN(sizeof(MovieCache), "MovieCache");
@@ -257,14 +256,14 @@ void IMB_moviecache_put(MovieCache *cache, void *userkey, ImBuf *ibuf)
        }
 }
 
-ImBufIMB_moviecache_get(MovieCache *cache, void *userkey)
+ImBuf *IMB_moviecache_get(MovieCache *cache, void *userkey)
 {
        MovieCacheKey key;
        MovieCacheItem *item;
 
        key.cache_owner = cache;
        key.userkey = userkey;
-       item = (MovieCacheItem*)BLI_ghash_lookup(cache->hash, &key);
+       item = (MovieCacheItem *)BLI_ghash_lookup(cache->hash, &key);
 
        if (item) {
                item->last_access = cache->curtime++;
@@ -316,7 +315,7 @@ void IMB_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_
        }
        else {
                int totframe = BLI_ghash_size(cache->hash);
-               int *frames = MEM_callocN(totframe*sizeof(int), "movieclip cache frames");
+               int *frames = MEM_callocN(totframe * sizeof(int), "movieclip cache frames");
                int a, totseg = 0;
                GHashIterator *iter;
 
@@ -353,7 +352,7 @@ void IMB_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_
                if (totseg) {
                        int b, *points;
 
-                       points = MEM_callocN(2*sizeof(int)*totseg, "movieclip cache segments");
+                       points = MEM_callocN(2 * sizeof(int) * totseg, "movieclip cache segments");
 
                        /* fill */
                        for (a = 0, b = 0; a < totframe; a++) {
index 88d8b09675bcf81ec8ee5ec4013ed0dbca19885d..523dc8120c4b9fa48aead9ca0ebe07316d2d23db 100644 (file)
 
 /* Note: as for now openexr only supports 32 chars in channel names.
  * This api also supports max 8 channels per pass now. easy to fix! */
-#define EXR_LAY_MAXNAME                19
-#define EXR_PASS_MAXNAME       11
-#define EXR_TOT_MAXNAME                32
-#define EXR_PASS_MAXCHAN       8
+#define EXR_LAY_MAXNAME     19
+#define EXR_PASS_MAXNAME    11
+#define EXR_TOT_MAXNAME     32
+#define EXR_PASS_MAXCHAN    8
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-void * IMB_exr_get_handle                      (void);
-void   IMB_exr_add_channel                     (void *handle, const char *layname, const char *passname, int xstride, int ystride, float *rect);
+void *IMB_exr_get_handle(void);
+void    IMB_exr_add_channel(void *handle, const char *layname, const char *passname, int xstride, int ystride, float *rect);
 
-int            IMB_exr_begin_read                      (void *handle, const char *filename, int *width, int *height);
-int            IMB_exr_begin_write                     (void *handle, const char *filename, int width, int height, int compress);
-void   IMB_exrtile_begin_write         (void *handle, const char *filename, int mipmap, int width, int height, int tilex, int tiley);
+int     IMB_exr_begin_read(void *handle, const char *filename, int *width, int *height);
+int     IMB_exr_begin_write(void *handle, const char *filename, int width, int height, int compress);
+void    IMB_exrtile_begin_write(void *handle, const char *filename, int mipmap, int width, int height, int tilex, int tiley);
 
-void   IMB_exr_set_channel                     (void *handle, const char *layname, const char *passname, int xstride, int ystride, float *rect);
+void    IMB_exr_set_channel(void *handle, const char *layname, const char *passname, int xstride, int ystride, float *rect);
 
-void   IMB_exr_read_channels           (void *handle);
-void   IMB_exr_write_channels          (void *handle);
-void   IMB_exrtile_write_channels      (void *handle, int partx, int party, int level);
-void   IMB_exrtile_clear_channels      (void *handle);
+void    IMB_exr_read_channels(void *handle);
+void    IMB_exr_write_channels(void *handle);
+void    IMB_exrtile_write_channels(void *handle, int partx, int party, int level);
+void    IMB_exrtile_clear_channels(void *handle);
 
-void    IMB_exr_multilayer_convert     (void *handle, void *base,  
-                                                                        void * (*addlayer)(void *base, char *str), 
-                                                                        void (*addpass)(void *base, void *lay, char *str, float *rect, int totchan, char *chan_id));
+void    IMB_exr_multilayer_convert(void *handle, void *base,
+                                   void * (*addlayer)(void *base, char *str),
+                                   void (*addpass)(void *base, void *lay, char *str, float *rect, int totchan, char *chan_id));
 
-void   IMB_exr_close                           (void *handle);
+void    IMB_exr_close(void *handle);
 
 #ifdef __cplusplus
 } // extern "C"
index 66acd952ac087d2798122d46ba910b496a9b2514..4f4ab9e72d09a424454f3d6e0fed9d1c59f1a5bc 100644 (file)
@@ -56,7 +56,7 @@
 /* needed constants */
 #define MINELEN 8
 #define MAXELEN 0x7fff
-#define MINRUN 4       /* minimum run length */
+#define MINRUN  4   /* minimum run length */
 #define RED 0
 #define GRN 1
 #define BLU 2
 typedef unsigned char RGBE[4];
 typedef float fCOLOR[3];
 /* copy source -> dest */
-#define copy_rgbe(c1, c2) (c2[RED]=c1[RED], c2[GRN]=c1[GRN], c2[BLU]=c1[BLU], c2[EXP]=c1[EXP])
-#define copy_fcol(f1, f2) (f2[RED]=f1[RED], f2[GRN]=f1[GRN], f2[BLU]=f1[BLU])
+#define copy_rgbe(c1, c2) (c2[RED] = c1[RED], c2[GRN] = c1[GRN], c2[BLU] = c1[BLU], c2[EXP] = c1[EXP])
+#define copy_fcol(f1, f2) (f2[RED] = f1[RED], f2[GRN] = f1[GRN], f2[BLU] = f1[BLU])
 
 /* read routines */
-static unsigned charoldreadcolrs(RGBE *scan, unsigned char *mem, int xmax)
+static unsigned char *oldreadcolrs(RGBE *scan, unsigned char *mem, int xmax)
 {
        int i, rshift = 0, len = xmax;
        while (len > 0) {
@@ -79,7 +79,7 @@ static unsigned char* oldreadcolrs(RGBE *scan, unsigned char *mem, int xmax)
                scan[0][BLU] = *mem++;
                scan[0][EXP] = *mem++;
                if (scan[0][RED] == 1 && scan[0][GRN] == 1 && scan[0][BLU] == 1) {
-                       for (i=scan[0][EXP]<<rshift;i>0;i--) {
+                       for (i = scan[0][EXP] << rshift; i > 0; i--) {
                                copy_rgbe(scan[-1], scan[0]);
                                scan++;
                                len--;
@@ -95,14 +95,14 @@ static unsigned char* oldreadcolrs(RGBE *scan, unsigned char *mem, int xmax)
        return mem;
 }
 
-static unsigned char* freadcolrs(RGBE *scan, unsigned char* mem, int xmax)
+static unsigned char *freadcolrs(RGBE *scan, unsigned char *mem, int xmax)
 {
        int i, j, code, val;
 
        if ((xmax < MINELEN) | (xmax > MAXELEN)) return oldreadcolrs(scan, mem, xmax);
 
        i = *mem++;
-       if (i != 2) return oldreadcolrs(scan, mem-1, xmax);
+       if (i != 2) return oldreadcolrs(scan, mem - 1, xmax);
 
        scan[0][GRN] = *mem++;
        scan[0][BLU] = *mem++;
@@ -110,8 +110,8 @@ static unsigned char* freadcolrs(RGBE *scan, unsigned char* mem, int xmax)
        i = *mem++;
        if (((scan[0][BLU] << 8) | i) != xmax) return NULL;
 
-       for (i=0;i<4;i++)
-               for (j=0;j<xmax;) {
+       for (i = 0; i < 4; i++)
+               for (j = 0; j < xmax; ) {
                        code = *mem++;
                        if (code > 128) {
                                code &= 127;
@@ -131,14 +131,14 @@ static unsigned char* freadcolrs(RGBE *scan, unsigned char* mem, int xmax)
 /* rgbe -> float color */
 static void RGBE2FLOAT(RGBE rgbe, fCOLOR fcol)
 {
-       if (rgbe[EXP]==0) {
+       if (rgbe[EXP] == 0) {
                fcol[RED] = fcol[GRN] = fcol[BLU] = 0;
        }
        else {
-               float f = ldexp(1.0, rgbe[EXP]-(COLXS+8));
-               fcol[RED] = f*(rgbe[RED] + 0.5f);
-               fcol[GRN] = f*(rgbe[GRN] + 0.5f);
-               fcol[BLU] = f*(rgbe[BLU] + 0.5f);
+               float f = ldexp(1.0, rgbe[EXP] - (COLXS + 8));
+               fcol[RED] = f * (rgbe[RED] + 0.5f);
+               fcol[GRN] = f * (rgbe[GRN] + 0.5f);
+               fcol[BLU] = f * (rgbe[BLU] + 0.5f);
        }
 }
 
@@ -146,8 +146,8 @@ static void RGBE2FLOAT(RGBE rgbe, fCOLOR fcol)
 static void FLOAT2RGBE(fCOLOR fcol, RGBE rgbe)
 {
        int e;
-       float d = (fcol[RED]>fcol[GRN]) ? fcol[RED] : fcol[GRN];
-       if (fcol[BLU]>d) d = fcol[BLU];
+       float d = (fcol[RED] > fcol[GRN]) ? fcol[RED] : fcol[GRN];
+       if (fcol[BLU] > d) d = fcol[BLU];
        if (d <= 1e-32f)
                rgbe[RED] = rgbe[GRN] = rgbe[BLU] = rgbe[EXP] = 0;
        else {
@@ -166,63 +166,63 @@ int imb_is_a_hdr(unsigned char *buf)
        // For recognition, Blender only loads first 32 bytes, so use #?RADIANCE id instead
        // update: actually, the 'RADIANCE' part is just an optional program name, the magic word is really only the '#?' part
        //if (strstr((char*)buf, "#?RADIANCE")) return 1;
-       if (strstr((char*)buf, "#?")) return 1;
+       if (strstr((char *)buf, "#?")) return 1;
        // if (strstr((char*)buf, "32-bit_rle_rgbe")) return 1;
        return 0;
 }
 
 struct ImBuf *imb_loadhdr(unsigned char *mem, size_t size, int flags)
 {
-       struct ImBufibuf;
-       RGBEsline;
+       struct ImBuf *ibuf;
+       RGBE *sline;
        fCOLOR fcol;
-       floatrect_float;
-       int found=0;
-       int width=0, height=0;
+       float *rect_float;
+       int found = 0;
+       int width = 0, height = 0;
        int x, y;
-       unsigned charptr;
+       unsigned char *ptr;
        char oriY[80], oriX[80];
 
        if (imb_is_a_hdr((void *)mem)) {
                /* find empty line, next line is resolution info */
-               for (x=1;x<size;x++) {
-                       if ((mem[x-1]=='\n') && (mem[x]=='\n')) {
+               for (x = 1; x < size; x++) {
+                       if ((mem[x - 1] == '\n') && (mem[x] == '\n')) {
                                found = 1;
                                break;
                        }
                }
-               if (found && (x<(size + 2))) {
+               if (found && (x < (size + 2))) {
                        if (sscanf((char *)&mem[x + 1], "%79s %d %79s %d", (char *)&oriY, &height,
-                                  (char*)&oriX, &width) != 4)
+                                  (char *)&oriX, &width) != 4)
                        {
                                return NULL;
                        }
 
                        /* find end of this line, data right behind it */
-                       ptr = (unsigned char *)strchr((char*)&mem[x+1], '\n');
+                       ptr = (unsigned char *)strchr((char *)&mem[x + 1], '\n');
                        ptr++;
 
                        if (flags & IB_test) ibuf = IMB_allocImBuf(width, height, 32, 0);
-                       else ibuf = IMB_allocImBuf(width, height, 32, (flags & IB_rect)|IB_rectfloat);
+                       else ibuf = IMB_allocImBuf(width, height, 32, (flags & IB_rect) | IB_rectfloat);
 
-                       if (ibuf==NULL) return NULL;
+                       if (ibuf == NULL) return NULL;
                        ibuf->ftype = RADHDR;
                        ibuf->profile = IB_PROFILE_LINEAR_RGB;
 
                        if (flags & IB_test) return ibuf;
 
                        /* read in and decode the actual data */
-                       sline = (RGBE*)MEM_mallocN(sizeof(RGBE)*width, "radhdr_read_tmpscan");
+                       sline = (RGBE *)MEM_mallocN(sizeof(RGBE) * width, "radhdr_read_tmpscan");
                        rect_float = (float *)ibuf->rect_float;
                        
-                       for (y=0;y<height;y++) {
+                       for (y = 0; y < height; y++) {
                                ptr = freadcolrs(sline, ptr, width);
-                               if (ptr==NULL) {
+                               if (ptr == NULL) {
                                        printf("HDR decode error\n");
                                        MEM_freeN(sline);
                                        return ibuf;
                                }
-                               for (x=0;x<width;x++) {
+                               for (x = 0; x < width; x++) {
                                        /* convert to ldr */
                                        RGBE2FLOAT(sline[x], fcol);
                                        *rect_float++ = fcol[RED];
@@ -232,7 +232,7 @@ struct ImBuf *imb_loadhdr(unsigned char *mem, size_t size, int flags)
                                }
                        }
                        MEM_freeN(sline);
-                       if (oriY[0]=='-') IMB_flipy(ibuf);
+                       if (oriY[0] == '-') IMB_flipy(ibuf);
                        
                        if (flags & IB_rect) {
                                IMB_rect_from_float(ibuf);
@@ -248,36 +248,36 @@ struct ImBuf *imb_loadhdr(unsigned char *mem, size_t size, int flags)
 }
 
 /* ImBuf write */
-static int fwritecolrs(FILE* file, int width, int channels, unsigned char* ibufscan, float* fpscan)
+static int fwritecolrs(FILE *file, int width, int channels, unsigned char *ibufscan, float *fpscan)
 {
-       int x, i, j, beg, c2, cnt=0;
+       int x, i, j, beg, c2, cnt = 0;
        fCOLOR fcol;
        RGBE rgbe, *rgbe_scan;
 
-       if ((ibufscan==NULL) && (fpscan==NULL)) return 0;
+       if ((ibufscan == NULL) && (fpscan == NULL)) return 0;
 
-       rgbe_scan = (RGBE*)MEM_mallocN(sizeof(RGBE)*width, "radhdr_write_tmpscan");
+       rgbe_scan = (RGBE *)MEM_mallocN(sizeof(RGBE) * width, "radhdr_write_tmpscan");
 
        /* convert scanline */
-               j= 0;
-       for (i=0;i<width;i++) {
+       = 0;
+       for (i = 0; i < width; i++) {
                if (fpscan) {
                        fcol[RED] = fpscan[j];
-                       fcol[GRN] = (channels >= 2)? fpscan[j+1]: fpscan[j];
-                       fcol[BLU] = (channels >= 3)? fpscan[j+2]: fpscan[j];
+                       fcol[GRN] = (channels >= 2) ? fpscan[j + 1] : fpscan[j];
+                       fcol[BLU] = (channels >= 3) ? fpscan[j + 2] : fpscan[j];
                }
                else {
                        fcol[RED] = (float)ibufscan[j] / 255.f;
-                       fcol[GRN] = (float)((channels >= 2)? ibufscan[j+1]: ibufscan[j]) / 255.f;
-                       fcol[BLU] = (float)((channels >= 3)? ibufscan[j+2]: ibufscan[j]) / 255.f;
+                       fcol[GRN] = (float)((channels >= 2) ? ibufscan[j + 1] : ibufscan[j]) / 255.f;
+                       fcol[BLU] = (float)((channels >= 3) ? ibufscan[j + 2] : ibufscan[j]) / 255.f;
                }
                FLOAT2RGBE(fcol, rgbe);
                copy_rgbe(rgbe, rgbe_scan[i]);
-               j+=channels;
+               j += channels;
        }
 
-       if ((width < MINELEN) | (width > MAXELEN)) {    /* OOBs, write out flat */
-               x=fwrite((char *)rgbe_scan, sizeof(RGBE), width, file) - width;
+       if ((width < MINELEN) | (width > MAXELEN)) {    /* OOBs, write out flat */
+               x = fwrite((char *)rgbe_scan, sizeof(RGBE), width, file) - width;
                MEM_freeN(rgbe_scan);
                return x;
        }
@@ -287,29 +287,29 @@ static int fwritecolrs(FILE* file, int width, int channels, unsigned char* ibufs
        putc((unsigned char)(width >> 8), file);
        putc((unsigned char)(width & 255), file);
        /* put components separately */
-       for (i=0;i<4;i++) {
-               for (j=0;j<width;j+=cnt) {      /* find next run */
-                       for (beg=j;beg<width;beg+=cnt) {
-                               for (cnt=1;(cnt<127) && ((beg+cnt)<width) && (rgbe_scan[beg+cnt][i] == rgbe_scan[beg][i]); cnt++);
-                               if (cnt>=MINRUN) break;   /* long enough */
+       for (i = 0; i < 4; i++) {
+               for (j = 0; j < width; j += cnt) {  /* find next run */
+                       for (beg = j; beg < width; beg += cnt) {
+                               for (cnt = 1; (cnt < 127) && ((beg + cnt) < width) && (rgbe_scan[beg + cnt][i] == rgbe_scan[beg][i]); cnt++) ;
+                               if (cnt >= MINRUN) break;  /* long enough */
                        }
-                       if (((beg-j)>1) && ((beg-j) < MINRUN)) {
-                               c2 = j+1;
+                       if (((beg - j) > 1) && ((beg - j) < MINRUN)) {
+                               c2 = j + 1;
                                while (rgbe_scan[c2++][i] == rgbe_scan[j][i])
                                        if (c2 == beg) {        /* short run */
-                                               putc((unsigned char)(128+beg-j), file);
+                                               putc((unsigned char)(128 + beg - j), file);
                                                putc((unsigned char)(rgbe_scan[j][i]), file);
                                                j = beg;
                                                break;
                                        }
                        }
                        while (j < beg) {     /* write out non-run */
-                               if ((c2 = beg-j) > 128) c2 = 128;
+                               if ((c2 = beg - j) > 128) c2 = 128;
                                putc((unsigned char)(c2), file);
                                while (c2--) putc(rgbe_scan[j++][i], file);
                        }
                        if (cnt >= MINRUN) {      /* write out run */
-                               putc((unsigned char)(128+cnt), file);
+                               putc((unsigned char)(128 + cnt), file);
                                putc(rgbe_scan[beg][i], file);
                        }
                        else cnt = 0;
@@ -336,30 +336,30 @@ static void writeHeader(FILE *file, int width, int height)
 
 int imb_savehdr(struct ImBuf *ibuf, const char *name, int flags)
 {
-       FILEfile = BLI_fopen(name, "wb");
-       float *fp= NULL;
-       int y, width=ibuf->x, height=ibuf->y;
-       unsigned char *cp= NULL;
+       FILE *file = BLI_fopen(name, "wb");
+       float *fp = NULL;
+       int y, width = ibuf->x, height = ibuf->y;
+       unsigned char *cp = NULL;
        
        (void)flags; /* unused */
        
-       if (file==NULL) return 0;
+       if (file == NULL) return 0;
 
        writeHeader(file, width, height);
 
        if (ibuf->rect)
-               cp= (unsigned char *)ibuf->rect + ibuf->channels*(height-1)*width;
+               cp = (unsigned char *)ibuf->rect + ibuf->channels * (height - 1) * width;
        if (ibuf->rect_float)
-               fp= ibuf->rect_float + ibuf->channels*(height-1)*width;
+               fp = ibuf->rect_float + ibuf->channels * (height - 1) * width;
        
-       for (y=height-1;y>=0;y--) {
+       for (y = height - 1; y >= 0; y--) {
                if (fwritecolrs(file, width, ibuf->channels, cp, fp) < 0) {
                        fclose(file);
                        printf("HDR write error\n");
                        return 0;
                }
-               if (cp) cp-= ibuf->channels*width;
-               if (fp) fp-= ibuf->channels*width;
+               if (cp) cp -= ibuf->channels * width;
+               if (fp) fp -= ibuf->channels * width;
        }
 
        fclose(file);
index 3ccb6739beb67d69c28d036f468d48157fc24366..5a652a50cbb64cacefd3e0f38ee22999f3bb41ec 100644 (file)
@@ -59,27 +59,27 @@ struct ImBuf *IMB_half_x(struct ImBuf *ibuf1)
        float af, rf, gf, bf, *p1f, *_p1f, *destf;
        int do_rect, do_float;
 
-       if (ibuf1==NULL) return (NULL);
-       if (ibuf1->rect==NULL && ibuf1->rect_float==NULL) return (NULL);
+       if (ibuf1 == NULL) return (NULL);
+       if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) return (NULL);
 
-       do_rect= (ibuf1->rect != NULL);
-       do_float= (ibuf1->rect_float != NULL);
+       do_rect = (ibuf1->rect != NULL);
+       do_float = (ibuf1->rect_float != NULL);
        
        if (ibuf1->x <= 1) return(IMB_dupImBuf(ibuf1));
        
-       ibuf2 = IMB_allocImBuf((ibuf1->x)/2, ibuf1->y, ibuf1->planes, ibuf1->flags);
-       if (ibuf2==NULL) return (NULL);
+       ibuf2 = IMB_allocImBuf((ibuf1->x) / 2, ibuf1->y, ibuf1->planes, ibuf1->flags);
+       if (ibuf2 == NULL) return (NULL);
 
        _p1 = (uchar *) ibuf1->rect;
-       dest=(uchar *) ibuf2->rect;
+       dest = (uchar *) ibuf2->rect;
 
        _p1f = ibuf1->rect_float;
-       destf= ibuf2->rect_float;
+       destf = ibuf2->rect_float;
 
-       for (y=ibuf2->y;y>0;y--) {
+       for (y = ibuf2->y; y > 0; y--) {
                p1 = _p1;
                p1f = _p1f;
-               for (x = ibuf2->x; x>0; x--) {
+               for (x = ibuf2->x; x > 0; x--) {
                        if (do_rect) {
                                a = *(p1++);
                                b = *(p1++);
@@ -103,10 +103,10 @@ struct ImBuf *IMB_half_x(struct ImBuf *ibuf1)
                                bf += *(p1f++);
                                gf += *(p1f++);
                                rf += *(p1f++);
-                               *(destf++) = 0.5f*af;
-                               *(destf++) = 0.5f*bf;
-                               *(destf++) = 0.5f*gf;
-                               *(destf++) = 0.5f*rf;
+                               *(destf++) = 0.5f * af;
+                               *(destf++) = 0.5f * bf;
+                               *(destf++) = 0.5f * gf;
+                               *(destf++) = 0.5f * rf;
                        }
                }
                if (do_rect) _p1 += (ibuf1->x << 2);
@@ -122,17 +122,17 @@ struct ImBuf *IMB_double_fast_x(struct ImBuf *ibuf1)
        int *p1, *dest, i, col, do_rect, do_float;
        float *p1f, *destf;
 
-       if (ibuf1==NULL) return (NULL);
-       if (ibuf1->rect==NULL && ibuf1->rect_float==NULL) return (NULL);
+       if (ibuf1 == NULL) return (NULL);
+       if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) return (NULL);
 
-       do_rect= (ibuf1->rect != NULL);
-       do_float= (ibuf1->rect_float != NULL);
+       do_rect = (ibuf1->rect != NULL);
+       do_float = (ibuf1->rect_float != NULL);
        
        ibuf2 = IMB_allocImBuf(2 * ibuf1->x, ibuf1->y, ibuf1->planes, ibuf1->flags);
-       if (ibuf2==NULL) return (NULL);
+       if (ibuf2 == NULL) return (NULL);
 
        p1 = (int *) ibuf1->rect;
-       dest=(int *) ibuf2->rect;
+       dest = (int *) ibuf2->rect;
        p1f = (float *)ibuf1->rect_float;
        destf = (float *)ibuf2->rect_float;
 
@@ -143,12 +143,12 @@ struct ImBuf *IMB_double_fast_x(struct ImBuf *ibuf1)
                        *dest++ = col;
                }
                if (do_float) {
-                       destf[0]= destf[4] = p1f[0];
-                       destf[1]= destf[5] = p1f[1];
-                       destf[2]= destf[6] = p1f[2];
-                       destf[3]= destf[7] = p1f[3];
-                       destf+= 8;
-                       p1f+= 4;
+                       destf[0] = destf[4] = p1f[0];
+                       destf[1] = destf[5] = p1f[1];
+                       destf[2] = destf[6] = p1f[2];
+                       destf[3] = destf[7] = p1f[3];
+                       destf += 8;
+                       p1f += 4;
                }
        }
 
@@ -159,8 +159,8 @@ struct ImBuf *IMB_double_x(struct ImBuf *ibuf1)
 {
        struct ImBuf *ibuf2;
 
-       if (ibuf1==NULL) return (NULL);
-       if (ibuf1->rect==NULL && ibuf1->rect_float==NULL) return (NULL);
+       if (ibuf1 == NULL) return (NULL);
+       if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) return (NULL);
 
        ibuf2 = IMB_double_fast_x(ibuf1);
 
@@ -178,24 +178,24 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1)
        int do_rect, do_float;
        float af, rf, gf, bf, *p1f, *p2f, *_p1f, *destf;
 
-       p1= p2= NULL;
-       p1f= p2f= NULL;
-       if (ibuf1==NULL) return (NULL);
-       if (ibuf1->rect==NULL && ibuf1->rect_float==NULL) return (NULL);
+       p1 = p2 = NULL;
+       p1f = p2f = NULL;
+       if (ibuf1 == NULL) return (NULL);
+       if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) return (NULL);
        if (ibuf1->y <= 1) return(IMB_dupImBuf(ibuf1));
 
-       do_rect= (ibuf1->rect != NULL);
-       do_float= (ibuf1->rect_float != NULL);
+       do_rect = (ibuf1->rect != NULL);
+       do_float = (ibuf1->rect_float != NULL);
 
        ibuf2 = IMB_allocImBuf(ibuf1->x, (ibuf1->y) / 2, ibuf1->planes, ibuf1->flags);
-       if (ibuf2==NULL) return (NULL);
+       if (ibuf2 == NULL) return (NULL);
 
        _p1 = (uchar *) ibuf1->rect;
-       dest=(uchar *) ibuf2->rect;
+       dest = (uchar *) ibuf2->rect;
        _p1f = (float *) ibuf1->rect_float;
-       destf= (float *) ibuf2->rect_float;
+       destf = (float *) ibuf2->rect_float;
 
-       for (y=ibuf2->y; y>0; y--) {
+       for (y = ibuf2->y; y > 0; y--) {
                if (do_rect) {
                        p1 = _p1;
                        p2 = _p1 + (ibuf1->x << 2);
@@ -228,10 +228,10 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1)
                                bf += *(p2f++);
                                gf += *(p2f++);
                                rf += *(p2f++);
-                               *(destf++) = 0.5f*af;
-                               *(destf++) = 0.5f*bf;
-                               *(destf++) = 0.5f*gf;
-                               *(destf++) = 0.5f*rf;
+                               *(destf++) = 0.5f * af;
+                               *(destf++) = 0.5f * bf;
+                               *(destf++) = 0.5f * gf;
+                               *(destf++) = 0.5f * rf;
                        }
                }
                if (do_rect) _p1 += (ibuf1->x << 3);
@@ -249,19 +249,19 @@ struct ImBuf *IMB_double_fast_y(struct ImBuf *ibuf1)
        int x, y;
        int do_rect, do_float;
 
-       if (ibuf1==NULL) return (NULL);
-       if (ibuf1->rect==NULL && ibuf1->rect_float==NULL) return (NULL);
+       if (ibuf1 == NULL) return (NULL);
+       if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) return (NULL);
 
-       do_rect= (ibuf1->rect != NULL);
-       do_float= (ibuf1->rect_float != NULL);
+       do_rect = (ibuf1->rect != NULL);
+       do_float = (ibuf1->rect_float != NULL);
 
        ibuf2 = IMB_allocImBuf(ibuf1->x, 2 * ibuf1->y, ibuf1->planes, ibuf1->flags);
-       if (ibuf2==NULL) return (NULL);
+       if (ibuf2 == NULL) return (NULL);
 
        p1 = (int *) ibuf1->rect;
-       dest1= (int *) ibuf2->rect;
+       dest1 = (int *) ibuf2->rect;
        p1f = (float *) ibuf1->rect_float;
-       dest1f= (float *) ibuf2->rect_float;
+       dest1f = (float *) ibuf2->rect_float;
 
        for (y = ibuf1->y; y > 0; y--) {
                if (do_rect) {
@@ -270,7 +270,7 @@ struct ImBuf *IMB_double_fast_y(struct ImBuf *ibuf1)
                        dest1 = dest2;
                }
                if (do_float) {
-                       dest2f = dest1f + (4*ibuf2->x);
+                       dest2f = dest1f + (4 * ibuf2->x);
                        for (x = ibuf2->x * 4; x > 0; x--) *dest1f++ = *dest2f++ = *p1f++;
                        dest1f = dest2f;
                }
@@ -283,8 +283,8 @@ struct ImBuf *IMB_double_y(struct ImBuf *ibuf1)
 {
        struct ImBuf *ibuf2;
 
-       if (ibuf1==NULL) return (NULL);
-       if (ibuf1->rect==NULL) return (NULL);
+       if (ibuf1 == NULL) return (NULL);
+       if (ibuf1->rect == NULL) return (NULL);
 
        ibuf2 = IMB_double_fast_y(ibuf1);
        
@@ -298,22 +298,22 @@ void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1)
        uchar *p1, *p2 = NULL, *dest;
        float *p1f, *destf, *p2f = NULL;
        int x, y;
-       const short do_rect= (ibuf1->rect != NULL);
-       const short do_float= (ibuf1->rect_float != NULL) && (ibuf2->rect_float != NULL);
+       const short do_rect = (ibuf1->rect != NULL);
+       const short do_float = (ibuf1->rect_float != NULL) && (ibuf2->rect_float != NULL);
 
        if (do_rect && (ibuf2->rect == NULL)) {
                imb_addrectImBuf(ibuf2);
        }
 
        p1f = ibuf1->rect_float;
-       destf=ibuf2->rect_float;
+       destf = ibuf2->rect_float;
        p1 = (uchar *) ibuf1->rect;
-       dest=(uchar *) ibuf2->rect;
+       dest = (uchar *) ibuf2->rect;
 
-       for (y=ibuf2->y;y>0;y--) {
+       for (y = ibuf2->y; y > 0; y--) {
                if (do_rect) p2 = p1 + (ibuf1->x << 2);
                if (do_float) p2f = p1f + (ibuf1->x << 2);
-               for (x=ibuf2->x;x>0;x--) {
+               for (x = ibuf2->x; x > 0; x--) {
                        if (do_rect) {
                                dest[0] = (p1[0] + p2[0] + p1[4] + p2[4]) >> 2;
                                dest[1] = (p1[1] + p2[1] + p1[5] + p2[5]) >> 2;
@@ -324,37 +324,36 @@ void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1)
                                dest += 4;
                        }
                        if (do_float) {
-                               destf[0] = 0.25f*(p1f[0] + p2f[0] + p1f[4] + p2f[4]);
-                               destf[1] = 0.25f*(p1f[1] + p2f[1] + p1f[5] + p2f[5]);
-                               destf[2] = 0.25f*(p1f[2] + p2f[2] + p1f[6] + p2f[6]);
-                               destf[3] = 0.25f*(p1f[3] + p2f[3] + p1f[7] + p2f[7]);
+                               destf[0] = 0.25f * (p1f[0] + p2f[0] + p1f[4] + p2f[4]);
+                               destf[1] = 0.25f * (p1f[1] + p2f[1] + p1f[5] + p2f[5]);
+                               destf[2] = 0.25f * (p1f[2] + p2f[2] + p1f[6] + p2f[6]);
+                               destf[3] = 0.25f * (p1f[3] + p2f[3] + p1f[7] + p2f[7]);
                                p1f += 8; 
                                p2f += 8; 
                                destf += 4;
                        }
                }
-               if (do_rect) p1=p2;
-               if (do_float) p1f=p2f;
+               if (do_rect) p1 = p2;
+               if (do_float) p1f = p2f;
                if (ibuf1->x & 1) {
-                       if (do_rect) p1+=4;
-                       if (do_float) p1f+=4;
+                       if (do_rect) p1 += 4;
+                       if (do_float) p1f += 4;
                }
        }
        
 }
 
-struct ImBuf *IMB_onehalf(struct ImBuf *ibuf1)
-{
+struct ImBuf *IMB_onehalf(struct ImBuf *ibuf1){
        struct ImBuf *ibuf2;
 
-       if (ibuf1==NULL) return (NULL);
-       if (ibuf1->rect==NULL && ibuf1->rect_float==NULL) return (NULL);
+       if (ibuf1 == NULL) return (NULL);
+       if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) return (NULL);
        
        if (ibuf1->x <= 1) return(IMB_half_y(ibuf1));
        if (ibuf1->y <= 1) return(IMB_half_x(ibuf1));
        
-       ibuf2=IMB_allocImBuf((ibuf1->x)/2, (ibuf1->y)/2, ibuf1->planes, ibuf1->flags);
-       if (ibuf2==NULL) return (NULL);
+       ibuf2 = IMB_allocImBuf((ibuf1->x) / 2, (ibuf1->y) / 2, ibuf1->planes, ibuf1->flags);
+       if (ibuf2 == NULL) return (NULL);
        
        imb_onehalf_no_alloc(ibuf2, ibuf1);
        
@@ -364,8 +363,8 @@ struct ImBuf *IMB_onehalf(struct ImBuf *ibuf1)
 /* q_scale_linear_interpolation helper functions */
 
 static void enlarge_picture_byte(
-       unsigned char* src, unsigned char* dst, int src_width, 
-       int src_height, int dst_width, int dst_height)
+        unsigned char *src, unsigned char *dst, int src_width,
+        int src_height, int dst_width, int dst_height)
 {
        double ratiox = (double) (dst_width - 1.0)  / (double) (src_width - 1.001);
        double ratioy = (double) (dst_height - 1.0) / (double) (src_height - 1.001);
@@ -377,8 +376,8 @@ static void enlarge_picture_byte(
 
        y_src = 0;
        for (y_dst = 0; y_dst < dst_height; y_dst++) {
-               unsigned charline1 = src + (y_src >> 16) * 4 * src_width;
-               unsigned charline2 = line1 + 4 * src_width;
+               unsigned char *line1 = src + (y_src >> 16) * 4 * src_width;
+               unsigned char *line2 = line1 + 4 * src_width;
                uintptr_t weight1y = 65536 - (y_src & 0xffff);
                uintptr_t weight2y = 65536 - weight1y;
 
@@ -429,25 +428,25 @@ struct scale_outpix_byte {
 };
 
 static void shrink_picture_byte(
-       unsigned char* src, unsigned char* dst, int src_width, 
-       int src_height, int dst_width, int dst_height)
+        unsigned char *src, unsigned char *dst, int src_width,
+        int src_height, int dst_width, int dst_height)
 {
        double ratiox = (double) (dst_width) / (double) (src_width);
        double ratioy = (double) (dst_height) / (double) (src_height);
        uintptr_t x_src, dx_dst, x_dst;
        uintptr_t y_src, dy_dst, y_dst;
        intptr_t y_counter;
-       unsigned char * dst_begin = dst;
+       unsigned char *dst_begin = dst;
 
-       struct scale_outpix_byte * dst_line1 = NULL;
-       struct scale_outpix_byte * dst_line2 = NULL;
+       struct scale_outpix_byte *dst_line1 = NULL;
+       struct scale_outpix_byte *dst_line2 = NULL;
 
-       dst_line1 = (struct scale_outpix_byte*) MEM_callocN(
-               (dst_width + 1) * sizeof(struct scale_outpix_byte), 
-               "shrink_picture_byte 1");
-       dst_line2 = (struct scale_outpix_byte*) MEM_callocN(
-               (dst_width + 1) * sizeof(struct scale_outpix_byte),
-               "shrink_picture_byte 2");
+       dst_line1 = (struct scale_outpix_byte *) MEM_callocN(
+           (dst_width + 1) * sizeof(struct scale_outpix_byte),
+           "shrink_picture_byte 1");
+       dst_line2 = (struct scale_outpix_byte *) MEM_callocN(
+           (dst_width + 1) * sizeof(struct scale_outpix_byte),
+           "shrink_picture_byte 2");
 
        dx_dst = 65536.0 * ratiox;
        dy_dst = 65536.0 * ratioy;
@@ -455,7 +454,7 @@ static void shrink_picture_byte(
        y_dst = 0;
        y_counter = 65536;
        for (y_src = 0; y_src < src_height; y_src++) {
-               unsigned charline = src + y_src * 4 * src_width;
+               unsigned char *line = src + y_src * 4 * src_width;
                uintptr_t weight1y = 65535 - (y_dst & 0xffff);
                uintptr_t weight2y = 65535 - weight1y;
                x_dst = 0;
@@ -486,19 +485,19 @@ static void shrink_picture_byte(
 
                        w = (weight1y * weight2x) >> 16;
 
-                       dst_line1[x+1].r += (line[0] * w + 32767) >> 16;
-                       dst_line1[x+1].g += (line[1] * w + 32767) >> 16;
-                       dst_line1[x+1].b += (line[2] * w + 32767) >> 16;
-                       dst_line1[x+1].a += (line[3] * w + 32767) >> 16;
-                       dst_line1[x+1].weight += w;
+                       dst_line1[x + 1].r += (line[0] * w + 32767) >> 16;
+                       dst_line1[x + 1].g += (line[1] * w + 32767) >> 16;
+                       dst_line1[x + 1].b += (line[2] * w + 32767) >> 16;
+                       dst_line1[x + 1].a += (line[3] * w + 32767) >> 16;
+                       dst_line1[x + 1].weight += w;
 
                        w = (weight2y * weight2x) >> 16;
 
-                       dst_line2[x+1].r += (line[0] * w + 32767) >> 16;
-                       dst_line2[x+1].g += (line[1] * w + 32767) >> 16;
-                       dst_line2[x+1].b += (line[2] * w + 32767) >> 16;
-                       dst_line2[x+1].a += (line[3] * w + 32767) >> 16;
-                       dst_line2[x+1].weight += w;
+                       dst_line2[x + 1].r += (line[0] * w + 32767) >> 16;
+                       dst_line2[x + 1].g += (line[1] * w + 32767) >> 16;
+                       dst_line2[x + 1].b += (line[2] * w + 32767) >> 16;
+                       dst_line2[x + 1].a += (line[3] * w + 32767) >> 16;
+                       dst_line2[x + 1].weight += w;
 
                        x_dst += dx_dst;
                        line += 4;
@@ -509,16 +508,16 @@ static void shrink_picture_byte(
                if (y_counter < 0) {
                        int val;
                        uintptr_t x;
-                       struct scale_outpix_byte * temp;
+                       struct scale_outpix_byte *temp;
 
                        y_counter += 65536;
                        
-                       for (x=0; x < dst_width; x++) {
+                       for (x = 0; x < dst_width; x++) {
                                uintptr_t f =  0x80000000UL / dst_line1[x].weight;
-                               *dst++ = (val= (dst_line1[x].r * f) >> 15) > 255 ? 255: val;
-                               *dst++ = (val= (dst_line1[x].g * f) >> 15) > 255 ? 255: val;
-                               *dst++ = (val= (dst_line1[x].b * f) >> 15) > 255 ? 255: val;
-                               *dst++ = (val= (dst_line1[x].a * f) >> 15) > 255 ? 255: val;
+                               *dst++ = (val = (dst_line1[x].r * f) >> 15) > 255 ? 255 : val;
+                               *dst++ = (val = (dst_line1[x].g * f) >> 15) > 255 ? 255 : val;
+                               *dst++ = (val = (dst_line1[x].b * f) >> 15) > 255 ? 255 : val;
+                               *dst++ = (val = (dst_line1[x].a * f) >> 15) > 255 ? 255 : val;
                        }
                        memset(dst_line1, 0, dst_width *
                               sizeof(struct scale_outpix_byte));
@@ -532,10 +531,10 @@ static void shrink_picture_byte(
                uintptr_t x;
                for (x = 0; x < dst_width; x++) {
                        uintptr_t f = 0x80000000UL / dst_line1[x].weight;
-                       *dst++ = (val= (dst_line1[x].r * f) >> 15) > 255 ? 255: val;
-                       *dst++ = (val= (dst_line1[x].g * f) >> 15) > 255 ? 255: val;
-                       *dst++ = (val= (dst_line1[x].b * f) >> 15) > 255 ? 255: val;
-                       *dst++ = (val= (dst_line1[x].a * f) >> 15) > 255 ? 255: val;
+                       *dst++ = (val = (dst_line1[x].r * f) >> 15) > 255 ? 255 : val;
+                       *dst++ = (val = (dst_line1[x].g * f) >> 15) > 255 ? 255 : val;
+                       *dst++ = (val = (dst_line1[x].b * f) >> 15) > 255 ? 255 : val;
+                       *dst++ = (val = (dst_line1[x].a * f) >> 15) > 255 ? 255 : val;
                }
        }
        MEM_freeN(dst_line1);
@@ -543,22 +542,22 @@ static void shrink_picture_byte(
 }
 
 
-static void q_scale_byte(unsigned char* in, unsigned char* out, int in_width, 
-                        int in_height, int dst_width, int dst_height)
+static void q_scale_byte(unsigned char *in, unsigned char *out, int in_width,
+                         int in_height, int dst_width, int dst_height)
 {
        if (dst_width > in_width && dst_height > in_height) {
                enlarge_picture_byte(in, out, in_width, in_height,
-                                        dst_width, dst_height);
+                                    dst_width, dst_height);
        }
        else if (dst_width < in_width && dst_height < in_height) {
                shrink_picture_byte(in, out, in_width, in_height,
-                                       dst_width, dst_height);
+                                   dst_width, dst_height);
        }
 }
 
 static void enlarge_picture_float(
-       float* src, float* dst, int src_width, 
-       int src_height, int dst_width, int dst_height)
+        float *src, float *dst, int src_width,
+        int src_height, int dst_width, int dst_height)
 {
        double ratiox = (double) (dst_width - 1.0) / (double) (src_width - 1.001);
        double ratioy = (double) (dst_height - 1.0) / (double) (src_height - 1.001);
@@ -572,8 +571,8 @@ static void enlarge_picture_float(
 
        y_src = 0;
        for (y_dst = 0; y_dst < dst_height; y_dst++) {
-               floatline1 = src + ((int) y_src) * 4 * src_width;
-               floatline2 = line1 + 4 * src_width;
+               float *line1 = src + ((int) y_src) * 4 * src_width;
+               float *line2 = line1 + 4 * src_width;
                const float weight1y = (float)(1.0 - (y_src - (int) y_src));
                const float weight2y = 1.0f - weight1y;
 
@@ -593,7 +592,7 @@ static void enlarge_picture_float(
 
                        uintptr_t x = ((int) x_src) * 4;
 
-                       *dst++ = line1[x]     * w11     +
+                       *dst++ = line1[x]     * w11 +
                                 line2[x]     * w21 +
                                 line1[4 + x] * w12 +
                                 line2[4 + x] * w22;
@@ -629,27 +628,27 @@ struct scale_outpix_float {
 };
 
 static void shrink_picture_float(
-       float* src, float* dst, int src_width, 
-       int src_height, int dst_width, int dst_height)
+        float *src, float *dst, int src_width,
+        int src_height, int dst_width, int dst_height)
 {
        double ratiox = (double) (dst_width) / (double) (src_width);
        double ratioy = (double) (dst_height) / (double) (src_height);
        uintptr_t x_src;
        uintptr_t y_src;
-               float dx_dst, x_dst;
+       float dx_dst, x_dst;
        float dy_dst, y_dst;
        float y_counter;
-       float * dst_begin = dst;
+       float *dst_begin = dst;
 
-       struct scale_outpix_float * dst_line1;
-       struct scale_outpix_float * dst_line2;
+       struct scale_outpix_float *dst_line1;
+       struct scale_outpix_float *dst_line2;
 
-       dst_line1 = (struct scale_outpix_float*) MEM_callocN(
-               (dst_width + 1) * sizeof(struct scale_outpix_float), 
-               "shrink_picture_float 1");
-       dst_line2 = (struct scale_outpix_float*) MEM_callocN(
-               (dst_width + 1) * sizeof(struct scale_outpix_float),
-               "shrink_picture_float 2");
+       dst_line1 = (struct scale_outpix_float *) MEM_callocN(
+               (dst_width + 1) * sizeof(struct scale_outpix_float),
+               "shrink_picture_float 1");
+       dst_line2 = (struct scale_outpix_float *) MEM_callocN(
+               (dst_width + 1) * sizeof(struct scale_outpix_float),
+               "shrink_picture_float 2");
 
        dx_dst = ratiox;
        dy_dst = ratioy;
@@ -657,7 +656,7 @@ static void shrink_picture_float(
        y_dst = 0;
        y_counter = 1.0;
        for (y_src = 0; y_src < src_height; y_src++) {
-               floatline = src + y_src * 4 * src_width;
+               float *line = src + y_src * 4 * src_width;
                uintptr_t weight1y = 1.0f - (y_dst - (int) y_dst);
                uintptr_t weight2y = 1.0f - weight1y;
                x_dst = 0;
@@ -687,19 +686,19 @@ static void shrink_picture_float(
 
                        w = weight1y * weight2x;
 
-                       dst_line1[x+1].r += line[0] * w;
-                       dst_line1[x+1].g += line[1] * w;
-                       dst_line1[x+1].b += line[2] * w;
-                       dst_line1[x+1].a += line[3] * w;
-                       dst_line1[x+1].weight += w;
+                       dst_line1[x + 1].r += line[0] * w;
+                       dst_line1[x + 1].g += line[1] * w;
+                       dst_line1[x + 1].b += line[2] * w;
+                       dst_line1[x + 1].a += line[3] * w;
+                       dst_line1[x + 1].weight += w;
 
                        w = weight2y * weight2x;
 
-                       dst_line2[x+1].r += line[0] * w;
-                       dst_line2[x+1].g += line[1] * w;
-                       dst_line2[x+1].b += line[2] * w;
-                       dst_line2[x+1].a += line[3] * w;
-                       dst_line2[x+1].weight += w;
+                       dst_line2[x + 1].r += line[0] * w;
+                       dst_line2[x + 1].g += line[1] * w;
+                       dst_line2[x + 1].b += line[2] * w;
+                       dst_line2[x + 1].a += line[3] * w;
+                       dst_line2[x + 1].weight += w;
 
                        x_dst += dx_dst;
                        line += 4;
@@ -709,11 +708,11 @@ static void shrink_picture_float(
                y_counter -= dy_dst;
                if (y_counter < 0) {
                        uintptr_t x;
-                       struct scale_outpix_float * temp;
+                       struct scale_outpix_float *temp;
 
                        y_counter += 1.0f;
                        
-                       for (x=0; x < dst_width; x++) {
+                       for (x = 0; x < dst_width; x++) {
                                float f = 1.0f / dst_line1[x].weight;
                                *dst++ = dst_line1[x].r * f;
                                *dst++ = dst_line1[x].g * f;
@@ -742,16 +741,16 @@ static void shrink_picture_float(
 }
 
 
-static void q_scale_float(float* in, float* out, int in_width, 
-                        int in_height, int dst_width, int dst_height)
+static void q_scale_float(float *in, float *out, int in_width,
+                          int in_height, int dst_width, int dst_height)
 {
        if (dst_width > in_width && dst_height > in_height) {
                enlarge_picture_float(in, out, in_width, in_height,
-                                         dst_width, dst_height);
+                                     dst_width, dst_height);
        }
        else if (dst_width < in_width && dst_height < in_height) {
                shrink_picture_float(in, out, in_width, in_height,
-                                        dst_width, dst_height);
+                                    dst_width, dst_height);
        }
 }
 
@@ -777,16 +776,17 @@ static void q_scale_float(float* in, float* out, int in_width,
  * NOTE: disabled, due to inacceptable inaccuracy and quality loss, see bug #18609 (ton)
  */
 static int q_scale_linear_interpolation(
-       struct ImBuf *ibuf, int newx, int newy)
+        struct ImBuf *ibuf, int newx, int newy)
 {
        if ((newx >= ibuf->x && newy <= ibuf->y) ||
-               (newx <= ibuf->x && newy >= ibuf->y)) {
+           (newx <= ibuf->x && newy >= ibuf->y))
+       {
                return FALSE;
        }
 
        if (ibuf->rect) {
-               unsigned char * newrect =
-                       MEM_mallocN(newx * newy * sizeof(int), "q_scale rect");
+               unsigned char *newrect =
+                   MEM_mallocN(newx * newy * sizeof(int), "q_scale rect");
                q_scale_byte((unsigned char *)ibuf->rect, newrect, ibuf->x, ibuf->y,
                             newx, newy);
 
@@ -795,9 +795,9 @@ static int q_scale_linear_interpolation(
                ibuf->rect = (unsigned int *) newrect;
        }
        if (ibuf->rect_float) {
-               float * newrect =
-                       MEM_mallocN(newx * newy * 4 *sizeof(float),
-                                   "q_scale rectfloat");
+               float *newrect =
+                   MEM_mallocN(newx * newy * 4 * sizeof(float),
+                               "q_scale rectfloat");
                q_scale_float(ibuf->rect_float, newrect, ibuf->x, ibuf->y,
                              newx, newy);
                imb_freerectfloatImBuf(ibuf);
@@ -812,29 +812,29 @@ static int q_scale_linear_interpolation(
 
 static struct ImBuf *scaledownx(struct ImBuf *ibuf, int newx)
 {
-       const int do_rect= (ibuf->rect != NULL);
-       const int do_float= (ibuf->rect_float != NULL);
-       const size_t rect_size= ibuf->x * ibuf->y * 4;
+       const int do_rect = (ibuf->rect != NULL);
+       const int do_float = (ibuf->rect_float != NULL);
+       const size_t rect_size = ibuf->x * ibuf->y * 4;
 
        uchar *rect, *_newrect, *newrect;
        float *rectf, *_newrectf, *newrectf;
        float sample, add, val[4], nval[4], valf[4], nvalf[4];
        int x, y;
 
-       rectf= _newrectf= newrectf= NULL; 
-       rect=_newrect= newrect= NULL; 
-       nval[0]=  nval[1]= nval[2]= nval[3]= 0.0f;
-       nvalf[0]=nvalf[1]=nvalf[2]=nvalf[3]= 0.0f;
+       rectf = _newrectf = newrectf = NULL;
+       rect = _newrect = newrect = NULL;
+       nval[0] =  nval[1] = nval[2] = nval[3] = 0.0f;
+       nvalf[0] = nvalf[1] = nvalf[2] = nvalf[3] = 0.0f;
 
        if (!do_rect && !do_float) return (ibuf);
 
        if (do_rect) {
                _newrect = MEM_mallocN(newx * ibuf->y * sizeof(uchar) * 4, "scaledownx");
-               if (_newrect==NULL) return(ibuf);
+               if (_newrect == NULL) return(ibuf);
        }
        if (do_float) {
                _newrectf = MEM_mallocN(newx * ibuf->y * sizeof(float) * 4, "scaledownxf");
-               if (_newrectf==NULL) {
+               if (_newrectf == NULL) {
                        if (_newrect) MEM_freeN(_newrect);
                        return(ibuf);
                }
@@ -853,21 +853,21 @@ static struct ImBuf *scaledownx(struct ImBuf *ibuf, int newx)
                
        for (y = ibuf->y; y > 0; y--) {
                sample = 0.0f;
-               val[0]=  val[1]= val[2]= val[3]= 0.0f;
-               valf[0]=valf[1]=valf[2]=valf[3]= 0.0f;
+               val[0] =  val[1] = val[2] = val[3] = 0.0f;
+               valf[0] = valf[1] = valf[2] = valf[3] = 0.0f;
 
                for (x = newx; x > 0; x--) {
                        if (do_rect) {
-                               nval[0] = - val[0] * sample;
-                               nval[1] = - val[1] * sample;
-                               nval[2] = - val[2] * sample;
-                               nval[3] = - val[3] * sample;
+                               nval[0] = -val[0] * sample;
+                               nval[1] = -val[1] * sample;
+                               nval[2] = -val[2] * sample;
+                               nval[3] = -val[3] * sample;
                        }
                        if (do_float) {
-                               nvalf[0] = - valf[0] * sample;
-                               nvalf[1] = - valf[1] * sample;
-                               nvalf[2] = - valf[2] * sample;
-                               nvalf[3] = - valf[3] * sample;
+                               nvalf[0] = -valf[0] * sample;
+                               nvalf[1] = -valf[1] * sample;
+                               nvalf[2] = -valf[2] * sample;
+                               nvalf[3] = -valf[3] * sample;
                        }
                        
                        sample += add;
@@ -892,25 +892,25 @@ static struct ImBuf *scaledownx(struct ImBuf *ibuf, int newx)
                        }
                        
                        if (do_rect) {
-                               val[0]= rect[0];val[1]= rect[1];val[2]= rect[2];val[3]= rect[3];
+                               val[0] = rect[0]; val[1] = rect[1]; val[2] = rect[2]; val[3] = rect[3];
                                rect += 4;
                                
-                               newrect[0] = ((nval[0] + sample * val[0])/add + 0.5f);
-                               newrect[1] = ((nval[1] + sample * val[1])/add + 0.5f);
-                               newrect[2] = ((nval[2] + sample * val[2])/add + 0.5f);
-                               newrect[3] = ((nval[3] + sample * val[3])/add + 0.5f);
+                               newrect[0] = ((nval[0] + sample * val[0]) / add + 0.5f);
+                               newrect[1] = ((nval[1] + sample * val[1]) / add + 0.5f);
+                               newrect[2] = ((nval[2] + sample * val[2]) / add + 0.5f);
+                               newrect[3] = ((nval[3] + sample * val[3]) / add + 0.5f);
                                
                                newrect += 4;
                        }
                        if (do_float) {
                                
-                               valf[0]= rectf[0];valf[1]= rectf[1];valf[2]= rectf[2];valf[3]= rectf[3];
+                               valf[0] = rectf[0]; valf[1] = rectf[1]; valf[2] = rectf[2]; valf[3] = rectf[3];
                                rectf += 4;
                                
-                               newrectf[0] = ((nvalf[0] + sample * valf[0])/add);
-                               newrectf[1] = ((nvalf[1] + sample * valf[1])/add);
-                               newrectf[2] = ((nvalf[2] + sample * valf[2])/add);
-                               newrectf[3] = ((nvalf[3] + sample * valf[3])/add);
+                               newrectf[0] = ((nvalf[0] + sample * valf[0]) / add);
+                               newrectf[1] = ((nvalf[1] + sample * valf[1]) / add);
+                               newrectf[2] = ((nvalf[2] + sample * valf[2]) / add);
+                               newrectf[3] = ((nvalf[3] + sample * valf[3]) / add);
                                
                                newrectf += 4;
                        }
@@ -942,29 +942,29 @@ static struct ImBuf *scaledownx(struct ImBuf *ibuf, int newx)
 
 static struct ImBuf *scaledowny(struct ImBuf *ibuf, int newy)
 {
-       const int do_rect= (ibuf->rect != NULL);
-       const int do_float= (ibuf->rect_float != NULL);
-       const size_t rect_size= ibuf->x * ibuf->y * 4;
+       const int do_rect = (ibuf->rect != NULL);
+       const int do_float = (ibuf->rect_float != NULL);
+       const size_t rect_size = ibuf->x * ibuf->y * 4;
 
        uchar *rect, *_newrect, *newrect;
        float *rectf, *_newrectf, *newrectf;
        float sample, add, val[4], nval[4], valf[4], nvalf[4];
        int x, y, skipx;
 
-       rectf= _newrectf= newrectf= NULL; 
-       rect= _newrect= newrect= NULL; 
-       nval[0]=  nval[1]= nval[2]= nval[3]= 0.0f;
-       nvalf[0]=nvalf[1]=nvalf[2]=nvalf[3]= 0.0f;
+       rectf = _newrectf = newrectf = NULL;
+       rect = _newrect = newrect = NULL;
+       nval[0] =  nval[1] = nval[2] = nval[3] = 0.0f;
+       nvalf[0] = nvalf[1] = nvalf[2] = nvalf[3] = 0.0f;
 
        if (!do_rect && !do_float) return (ibuf);
 
        if (do_rect) {
                _newrect = MEM_mallocN(newy * ibuf->x * sizeof(uchar) * 4, "scaledowny");
-               if (_newrect==NULL) return(ibuf);
+               if (_newrect == NULL) return(ibuf);
        }
        if (do_float) {
                _newrectf = MEM_mallocN(newy * ibuf->x * sizeof(float) * 4, "scaledownyf");
-               if (_newrectf==NULL) {
+               if (_newrectf == NULL) {
                        if (_newrect) MEM_freeN(_newrect);
                        return(ibuf);
                }
@@ -984,21 +984,21 @@ static struct ImBuf *scaledowny(struct ImBuf *ibuf, int newy)
                }
                
                sample = 0.0f;
-               val[0]=  val[1]= val[2]= val[3]= 0.0f;
-               valf[0]=valf[1]=valf[2]=valf[3]= 0.0f;
+               val[0] =  val[1] = val[2] = val[3] = 0.0f;
+               valf[0] = valf[1] = valf[2] = valf[3] = 0.0f;
 
                for (y = newy; y > 0; y--) {
                        if (do_rect) {
-                               nval[0] = - val[0] * sample;
-                               nval[1] = - val[1] * sample;
-                               nval[2] = - val[2] * sample;
-                               nval[3] = - val[3] * sample;
+                               nval[0] = -val[0] * sample;
+                               nval[1] = -val[1] * sample;
+                               nval[2] = -val[2] * sample;
+                               nval[3] = -val[3] * sample;
                        }
                        if (do_float) {
-                               nvalf[0] = - valf[0] * sample;
-                               nvalf[1] = - valf[1] * sample;
-                               nvalf[2] = - valf[2] * sample;
-                               nvalf[3] = - valf[3] * sample;
+                               nvalf[0] = -valf[0] * sample;
+                               nvalf[1] = -valf[1] * sample;
+                               nvalf[2] = -valf[2] * sample;
+                               nvalf[3] = -valf[3] * sample;
                        }
                        
                        sample += add;
@@ -1023,25 +1023,25 @@ static struct ImBuf *scaledowny(struct ImBuf *ibuf, int newy)
                        }
 
                        if (do_rect) {
-                               val[0]= rect[0];val[1]= rect[1];val[2]= rect[2];val[3]= rect[3];
+                               val[0] = rect[0]; val[1] = rect[1]; val[2] = rect[2]; val[3] = rect[3];
                                rect += skipx;
                                
-                               newrect[0] = ((nval[0] + sample * val[0])/add + 0.5f);
-                               newrect[1] = ((nval[1] + sample * val[1])/add + 0.5f);
-                               newrect[2] = ((nval[2] + sample * val[2])/add + 0.5f);
-                               newrect[3] = ((nval[3] + sample * val[3])/add + 0.5f);
+                               newrect[0] = ((nval[0] + sample * val[0]) / add + 0.5f);
+                               newrect[1] = ((nval[1] + sample * val[1]) / add + 0.5f);
+                               newrect[2] = ((nval[2] + sample * val[2]) / add + 0.5f);
+                               newrect[3] = ((nval[3] + sample * val[3]) / add + 0.5f);
                                
                                newrect += skipx;
                        }
                        if (do_float) {
                                
-                               valf[0]= rectf[0];valf[1]= rectf[1];valf[2]= rectf[2];valf[3]= rectf[3];
+                               valf[0] = rectf[0]; valf[1] = rectf[1]; valf[2] = rectf[2]; valf[3] = rectf[3];
                                rectf += skipx;
                                
-                               newrectf[0] = ((nvalf[0] + sample * valf[0])/add);
-                               newrectf[1] = ((nvalf[1] + sample * valf[1])/add);
-                               newrectf[2] = ((nvalf[2] + sample * valf[2])/add);
-                               newrectf[3] = ((nvalf[3] + sample * valf[3])/add);
+                               newrectf[0] = ((nvalf[0] + sample * valf[0]) / add);
+                               newrectf[1] = ((nvalf[1] + sample * valf[1]) / add);
+                               newrectf[2] = ((nvalf[2] + sample * valf[2]) / add);
+                               newrectf[3] = ((nvalf[3] + sample * valf[3]) / add);
                                
                                newrectf += skipx;
                        }
@@ -1073,8 +1073,8 @@ static struct ImBuf *scaledowny(struct ImBuf *ibuf, int newy)
 
 static struct ImBuf *scaleupx(struct ImBuf *ibuf, int newx)
 {
-       uchar *rect, *_newrect=NULL, *newrect;
-       float *rectf, *_newrectf=NULL, *newrectf;
+       uchar *rect, *_newrect = NULL, *newrect;
+       float *rectf, *_newrectf = NULL, *newrectf;
        float sample, add;
        float val_a, nval_a, diff_a;
        float val_b, nval_b, diff_b;
@@ -1090,18 +1090,18 @@ static struct ImBuf *scaleupx(struct ImBuf *ibuf, int newx)
        val_g = nval_g = diff_g = val_r = nval_r = diff_r = 0;
        val_af = nval_af = diff_af = val_bf = nval_bf = diff_bf = 0;
        val_gf = nval_gf = diff_gf = val_rf = nval_rf = diff_rf = 0;
-       if (ibuf==NULL) return(NULL);
-       if (ibuf->rect==NULL && ibuf->rect_float==NULL) return (ibuf);
+       if (ibuf == NULL) return(NULL);
+       if (ibuf->rect == NULL && ibuf->rect_float == NULL) return (ibuf);
 
        if (ibuf->rect) {
                do_rect = 1;
                _newrect = MEM_mallocN(newx * ibuf->y * sizeof(int), "scaleupx");
-               if (_newrect==NULL) return(ibuf);
+               if (_newrect == NULL) return(ibuf);
        }
        if (ibuf->rect_float) {
                do_float = 1;
                _newrectf = MEM_mallocN(newx * ibuf->y * sizeof(float) * 4, "scaleupxf");
-               if (_newrectf==NULL) {
+               if (_newrectf == NULL) {
                        if (_newrect) MEM_freeN(_newrect);
                        return(ibuf);
                }
@@ -1240,8 +1240,8 @@ static struct ImBuf *scaleupx(struct ImBuf *ibuf, int newx)
 
 static struct ImBuf *scaleupy(struct ImBuf *ibuf, int newy)
 {
-       uchar *rect, *_newrect=NULL, *newrect;
-       float *rectf, *_newrectf=NULL, *newrectf;
+       uchar *rect, *_newrect = NULL, *newrect;
+       float *rectf, *_newrectf = NULL, *newrectf;
        float sample, add;
        float val_a, nval_a, diff_a;
        float val_b, nval_b, diff_b;
@@ -1257,18 +1257,18 @@ static struct ImBuf *scaleupy(struct ImBuf *ibuf, int newy)
        val_g = nval_g = diff_g = val_r = nval_r = diff_r = 0;
        val_af = nval_af = diff_af = val_bf = nval_bf = diff_bf = 0;
        val_gf = nval_gf = diff_gf = val_rf = nval_rf = diff_rf = 0;
-       if (ibuf==NULL) return(NULL);
-       if (ibuf->rect==NULL && ibuf->rect_float==NULL) return (ibuf);
+       if (ibuf == NULL) return(NULL);
+       if (ibuf->rect == NULL && ibuf->rect_float == NULL) return (ibuf);
 
        if (ibuf->rect) {
                do_rect = 1;
                _newrect = MEM_mallocN(ibuf->x * newy * sizeof(int), "scaleupy");
-               if (_newrect==NULL) return(ibuf);
+               if (_newrect == NULL) return(ibuf);
        }
        if (ibuf->rect_float) {
                do_float = 1;
                _newrectf = MEM_mallocN(ibuf->x * newy * sizeof(float) * 4, "scaleupyf");
-               if (_newrectf==NULL) {
+               if (_newrectf == NULL) {
                        if (_newrect) MEM_freeN(_newrect);
                        return(ibuf);
                }
@@ -1286,8 +1286,8 @@ static struct ImBuf *scaleupy(struct ImBuf *ibuf, int newy)
 
                sample = 0;
                if (do_rect) {
-                       rect = ((uchar *)ibuf->rect) + 4*(x-1);
-                       newrect = _newrect + 4*(x-1);
+                       rect = ((uchar *)ibuf->rect) + 4 * (x - 1);
+                       newrect = _newrect + 4 * (x - 1);
 
                        val_a = rect[0];
                        nval_a = rect[skipx];
@@ -1295,43 +1295,43 @@ static struct ImBuf *scaleupy(struct ImBuf *ibuf, int newy)
                        val_a += 0.5f;