From 6b3bf9e2a86c73fd78452fbdc05785a560a2be9e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 22 Apr 2019 09:10:05 +1000 Subject: Cleanup: style, use braces for avi --- source/blender/avi/intern/avi.c | 84 ++++++++++++++++++++++----------- source/blender/avi/intern/avi_codecs.c | 12 +++-- source/blender/avi/intern/avi_mjpeg.c | 27 +++++++---- source/blender/avi/intern/avi_options.c | 6 ++- source/blender/avi/intern/avi_rgb.c | 6 ++- 5 files changed, 90 insertions(+), 45 deletions(-) (limited to 'source/blender/avi') diff --git a/source/blender/avi/intern/avi.c b/source/blender/avi/intern/avi.c index 1f55f6ce557..22eb0be0cc0 100644 --- a/source/blender/avi/intern/avi.c +++ b/source/blender/avi/intern/avi.c @@ -107,15 +107,18 @@ int AVI_get_stream(AviMovie *movie, int avist_type, int stream_num) { int cur_stream; - if (movie == NULL) + if (movie == NULL) { return -AVI_ERROR_OPTION; + } for (cur_stream = 0; cur_stream < movie->header->Streams; cur_stream++) { if (movie->streams[cur_stream].sh.Type == avist_type) { - if (stream_num == 0) + if (stream_num == 0) { return cur_stream; - else + } + else { stream_num--; + } } } @@ -143,10 +146,12 @@ static bool fcc_is_data(int fcc) fccs[2] = fcc >> 16; fccs[3] = fcc >> 24; - if (!isdigit(fccs[0]) || !isdigit(fccs[1]) || (fccs[2] != 'd' && fccs[2] != 'w')) + if (!isdigit(fccs[0]) || !isdigit(fccs[1]) || (fccs[2] != 'd' && fccs[2] != 'w')) { return 0; - if (fccs[3] != 'b' && fccs[3] != 'c') + } + if (fccs[3] != 'b' && fccs[3] != 'c') { return 0; + } return 1; } @@ -155,10 +160,12 @@ AviError AVI_print_error(AviError in_error) { int error; - if ((int)in_error < 0) + if ((int)in_error < 0) { error = -in_error; - else + } + else { error = in_error; + } switch (error) { case AVI_ERROR_NONE: @@ -208,8 +215,9 @@ bool AVI_is_avi(const char *name) movie.fp = BLI_fopen(name, "rb"); movie.offset_table = NULL; - if (movie.fp == NULL) + if (movie.fp == NULL) { return 0; + } if (GET_FCC(movie.fp) != FCC("RIFF") || !(movie.size = GET_FCC(movie.fp))) { fclose(movie.fp); @@ -353,8 +361,9 @@ bool AVI_is_avi(const char *name) } } } - if (j > 0) + if (j > 0) { fseek(movie.fp, j, SEEK_CUR); + } } else { fseek(movie.fp, movie.streams[temp].sf_size, SEEK_CUR); @@ -395,8 +404,9 @@ AviError AVI_open_movie(const char *name, AviMovie *movie) movie->fp = BLI_fopen(name, "rb"); movie->offset_table = NULL; - if (movie->fp == NULL) + if (movie->fp == NULL) { return AVI_ERROR_OPEN; + } if (GET_FCC(movie->fp) != FCC("RIFF") || !(movie->size = GET_FCC(movie->fp))) { return AVI_ERROR_FORMAT; @@ -529,8 +539,9 @@ AviError AVI_open_movie(const char *name, AviMovie *movie) } } } - if (j > 0) + if (j > 0) { fseek(movie->fp, j, SEEK_CUR); + } } else { fseek(movie->fp, movie->streams[temp].sf_size, SEEK_CUR); @@ -553,14 +564,17 @@ AviError AVI_open_movie(const char *name, AviMovie *movie) temp = GET_FCC(movie->fp); size = GET_FCC(movie->fp); - if (size == 0) + if (size == 0) { break; + } if (temp == FCC("LIST")) { - if (GET_FCC(movie->fp) == FCC("movi")) + if (GET_FCC(movie->fp) == FCC("movi")) { break; - else + } + else { fseek(movie->fp, size - 4, SEEK_CUR); + } } else { fseek(movie->fp, size, SEEK_CUR); @@ -615,8 +629,9 @@ AviError AVI_open_movie(const char *name, AviMovie *movie) * Note the offset needs an extra 4 bytes for some * undetermined reason */ - if (movie->entries[0].Offset == movie->movi_offset) + if (movie->entries[0].Offset == movie->movi_offset) { movie->read_offset = 4; + } } DEBUG_PRINT("movie successfully opened\n"); @@ -650,8 +665,9 @@ void *AVI_read_frame(AviMovie *movie, AviFormat format, int frame, int stream) } } - if (cur_frame != frame) + if (cur_frame != frame) { return NULL; + } fseek(movie->fp, movie->read_offset + movie->entries[i - 1].Offset, SEEK_SET); @@ -684,10 +700,12 @@ AviError AVI_close(AviMovie *movie) MEM_freeN(movie->header); MEM_freeN(movie->streams); - if (movie->entries != NULL) + if (movie->entries != NULL) { MEM_freeN(movie->entries); - if (movie->offset_table != NULL) + } + if (movie->offset_table != NULL) { MEM_freeN(movie->offset_table); + } return AVI_ERROR_NONE; } @@ -707,13 +725,15 @@ AviError AVI_open_compress(char *name, AviMovie *movie, int streams, ...) movie->index_entries = 0; - if (movie->fp == NULL) + if (movie->fp == NULL) { return AVI_ERROR_OPEN; + } movie->offset_table = (int64_t *)MEM_mallocN((1 + streams * 2) * sizeof(int64_t), "offsettable"); - for (i = 0; i < 1 + streams * 2; i++) + for (i = 0; i < 1 + streams * 2; i++) { movie->offset_table[i] = -1L; + } movie->entries = NULL; @@ -852,8 +872,9 @@ AviError AVI_open_compress(char *name, AviMovie *movie, int streams, ...) awrite(movie, &chunk, 1, sizeof(AviChunk), movie->fp, AVI_CHUNK); - for (i = 0; i < chunk.size; i++) + for (i = 0; i < chunk.size; i++) { putc(0, movie->fp); + } } header_pos2 = ftell(movie->fp); @@ -885,8 +906,9 @@ AviError AVI_write_frame(AviMovie *movie, int frame_num, ...) AviFormat format; void *buffer; - if (frame_num < 0) + if (frame_num < 0) { return AVI_ERROR_OPTION; + } /* Allocate the new memory for the index entry */ @@ -930,8 +952,9 @@ AviError AVI_write_frame(AviMovie *movie, int frame_num, ...) chunk.fcc = avi_get_data_id(format, stream); chunk.size = size; - if (size % 4) + if (size % 4) { chunk.size += 4 - size % 4; + } awrite(movie, &chunk, 1, sizeof(AviChunk), movie->fp, AVI_CHUNK); @@ -947,8 +970,9 @@ AviError AVI_write_frame(AviMovie *movie, int frame_num, ...) awrite(movie, buffer, 1, size, movie->fp, AVI_RAW); MEM_freeN(buffer); - if (size % 4) + if (size % 4) { awrite(movie, &tbuf, 1, 4 - size % 4, movie->fp, AVI_RAW); + } /* Update the stream headers length field */ movie->streams[stream].sh.Length++; @@ -995,8 +1019,9 @@ AviError AVI_close_compress(AviMovie *movie) PUT_FCC("idx1", movie->fp); PUT_FCCN((movie->index_entries * (movie->header->Streams + 1) * 16), movie->fp); - for (temp = 0; temp < movie->index_entries * (movie->header->Streams + 1); temp++) + for (temp = 0; temp < movie->index_entries * (movie->header->Streams + 1); temp++) { awrite(movie, &movie->entries[temp], 1, sizeof(AviIndexEntry), movie->fp, AVI_INDEXE); + } temp = (int)ftell(movie->fp); @@ -1018,11 +1043,14 @@ AviError AVI_close_compress(AviMovie *movie) MEM_freeN(movie->header); - if (movie->entries != NULL) + if (movie->entries != NULL) { MEM_freeN(movie->entries); - if (movie->streams != NULL) + } + if (movie->streams != NULL) { MEM_freeN(movie->streams); - if (movie->offset_table != NULL) + } + if (movie->offset_table != NULL) { MEM_freeN(movie->offset_table); + } return AVI_ERROR_NONE; } diff --git a/source/blender/avi/intern/avi_codecs.c b/source/blender/avi/intern/avi_codecs.c index 705ca1e41e1..15f498ac653 100644 --- a/source/blender/avi/intern/avi_codecs.c +++ b/source/blender/avi/intern/avi_codecs.c @@ -33,8 +33,9 @@ void *avi_format_convert( AviMovie *movie, int stream, void *buffer, AviFormat from, AviFormat to, size_t *size) { - if (from == to) + if (from == to) { return buffer; + } if (from != AVI_FORMAT_RGB24 && to != AVI_FORMAT_RGB24) { return avi_format_convert( @@ -82,12 +83,15 @@ int avi_get_data_id(AviFormat format, int stream) { char fcc[5]; - if (avi_get_format_type(format) == FCC("vids")) + if (avi_get_format_type(format) == FCC("vids")) { sprintf(fcc, "%2.2ddc", stream); - else if (avi_get_format_type(format) == FCC("auds")) + } + else if (avi_get_format_type(format) == FCC("auds")) { sprintf(fcc, "%2.2ddc", stream); - else + } + else { return 0; + } return FCC(fcc); } diff --git a/source/blender/avi/intern/avi_mjpeg.c b/source/blender/avi/intern/avi_mjpeg.c index 28743619c04..d4c7378964e 100644 --- a/source/blender/avi/intern/avi_mjpeg.c +++ b/source/blender/avi/intern/avi_mjpeg.c @@ -47,8 +47,9 @@ static void add_huff_table(j_decompress_ptr dinfo, const UINT8 *bits, const UINT8 *val) { - if (*htblptr == NULL) + if (*htblptr == NULL) { *htblptr = jpeg_alloc_huff_table((j_common_ptr)dinfo); + } memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits)); memcpy((*htblptr)->huffval, val, sizeof((*htblptr)->huffval)); @@ -237,8 +238,9 @@ static int Decode_JPEG(unsigned char *inBuffer, } jpeg_finish_decompress(&dinfo); - if (dinfo.output_height >= height) + if (dinfo.output_height >= height) { return 0; + } inBuffer += numbytes; jpegmemsrcmgr_build(&dinfo, inBuffer, bufsize - numbytes); @@ -306,14 +308,16 @@ static void Compress_JPEG(int quality, marker[i++] = 'I'; marker[i++] = '1'; marker[i++] = 0; - while (i < 60) + while (i < 60) { marker[i++] = 32; + } jpeg_write_marker(&cinfo, JPEG_APP0, marker, 60); i = 0; - while (i < 60) + while (i < 60) { marker[i++] = 0; + } jpeg_write_marker(&cinfo, JPEG_COM, marker, 60); @@ -331,10 +335,12 @@ static void interlace(unsigned char *to, unsigned char *from, int width, int hei size_t i, rowstride = width * 3; for (i = 0; i < height; i++) { - if (i & 1) + if (i & 1) { memcpy(&to[i * rowstride], &from[(i / 2 + height / 2) * rowstride], rowstride); - else + } + else { memcpy(&to[i * rowstride], &from[(i / 2) * rowstride], rowstride); + } } } @@ -343,10 +349,12 @@ static void deinterlace(int odd, unsigned char *to, unsigned char *from, int wid size_t i, rowstride = width * 3; for (i = 0; i < height; i++) { - if ((i & 1) == odd) + if ((i & 1) == odd) { memcpy(&to[(i / 2 + height / 2) * rowstride], &from[i * rowstride], rowstride); - else + } + else { memcpy(&to[(i / 2) * rowstride], &from[i * rowstride], rowstride); + } } } @@ -507,8 +515,9 @@ static boolean jpegmemsrcmgr_fill_input_buffer(j_decompress_ptr dinfo) static void jpegmemsrcmgr_skip_input_data(j_decompress_ptr dinfo, long skipcnt) { - if (dinfo->src->bytes_in_buffer < skipcnt) + if (dinfo->src->bytes_in_buffer < skipcnt) { skipcnt = dinfo->src->bytes_in_buffer; + } dinfo->src->next_input_byte += skipcnt; dinfo->src->bytes_in_buffer -= skipcnt; diff --git a/source/blender/avi/intern/avi_options.c b/source/blender/avi/intern/avi_options.c index d491f3bb2d0..4f7e26c874c 100644 --- a/source/blender/avi/intern/avi_options.c +++ b/source/blender/avi/intern/avi_options.c @@ -43,8 +43,9 @@ AviError AVI_set_compress_option( (void)stream; /* unused */ if (movie->header->TotalFrames != - 0) /* Can't change params after we have already started writing frames */ + 0) { /* Can't change params after we have already started writing frames */ return AVI_ERROR_OPTION; + } switch (option_type) { case AVI_OPTION_TYPE_MAIN: @@ -112,8 +113,9 @@ AviError AVI_set_compress_option( case AVI_OPTION_FRAMERATE: useconds = (int)(1000000 / (*((double *)opt_data))); - if (useconds) + if (useconds) { movie->header->MicroSecPerFrame = useconds; + } for (i = 0; i < movie->header->Streams; i++) { if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { diff --git a/source/blender/avi/intern/avi_rgb.c b/source/blender/avi/intern/avi_rgb.c index 8d81b561403..d449556e79b 100644 --- a/source/blender/avi/intern/avi_rgb.c +++ b/source/blender/avi/intern/avi_rgb.c @@ -44,8 +44,9 @@ void *avi_converter_from_avi_rgb(AviMovie *movie, int stream, unsigned char *buf (void)size; /* unused */ bi = (AviBitmapInfoHeader *)movie->streams[stream].sf; - if (bi) + if (bi) { bits = bi->BitCount; + } if (bits == 16) { unsigned short *pxl; @@ -96,8 +97,9 @@ void *avi_converter_from_avi_rgb(AviMovie *movie, int stream, unsigned char *buf if (buf) { size_t rowstride = movie->header->Width * 3; - if ((bits != 16) && (movie->header->Width % 2)) + if ((bits != 16) && (movie->header->Width % 2)) { rowstride++; + } for (size_t y = 0; y < movie->header->Height; y++) { memcpy(&buf[y * movie->header->Width * 3], -- cgit v1.2.3