diff options
Diffstat (limited to 'source/blender/avi')
-rw-r--r-- | source/blender/avi/intern/avi.c | 689 | ||||
-rw-r--r-- | source/blender/avi/intern/avirgb.c | 84 | ||||
-rw-r--r-- | source/blender/avi/intern/codecs.c | 108 | ||||
-rw-r--r-- | source/blender/avi/intern/endian.c | 242 | ||||
-rw-r--r-- | source/blender/avi/intern/mjpeg.c | 246 | ||||
-rw-r--r-- | source/blender/avi/intern/options.c | 134 | ||||
-rw-r--r-- | source/blender/avi/intern/rgb32.c | 34 |
7 files changed, 779 insertions, 758 deletions
diff --git a/source/blender/avi/intern/avi.c b/source/blender/avi/intern/avi.c index 17c29e2a834..c4c4e65a7be 100644 --- a/source/blender/avi/intern/avi.c +++ b/source/blender/avi/intern/avi.c @@ -51,7 +51,7 @@ #include "endian.h" -static int AVI_DEBUG=0; +static int AVI_DEBUG = 0; static char DEBUG_FCC[4]; #define DEBUG_PRINT(x) if (AVI_DEBUG) { printf("AVI DEBUG: " x); } (void)0 @@ -64,7 +64,7 @@ char *tcc_to_char(unsigned int tcc); /* implemetation */ -unsigned int GET_FCC (FILE *fp) +unsigned int GET_FCC(FILE *fp) { unsigned char tmp[4]; @@ -73,10 +73,10 @@ unsigned int GET_FCC (FILE *fp) tmp[2] = getc(fp); tmp[3] = getc(fp); - return FCC (tmp); + return FCC(tmp); } -unsigned int GET_TCC (FILE *fp) +unsigned int GET_TCC(FILE *fp) { char tmp[5]; @@ -85,25 +85,25 @@ unsigned int GET_TCC (FILE *fp) tmp[2] = 0; tmp[3] = 0; - return FCC (tmp); + return FCC(tmp); } char *fcc_to_char(unsigned int fcc) { - DEBUG_FCC[0]= (fcc)&127; - DEBUG_FCC[1]= (fcc>>8)&127; - DEBUG_FCC[2]= (fcc>>16)&127; - DEBUG_FCC[3]= (fcc>>24)&127; + DEBUG_FCC[0] = (fcc) & 127; + DEBUG_FCC[1] = (fcc >> 8) & 127; + DEBUG_FCC[2] = (fcc >> 16) & 127; + DEBUG_FCC[3] = (fcc >> 24) & 127; return DEBUG_FCC; } char *tcc_to_char(unsigned int tcc) { - DEBUG_FCC[0]= (tcc)&127; - DEBUG_FCC[1]= (tcc>>8)&127; - DEBUG_FCC[2]= 0; - DEBUG_FCC[3]= 0; + DEBUG_FCC[0] = (tcc) & 127; + DEBUG_FCC[1] = (tcc >> 8) & 127; + DEBUG_FCC[2] = 0; + DEBUG_FCC[3] = 0; return DEBUG_FCC; } @@ -115,7 +115,7 @@ int AVI_get_stream(AviMovie *movie, int avist_type, int stream_num) if (movie == NULL) return -AVI_ERROR_OPTION; - for (cur_stream=0; cur_stream < movie->header->Streams; cur_stream++) { + for (cur_stream = 0; cur_stream < movie->header->Streams; cur_stream++) { if (movie->streams[cur_stream].sh.Type == avist_type) { if (stream_num == 0) return cur_stream; @@ -127,28 +127,28 @@ int AVI_get_stream(AviMovie *movie, int avist_type, int stream_num) return -AVI_ERROR_FOUND; } -static int fcc_get_stream (int fcc) +static int fcc_get_stream(int fcc) { char fccs[4]; fccs[0] = fcc; - fccs[1] = fcc>>8; - fccs[2] = fcc>>16; - fccs[3] = fcc>>24; + fccs[1] = fcc >> 8; + fccs[2] = fcc >> 16; + fccs[3] = fcc >> 24; - return 10*(fccs[0]-'0') + (fccs[1]-'0'); + return 10 * (fccs[0] - '0') + (fccs[1] - '0'); } -static int fcc_is_data (int fcc) +static int fcc_is_data(int fcc) { char fccs[4]; fccs[0] = fcc; - fccs[1] = fcc>>8; - fccs[2] = fcc>>16; - fccs[3] = fcc>>24; + fccs[1] = fcc >> 8; + fccs[2] = fcc >> 16; + fccs[3] = fcc >> 24; - if (!isdigit (fccs[0]) || !isdigit (fccs[1]) || (fccs[2] != 'd' && fccs[2] != 'w')) + if (!isdigit(fccs[0]) || !isdigit(fccs[1]) || (fccs[2] != 'd' && fccs[2] != 'w')) return 0; if (fccs[3] != 'b' && fccs[3] != 'c') return 0; @@ -166,34 +166,34 @@ AviError AVI_print_error(AviError in_error) error = in_error; switch (error) { - case AVI_ERROR_NONE: - break; - case AVI_ERROR_COMPRESSION: - printf ("AVI ERROR: compressed in an unsupported format\n"); - break; - case AVI_ERROR_OPEN: - printf ("AVI ERROR: could not open file\n"); - break; - case AVI_ERROR_READING: - printf ("AVI ERROR: could not read from file\n"); - break; - case AVI_ERROR_WRITING: - printf ("AVI ERROR: could not write to file\n"); - break; - case AVI_ERROR_FORMAT: - printf ("AVI ERROR: file is in an illegal or unrecognized format\n"); - break; - case AVI_ERROR_ALLOC: - printf ("AVI ERROR: error encountered while allocating memory\n"); - break; - case AVI_ERROR_OPTION: - printf ("AVI ERROR: program made illegal request\n"); - break; - case AVI_ERROR_FOUND: - printf ("AVI ERROR: movie did not contain expected item\n"); - break; - default: - break; + case AVI_ERROR_NONE: + break; + case AVI_ERROR_COMPRESSION: + printf("AVI ERROR: compressed in an unsupported format\n"); + break; + case AVI_ERROR_OPEN: + printf("AVI ERROR: could not open file\n"); + break; + case AVI_ERROR_READING: + printf("AVI ERROR: could not read from file\n"); + break; + case AVI_ERROR_WRITING: + printf("AVI ERROR: could not write to file\n"); + break; + case AVI_ERROR_FORMAT: + printf("AVI ERROR: file is in an illegal or unrecognized format\n"); + break; + case AVI_ERROR_ALLOC: + printf("AVI ERROR: error encountered while allocating memory\n"); + break; + case AVI_ERROR_OPTION: + printf("AVI ERROR: program made illegal request\n"); + break; + case AVI_ERROR_FOUND: + printf("AVI ERROR: movie did not contain expected item\n"); + break; + default: + break; } return in_error; @@ -201,7 +201,7 @@ AviError AVI_print_error(AviError in_error) #if 0 void AVI_set_debug(int mode) { - AVI_DEBUG= mode; + AVI_DEBUG = mode; } int AVI_is_avi(char *name) @@ -209,13 +209,13 @@ int AVI_is_avi(char *name) FILE *fp; int ret; - fp = fopen (name, "rb"); + fp = fopen(name, "rb"); if (fp == NULL) return 0; - if (GET_FCC (fp) != FCC("RIFF") || - !GET_FCC (fp) || - GET_FCC (fp) != FCC("AVI ")) { + if (GET_FCC(fp) != FCC("RIFF") || + !GET_FCC(fp) || + GET_FCC(fp) != FCC("AVI ")) { ret = 0; } else { @@ -230,7 +230,7 @@ int AVI_is_avi(char *name) int AVI_is_avi(const char *name) { int temp, fcca, j; - AviMovie movie= {NULL}; + AviMovie movie = {NULL}; AviMainHeader header; AviBitmapInfoHeader bheader; int movie_tracks = 0; @@ -238,26 +238,26 @@ int AVI_is_avi(const char *name) DEBUG_PRINT("opening movie\n"); movie.type = AVI_MOVIE_READ; - movie.fp = fopen (name, "rb"); + movie.fp = fopen(name, "rb"); movie.offset_table = NULL; if (movie.fp == NULL) return 0; - if (GET_FCC (movie.fp) != FCC("RIFF") || - !(movie.size = GET_FCC (movie.fp))) { + if (GET_FCC(movie.fp) != FCC("RIFF") || + !(movie.size = GET_FCC(movie.fp))) { fclose(movie.fp); return 0; } movie.header = &header; - if (GET_FCC (movie.fp) != FCC("AVI ") || - GET_FCC (movie.fp) != FCC("LIST") || - !GET_FCC (movie.fp) || - GET_FCC (movie.fp) != FCC("hdrl") || - (movie.header->fcc = GET_FCC (movie.fp)) != FCC("avih") || - !(movie.header->size = GET_FCC (movie.fp))) { + if (GET_FCC(movie.fp) != FCC("AVI ") || + GET_FCC(movie.fp) != FCC("LIST") || + !GET_FCC(movie.fp) || + GET_FCC(movie.fp) != FCC("hdrl") || + (movie.header->fcc = GET_FCC(movie.fp)) != FCC("avih") || + !(movie.header->size = GET_FCC(movie.fp))) { DEBUG_PRINT("bad initial header info\n"); fclose(movie.fp); return 0; @@ -278,7 +278,7 @@ int AVI_is_avi(const char *name) movie.header->Reserved[2] = GET_FCC(movie.fp); movie.header->Reserved[3] = GET_FCC(movie.fp); - fseek (movie.fp, movie.header->size-14*4, SEEK_CUR); + fseek(movie.fp, movie.header->size - 14 * 4, SEEK_CUR); if (movie.header->Streams < 1) { DEBUG_PRINT("streams less than 1\n"); @@ -286,15 +286,16 @@ int AVI_is_avi(const char *name) return 0; } - movie.streams = (AviStreamRec *) MEM_callocN (sizeof(AviStreamRec) * movie.header->Streams, "moviestreams"); + movie.streams = (AviStreamRec *) MEM_callocN(sizeof(AviStreamRec) * movie.header->Streams, "moviestreams"); - for (temp=0; temp < movie.header->Streams; temp++) { + for (temp = 0; temp < movie.header->Streams; temp++) { if (GET_FCC(movie.fp) != FCC("LIST") || - !GET_FCC (movie.fp) || - GET_FCC (movie.fp) != FCC ("strl") || - (movie.streams[temp].sh.fcc = GET_FCC (movie.fp)) != FCC ("strh") || - !(movie.streams[temp].sh.size = GET_FCC (movie.fp))) { + !GET_FCC(movie.fp) || + GET_FCC(movie.fp) != FCC("strl") || + (movie.streams[temp].sh.fcc = GET_FCC(movie.fp)) != FCC("strh") || + !(movie.streams[temp].sh.size = GET_FCC(movie.fp))) + { DEBUG_PRINT("bad stream header information\n"); MEM_freeN(movie.streams); @@ -302,20 +303,21 @@ int AVI_is_avi(const char *name) return 0; } - movie.streams[temp].sh.Type = GET_FCC (movie.fp); - movie.streams[temp].sh.Handler = GET_FCC (movie.fp); + movie.streams[temp].sh.Type = GET_FCC(movie.fp); + movie.streams[temp].sh.Handler = GET_FCC(movie.fp); fcca = movie.streams[temp].sh.Handler; if (movie.streams[temp].sh.Type == FCC("vids")) { - if (fcca == FCC ("DIB ") || - fcca == FCC ("RGB ") || - fcca == FCC ("rgb ") || - fcca == FCC ("RAW ") || - fcca == 0) { + if (fcca == FCC("DIB ") || + fcca == FCC("RGB ") || + fcca == FCC("rgb ") || + fcca == FCC("RAW ") || + fcca == 0) + { movie.streams[temp].format = AVI_FORMAT_AVI_RGB; } - else if (fcca == FCC ("mjpg")||fcca == FCC ("MJPG")) { + else if (fcca == FCC("mjpg") || fcca == FCC("MJPG")) { movie.streams[temp].format = AVI_FORMAT_MJPEG; } else { @@ -326,67 +328,70 @@ int AVI_is_avi(const char *name) movie_tracks++; } - movie.streams[temp].sh.Flags = GET_FCC (movie.fp); - movie.streams[temp].sh.Priority = GET_TCC (movie.fp); - movie.streams[temp].sh.Language = GET_TCC (movie.fp); - movie.streams[temp].sh.InitialFrames = GET_FCC (movie.fp); - movie.streams[temp].sh.Scale = GET_FCC (movie.fp); - movie.streams[temp].sh.Rate = GET_FCC (movie.fp); - movie.streams[temp].sh.Start = GET_FCC (movie.fp); - movie.streams[temp].sh.Length = GET_FCC (movie.fp); - movie.streams[temp].sh.SuggestedBufferSize = GET_FCC (movie.fp); - movie.streams[temp].sh.Quality = GET_FCC (movie.fp); - movie.streams[temp].sh.SampleSize = GET_FCC (movie.fp); - movie.streams[temp].sh.left = GET_TCC (movie.fp); - movie.streams[temp].sh.top = GET_TCC (movie.fp); - movie.streams[temp].sh.right = GET_TCC (movie.fp); - movie.streams[temp].sh.bottom = GET_TCC (movie.fp); - - fseek (movie.fp, movie.streams[temp].sh.size-14*4, SEEK_CUR); - - if (GET_FCC (movie.fp) != FCC("strf")) { + movie.streams[temp].sh.Flags = GET_FCC(movie.fp); + movie.streams[temp].sh.Priority = GET_TCC(movie.fp); + movie.streams[temp].sh.Language = GET_TCC(movie.fp); + movie.streams[temp].sh.InitialFrames = GET_FCC(movie.fp); + movie.streams[temp].sh.Scale = GET_FCC(movie.fp); + movie.streams[temp].sh.Rate = GET_FCC(movie.fp); + movie.streams[temp].sh.Start = GET_FCC(movie.fp); + movie.streams[temp].sh.Length = GET_FCC(movie.fp); + movie.streams[temp].sh.SuggestedBufferSize = GET_FCC(movie.fp); + movie.streams[temp].sh.Quality = GET_FCC(movie.fp); + movie.streams[temp].sh.SampleSize = GET_FCC(movie.fp); + movie.streams[temp].sh.left = GET_TCC(movie.fp); + movie.streams[temp].sh.top = GET_TCC(movie.fp); + movie.streams[temp].sh.right = GET_TCC(movie.fp); + movie.streams[temp].sh.bottom = GET_TCC(movie.fp); + + fseek(movie.fp, movie.streams[temp].sh.size - 14 * 4, SEEK_CUR); + + if (GET_FCC(movie.fp) != FCC("strf")) { DEBUG_PRINT("no stream format information\n"); MEM_freeN(movie.streams); fclose(movie.fp); return 0; } - movie.streams[temp].sf_size= GET_FCC(movie.fp); + movie.streams[temp].sf_size = GET_FCC(movie.fp); if (movie.streams[temp].sh.Type == FCC("vids")) { j = movie.streams[temp].sf_size - (sizeof(AviBitmapInfoHeader) - 8); if (j >= 0) { AviBitmapInfoHeader *bi; - movie.streams[temp].sf= &bheader; - bi= (AviBitmapInfoHeader *) movie.streams[temp].sf; + movie.streams[temp].sf = &bheader; + bi = (AviBitmapInfoHeader *) movie.streams[temp].sf; - bi->fcc= FCC("strf"); - bi->size= movie.streams[temp].sf_size; - bi->Size= GET_FCC(movie.fp); - bi->Width= GET_FCC(movie.fp); - bi->Height= GET_FCC(movie.fp); - bi->Planes= GET_TCC(movie.fp); - bi->BitCount= GET_TCC(movie.fp); - bi->Compression= GET_FCC(movie.fp); - bi->SizeImage= GET_FCC(movie.fp); - bi->XPelsPerMeter= GET_FCC(movie.fp); - bi->YPelsPerMeter= GET_FCC(movie.fp); - bi->ClrUsed= GET_FCC(movie.fp); - bi->ClrImportant= GET_FCC(movie.fp); + bi->fcc = FCC("strf"); + bi->size = movie.streams[temp].sf_size; + bi->Size = GET_FCC(movie.fp); + bi->Width = GET_FCC(movie.fp); + bi->Height = GET_FCC(movie.fp); + bi->Planes = GET_TCC(movie.fp); + bi->BitCount = GET_TCC(movie.fp); + bi->Compression = GET_FCC(movie.fp); + bi->SizeImage = GET_FCC(movie.fp); + bi->XPelsPerMeter = GET_FCC(movie.fp); + bi->YPelsPerMeter = GET_FCC(movie.fp); + bi->ClrUsed = GET_FCC(movie.fp); + bi->ClrImportant = GET_FCC(movie.fp); fcca = bi->Compression; - if ( movie.streams[temp].format == - AVI_FORMAT_AVI_RGB) { - if (fcca == FCC ("DIB ") || - fcca == FCC ("RGB ") || - fcca == FCC ("rgb ") || - fcca == FCC ("RAW ") || - fcca == 0 ) { + if (movie.streams[temp].format == + AVI_FORMAT_AVI_RGB) { + if (fcca == FCC("DIB ") || + fcca == FCC("RGB ") || + fcca == FCC("rgb ") || + fcca == FCC("RAW ") || + fcca == 0) + { + /* pass */ } - else if ( fcca == FCC ("mjpg") || - fcca == FCC ("MJPG")) { - movie.streams[temp].format = AVI_FORMAT_MJPEG; + else if (fcca == FCC("mjpg") || + fcca == FCC("MJPG")) + { + movie.streams[temp].format = AVI_FORMAT_MJPEG; } else { MEM_freeN(movie.streams); @@ -396,14 +401,14 @@ int AVI_is_avi(const char *name) } } - if (j > 0) fseek (movie.fp, j, SEEK_CUR); + if (j > 0) fseek(movie.fp, j, SEEK_CUR); } - else fseek (movie.fp, movie.streams[temp].sf_size, SEEK_CUR); + else fseek(movie.fp, movie.streams[temp].sf_size, SEEK_CUR); /* Walk to the next LIST */ - while (GET_FCC (movie.fp) != FCC("LIST")) { - temp= GET_FCC (movie.fp); - if (temp<0 || ftell(movie.fp) > movie.size) { + while (GET_FCC(movie.fp) != FCC("LIST")) { + temp = GET_FCC(movie.fp); + if (temp < 0 || ftell(movie.fp) > movie.size) { DEBUG_PRINT("incorrect size in header or error in AVI\n"); MEM_freeN(movie.streams); @@ -433,26 +438,27 @@ AviError AVI_open_movie(const char *name, AviMovie *movie) memset(movie, 0, sizeof(AviMovie)); movie->type = AVI_MOVIE_READ; - movie->fp = fopen (name, "rb"); + movie->fp = fopen(name, "rb"); movie->offset_table = NULL; if (movie->fp == NULL) return AVI_ERROR_OPEN; - if (GET_FCC (movie->fp) != FCC("RIFF") || - !(movie->size = GET_FCC (movie->fp))) + if (GET_FCC(movie->fp) != FCC("RIFF") || + !(movie->size = GET_FCC(movie->fp))) { return AVI_ERROR_FORMAT; } - movie->header = (AviMainHeader *) MEM_mallocN (sizeof (AviMainHeader), "movieheader"); + movie->header = (AviMainHeader *) MEM_mallocN(sizeof (AviMainHeader), "movieheader"); - if (GET_FCC (movie->fp) != FCC("AVI ") || - GET_FCC (movie->fp) != FCC("LIST") || - !GET_FCC (movie->fp) || - GET_FCC (movie->fp) != FCC("hdrl") || - (movie->header->fcc = GET_FCC (movie->fp)) != FCC("avih") || - !(movie->header->size = GET_FCC (movie->fp))) { + if (GET_FCC(movie->fp) != FCC("AVI ") || + GET_FCC(movie->fp) != FCC("LIST") || + !GET_FCC(movie->fp) || + GET_FCC(movie->fp) != FCC("hdrl") || + (movie->header->fcc = GET_FCC(movie->fp)) != FCC("avih") || + !(movie->header->size = GET_FCC(movie->fp))) + { DEBUG_PRINT("bad initial header info\n"); return AVI_ERROR_FORMAT; } @@ -472,40 +478,42 @@ AviError AVI_open_movie(const char *name, AviMovie *movie) movie->header->Reserved[2] = GET_FCC(movie->fp); movie->header->Reserved[3] = GET_FCC(movie->fp); - fseek (movie->fp, movie->header->size-14*4, SEEK_CUR); + fseek(movie->fp, movie->header->size - 14 * 4, SEEK_CUR); if (movie->header->Streams < 1) { DEBUG_PRINT("streams less than 1\n"); return AVI_ERROR_FORMAT; } - movie->streams = (AviStreamRec *) MEM_callocN (sizeof(AviStreamRec) * movie->header->Streams, "moviestreams"); + movie->streams = (AviStreamRec *) MEM_callocN(sizeof(AviStreamRec) * movie->header->Streams, "moviestreams"); - for (temp=0; temp < movie->header->Streams; temp++) { + for (temp = 0; temp < movie->header->Streams; temp++) { if (GET_FCC(movie->fp) != FCC("LIST") || - !GET_FCC (movie->fp) || - GET_FCC (movie->fp) != FCC ("strl") || - (movie->streams[temp].sh.fcc = GET_FCC (movie->fp)) != FCC ("strh") || - !(movie->streams[temp].sh.size = GET_FCC (movie->fp))) { + !GET_FCC(movie->fp) || + GET_FCC(movie->fp) != FCC("strl") || + (movie->streams[temp].sh.fcc = GET_FCC(movie->fp)) != FCC("strh") || + !(movie->streams[temp].sh.size = GET_FCC(movie->fp))) + { DEBUG_PRINT("bad stream header information\n"); - return AVI_ERROR_FORMAT; + return AVI_ERROR_FORMAT; } - movie->streams[temp].sh.Type = GET_FCC (movie->fp); - movie->streams[temp].sh.Handler = GET_FCC (movie->fp); + movie->streams[temp].sh.Type = GET_FCC(movie->fp); + movie->streams[temp].sh.Handler = GET_FCC(movie->fp); fcca = movie->streams[temp].sh.Handler; if (movie->streams[temp].sh.Type == FCC("vids")) { - if (fcca == FCC ("DIB ") || - fcca == FCC ("RGB ") || - fcca == FCC ("rgb ") || - fcca == FCC ("RAW ") || - fcca == 0) { + if (fcca == FCC("DIB ") || + fcca == FCC("RGB ") || + fcca == FCC("rgb ") || + fcca == FCC("RAW ") || + fcca == 0) + { movie->streams[temp].format = AVI_FORMAT_AVI_RGB; } - else if (fcca == FCC ("mjpg")||fcca == FCC ("MJPG")) { + else if (fcca == FCC("mjpg") || fcca == FCC("MJPG")) { movie->streams[temp].format = AVI_FORMAT_MJPEG; } else { @@ -513,66 +521,70 @@ AviError AVI_open_movie(const char *name, AviMovie *movie) } } - movie->streams[temp].sh.Flags = GET_FCC (movie->fp); - movie->streams[temp].sh.Priority = GET_TCC (movie->fp); - movie->streams[temp].sh.Language = GET_TCC (movie->fp); - movie->streams[temp].sh.InitialFrames = GET_FCC (movie->fp); - movie->streams[temp].sh.Scale = GET_FCC (movie->fp); - movie->streams[temp].sh.Rate = GET_FCC (movie->fp); - movie->streams[temp].sh.Start = GET_FCC (movie->fp); - movie->streams[temp].sh.Length = GET_FCC (movie->fp); - movie->streams[temp].sh.SuggestedBufferSize = GET_FCC (movie->fp); - movie->streams[temp].sh.Quality = GET_FCC (movie->fp); - movie->streams[temp].sh.SampleSize = GET_FCC (movie->fp); - movie->streams[temp].sh.left = GET_TCC (movie->fp); - movie->streams[temp].sh.top = GET_TCC (movie->fp); - movie->streams[temp].sh.right = GET_TCC (movie->fp); - movie->streams[temp].sh.bottom = GET_TCC (movie->fp); - - fseek (movie->fp, movie->streams[temp].sh.size-14*4, SEEK_CUR); - - if (GET_FCC (movie->fp) != FCC("strf")) { + movie->streams[temp].sh.Flags = GET_FCC(movie->fp); + movie->streams[temp].sh.Priority = GET_TCC(movie->fp); + movie->streams[temp].sh.Language = GET_TCC(movie->fp); + movie->streams[temp].sh.InitialFrames = GET_FCC(movie->fp); + movie->streams[temp].sh.Scale = GET_FCC(movie->fp); + movie->streams[temp].sh.Rate = GET_FCC(movie->fp); + movie->streams[temp].sh.Start = GET_FCC(movie->fp); + movie->streams[temp].sh.Length = GET_FCC(movie->fp); + movie->streams[temp].sh.SuggestedBufferSize = GET_FCC(movie->fp); + movie->streams[temp].sh.Quality = GET_FCC(movie->fp); + movie->streams[temp].sh.SampleSize = GET_FCC(movie->fp); + movie->streams[temp].sh.left = GET_TCC(movie->fp); + movie->streams[temp].sh.top = GET_TCC(movie->fp); + movie->streams[temp].sh.right = GET_TCC(movie->fp); + movie->streams[temp].sh.bottom = GET_TCC(movie->fp); + + fseek(movie->fp, movie->streams[temp].sh.size - 14 * 4, SEEK_CUR); + + if (GET_FCC(movie->fp) != FCC("strf")) { DEBUG_PRINT("no stream format information\n"); return AVI_ERROR_FORMAT; } - movie->streams[temp].sf_size= GET_FCC(movie->fp); + movie->streams[temp].sf_size = GET_FCC(movie->fp); if (movie->streams[temp].sh.Type == FCC("vids")) { j = movie->streams[temp].sf_size - (sizeof(AviBitmapInfoHeader) - 8); if (j >= 0) { AviBitmapInfoHeader *bi; - movie->streams[temp].sf= MEM_mallocN(sizeof(AviBitmapInfoHeader), "streamformat"); + movie->streams[temp].sf = MEM_mallocN(sizeof(AviBitmapInfoHeader), "streamformat"); - bi= (AviBitmapInfoHeader *) movie->streams[temp].sf; + bi = (AviBitmapInfoHeader *) movie->streams[temp].sf; - bi->fcc= FCC("strf"); - bi->size= movie->streams[temp].sf_size; - bi->Size= GET_FCC(movie->fp); - bi->Width= GET_FCC(movie->fp); - bi->Height= GET_FCC(movie->fp); - bi->Planes= GET_TCC(movie->fp); - bi->BitCount= GET_TCC(movie->fp); - bi->Compression= GET_FCC(movie->fp); - bi->SizeImage= GET_FCC(movie->fp); - bi->XPelsPerMeter= GET_FCC(movie->fp); - bi->YPelsPerMeter= GET_FCC(movie->fp); - bi->ClrUsed= GET_FCC(movie->fp); - bi->ClrImportant= GET_FCC(movie->fp); + bi->fcc = FCC("strf"); + bi->size = movie->streams[temp].sf_size; + bi->Size = GET_FCC(movie->fp); + bi->Width = GET_FCC(movie->fp); + bi->Height = GET_FCC(movie->fp); + bi->Planes = GET_TCC(movie->fp); + bi->BitCount = GET_TCC(movie->fp); + bi->Compression = GET_FCC(movie->fp); + bi->SizeImage = GET_FCC(movie->fp); + bi->XPelsPerMeter = GET_FCC(movie->fp); + bi->YPelsPerMeter = GET_FCC(movie->fp); + bi->ClrUsed = GET_FCC(movie->fp); + bi->ClrImportant = GET_FCC(movie->fp); fcca = bi->Compression; - if ( movie->streams[temp].format == - AVI_FORMAT_AVI_RGB) { - if (fcca == FCC ("DIB ") || - fcca == FCC ("RGB ") || - fcca == FCC ("rgb ") || - fcca == FCC ("RAW ") || - fcca == 0 ) { + if (movie->streams[temp].format == + AVI_FORMAT_AVI_RGB) + { + if (fcca == FCC("DIB ") || + fcca == FCC("RGB ") || + fcca == FCC("rgb ") || + fcca == FCC("RAW ") || + fcca == 0) + { + /* pass */ } - else if ( fcca == FCC ("mjpg") || - fcca == FCC ("MJPG")) { - movie->streams[temp].format = AVI_FORMAT_MJPEG; + else if (fcca == FCC("mjpg") || + fcca == FCC("MJPG")) + { + movie->streams[temp].format = AVI_FORMAT_MJPEG; } else { return AVI_ERROR_COMPRESSION; @@ -580,38 +592,38 @@ AviError AVI_open_movie(const char *name, AviMovie *movie) } } - if (j > 0) fseek (movie->fp, j, SEEK_CUR); + if (j > 0) fseek(movie->fp, j, SEEK_CUR); } - else fseek (movie->fp, movie->streams[temp].sf_size, SEEK_CUR); + else fseek(movie->fp, movie->streams[temp].sf_size, SEEK_CUR); /* Walk to the next LIST */ - while (GET_FCC (movie->fp) != FCC("LIST")) { - temp= GET_FCC (movie->fp); - if (temp<0 || ftell(movie->fp) > movie->size) { + while (GET_FCC(movie->fp) != FCC("LIST")) { + temp = GET_FCC(movie->fp); + if (temp < 0 || ftell(movie->fp) > movie->size) { DEBUG_PRINT("incorrect size in header or error in AVI\n"); - return AVI_ERROR_FORMAT; + return AVI_ERROR_FORMAT; } - fseek(movie->fp, temp, SEEK_CUR); + fseek(movie->fp, temp, SEEK_CUR); } - fseek(movie->fp, -4L, SEEK_CUR); + fseek(movie->fp, -4L, SEEK_CUR); } while (1) { - temp = GET_FCC (movie->fp); - size = GET_FCC (movie->fp); + temp = GET_FCC(movie->fp); + size = GET_FCC(movie->fp); if (size == 0) break; if (temp == FCC("LIST")) { - if (GET_FCC(movie->fp) == FCC ("movi")) + if (GET_FCC(movie->fp) == FCC("movi")) break; else - fseek (movie->fp, size-4, SEEK_CUR); + fseek(movie->fp, size - 4, SEEK_CUR); } else { - fseek (movie->fp, size, SEEK_CUR); + fseek(movie->fp, size, SEEK_CUR); } if (ftell(movie->fp) > movie->size) { DEBUG_PRINT("incorrect size in header or error in AVI\n"); @@ -619,31 +631,31 @@ AviError AVI_open_movie(const char *name, AviMovie *movie) } } - movie->movi_offset = ftell (movie->fp); + movie->movi_offset = ftell(movie->fp); movie->read_offset = movie->movi_offset; /* Read in the index if the file has one, otherwise create one */ if (movie->header->Flags & AVIF_HASINDEX) { - fseek(movie->fp, size-4, SEEK_CUR); + fseek(movie->fp, size - 4, SEEK_CUR); if (GET_FCC(movie->fp) != FCC("idx1")) { DEBUG_PRINT("bad index informatio\n"); return AVI_ERROR_FORMAT; } - movie->index_entries = GET_FCC (movie->fp)/sizeof(AviIndexEntry); + movie->index_entries = GET_FCC(movie->fp) / sizeof(AviIndexEntry); if (movie->index_entries == 0) { DEBUG_PRINT("no index entries\n"); return AVI_ERROR_FORMAT; } - movie->entries = (AviIndexEntry *) MEM_mallocN (movie->index_entries * sizeof(AviIndexEntry), "movieentries"); + movie->entries = (AviIndexEntry *) MEM_mallocN(movie->index_entries * sizeof(AviIndexEntry), "movieentries"); - for (temp=0; temp < movie->index_entries; temp++) { - movie->entries[temp].ChunkId = GET_FCC (movie->fp); - movie->entries[temp].Flags = GET_FCC (movie->fp); - movie->entries[temp].Offset = GET_FCC (movie->fp); - movie->entries[temp].Size = GET_FCC (movie->fp); + for (temp = 0; temp < movie->index_entries; temp++) { + movie->entries[temp].ChunkId = GET_FCC(movie->fp); + movie->entries[temp].Flags = GET_FCC(movie->fp); + movie->entries[temp].Offset = GET_FCC(movie->fp); + movie->entries[temp].Size = GET_FCC(movie->fp); if (AVI_DEBUG) { printf("Index entry %04d: ChunkId:%s Flags:%d Offset:%d Size:%d\n", @@ -660,31 +672,32 @@ AviError AVI_open_movie(const char *name, AviMovie *movie) * undetermined reason */ if (movie->entries[0].Offset == movie->movi_offset) - movie->read_offset= 4; + movie->read_offset = 4; } DEBUG_PRINT("movie succesfully opened\n"); return AVI_ERROR_NONE; } -void *AVI_read_frame (AviMovie *movie, AviFormat format, int frame, int stream) +void *AVI_read_frame(AviMovie *movie, AviFormat format, int frame, int stream) { - int cur_frame=-1, temp, i=0, rewind=1; + int cur_frame = -1, temp, i = 0, rewind = 1; void *buffer; /* Retrieve the record number of the desired frame in the index * If a chunk has Size 0 we need to rewind to previous frame */ while (rewind && frame > -1) { - i=0; - cur_frame=-1; + i = 0; + cur_frame = -1; rewind = 0; while (cur_frame < frame && i < movie->index_entries) { - if (fcc_is_data (movie->entries[i].ChunkId) && - fcc_get_stream (movie->entries[i].ChunkId) == stream) { - if ((cur_frame == frame -1) && (movie->entries[i].Size == 0)) { + if (fcc_is_data(movie->entries[i].ChunkId) && + fcc_get_stream(movie->entries[i].ChunkId) == stream) + { + if ((cur_frame == frame - 1) && (movie->entries[i].Size == 0)) { rewind = 1; - frame = frame -1; + frame = frame - 1; } else { cur_frame++; @@ -697,18 +710,18 @@ void *AVI_read_frame (AviMovie *movie, AviFormat format, int frame, int stream) if (cur_frame != frame) return NULL; - fseek (movie->fp, movie->read_offset + movie->entries[i-1].Offset, SEEK_SET); + fseek(movie->fp, movie->read_offset + movie->entries[i - 1].Offset, SEEK_SET); temp = GET_FCC(movie->fp); - buffer = MEM_mallocN (temp, "readbuffer"); + buffer = MEM_mallocN(temp, "readbuffer"); - if (fread (buffer, 1, temp, movie->fp) != temp) { + if (fread(buffer, 1, temp, movie->fp) != temp) { MEM_freeN(buffer); return NULL; } - buffer = avi_format_convert (movie, stream, buffer, movie->streams[stream].format, format, &temp); + buffer = avi_format_convert(movie, stream, buffer, movie->streams[stream].format, format, &temp); return buffer; } @@ -717,21 +730,21 @@ AviError AVI_close(AviMovie *movie) { int i; - fclose (movie->fp); + fclose(movie->fp); - for (i=0; i < movie->header->Streams; i++) { + for (i = 0; i < movie->header->Streams; i++) { if (movie->streams[i].sf != NULL) - MEM_freeN (movie->streams[i].sf); + MEM_freeN(movie->streams[i].sf); } if (movie->header != NULL) - MEM_freeN (movie->header); - if (movie->streams!= NULL) - MEM_freeN (movie->streams); + MEM_freeN(movie->header); + if (movie->streams != NULL) + MEM_freeN(movie->streams); if (movie->entries != NULL) - MEM_freeN (movie->entries); + MEM_freeN(movie->entries); if (movie->offset_table != NULL) - MEM_freeN (movie->offset_table); + MEM_freeN(movie->offset_table); return AVI_ERROR_NONE; } @@ -747,21 +760,21 @@ AviError AVI_open_compress(char *name, AviMovie *movie, int streams, ...) int64_t junk_pos; movie->type = AVI_MOVIE_WRITE; - movie->fp = fopen (name, "wb"); + movie->fp = fopen(name, "wb"); movie->index_entries = 0; if (movie->fp == NULL) return AVI_ERROR_OPEN; - movie->offset_table = (int64_t *) MEM_mallocN ((1+streams*2) * sizeof (int64_t), "offsettable"); + movie->offset_table = (int64_t *) MEM_mallocN((1 + streams * 2) * sizeof (int64_t), "offsettable"); - for (i=0; i < 1 + streams*2; i++) + for (i = 0; i < 1 + streams * 2; i++) movie->offset_table[i] = -1L; movie->entries = NULL; - movie->header = (AviMainHeader *) MEM_mallocN (sizeof(AviMainHeader), "movieheader"); + movie->header = (AviMainHeader *) MEM_mallocN(sizeof(AviMainHeader), "movieheader"); movie->header->fcc = FCC("avih"); movie->header->size = 56; @@ -780,20 +793,20 @@ AviError AVI_open_compress(char *name, AviMovie *movie, int streams, ...) movie->header->Reserved[2] = 0; movie->header->Reserved[3] = 0; - movie->streams = (AviStreamRec *) MEM_mallocN (sizeof(AviStreamRec) * movie->header->Streams, "moviestreams"); + movie->streams = (AviStreamRec *) MEM_mallocN(sizeof(AviStreamRec) * movie->header->Streams, "moviestreams"); - va_start (ap, streams); + va_start(ap, streams); - for (i=0; i < movie->header->Streams; i++) { + for (i = 0; i < movie->header->Streams; i++) { movie->streams[i].format = va_arg(ap, AviFormat); - movie->streams[i].sh.fcc = FCC ("strh"); + movie->streams[i].sh.fcc = FCC("strh"); movie->streams[i].sh.size = 56; - movie->streams[i].sh.Type = avi_get_format_type (movie->streams[i].format); + movie->streams[i].sh.Type = avi_get_format_type(movie->streams[i].format); if (movie->streams[i].sh.Type == 0) return AVI_ERROR_FORMAT; - movie->streams[i].sh.Handler = avi_get_format_fcc (movie->streams[i].format); + movie->streams[i].sh.Handler = avi_get_format_fcc(movie->streams[i].format); if (movie->streams[i].sh.Handler == 0) return AVI_ERROR_FORMAT; @@ -816,30 +829,30 @@ AviError AVI_open_compress(char *name, AviMovie *movie, int streams, ...) if (movie->streams[i].sh.Type == FCC("vids")) { #if 0 if (movie->streams[i].format == AVI_FORMAT_MJPEG) { - movie->streams[i].sf = MEM_mallocN (sizeof(AviBitmapInfoHeader) - + sizeof(AviMJPEGUnknown), "moviestreamformatL"); + movie->streams[i].sf = MEM_mallocN(sizeof(AviBitmapInfoHeader) + + sizeof(AviMJPEGUnknown), "moviestreamformatL"); movie->streams[i].sf_size = sizeof(AviBitmapInfoHeader) + sizeof(AviMJPEGUnknown); } else { #endif - movie->streams[i].sf = MEM_mallocN (sizeof(AviBitmapInfoHeader), "moviestreamformatS"); + movie->streams[i].sf = MEM_mallocN(sizeof(AviBitmapInfoHeader), "moviestreamformatS"); movie->streams[i].sf_size = sizeof(AviBitmapInfoHeader); - ((AviBitmapInfoHeader *) movie->streams[i].sf)->fcc = FCC ("strf"); + ((AviBitmapInfoHeader *) movie->streams[i].sf)->fcc = FCC("strf"); ((AviBitmapInfoHeader *) movie->streams[i].sf)->size = movie->streams[i].sf_size - 8; ((AviBitmapInfoHeader *) movie->streams[i].sf)->Size = movie->streams[i].sf_size - 8; ((AviBitmapInfoHeader *) movie->streams[i].sf)->Width = 0; ((AviBitmapInfoHeader *) movie->streams[i].sf)->Height = 0; ((AviBitmapInfoHeader *) movie->streams[i].sf)->Planes = 1; ((AviBitmapInfoHeader *) movie->streams[i].sf)->BitCount = 24; - ((AviBitmapInfoHeader *) movie->streams[i].sf)->Compression = avi_get_format_compression (movie->streams[i].format); + ((AviBitmapInfoHeader *) movie->streams[i].sf)->Compression = avi_get_format_compression(movie->streams[i].format); ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = 0; ((AviBitmapInfoHeader *) movie->streams[i].sf)->XPelsPerMeter = 0; ((AviBitmapInfoHeader *) movie->streams[i].sf)->YPelsPerMeter = 0; ((AviBitmapInfoHeader *) movie->streams[i].sf)->ClrUsed = 0; ((AviBitmapInfoHeader *) movie->streams[i].sf)->ClrImportant = 0; -/* +#if 0 if (movie->streams[i].format == AVI_FORMAT_MJPEG) { AviMJPEGUnknown *tmp; @@ -857,7 +870,7 @@ AviError AVI_open_compress(char *name, AviMovie *movie, int streams, ...) else if (movie->streams[i].sh.Type == FCC("auds")) { // pass } -*/ +#endif } } @@ -865,53 +878,53 @@ AviError AVI_open_compress(char *name, AviMovie *movie, int streams, ...) list.size = 0; list.ids = FCC("AVI "); - awrite (movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST); + awrite(movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST); list.fcc = FCC("LIST"); list.size = 0; list.ids = FCC("hdrl"); - awrite (movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST); + awrite(movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST); header_pos1 = ftell(movie->fp); movie->offset_table[0] = ftell(movie->fp); - awrite (movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH); + awrite(movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH); - for (i=0; i < movie->header->Streams; i++) { + for (i = 0; i < movie->header->Streams; i++) { list.fcc = FCC("LIST"); list.size = 0; list.ids = FCC("strl"); - awrite (movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST); + awrite(movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST); stream_pos1 = ftell(movie->fp); - movie->offset_table[1+i*2] = ftell(movie->fp); - awrite (movie, &movie->streams[i].sh, 1, sizeof(AviStreamHeader), movie->fp, AVI_STREAMH); + movie->offset_table[1 + i * 2] = ftell(movie->fp); + awrite(movie, &movie->streams[i].sh, 1, sizeof(AviStreamHeader), movie->fp, AVI_STREAMH); - movie->offset_table[1+i*2+1] = ftell(movie->fp); - awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); + movie->offset_table[1 + i * 2 + 1] = ftell(movie->fp); + awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); stream_pos2 = ftell(movie->fp); - fseek (movie->fp, stream_pos1-8, SEEK_SET); + fseek(movie->fp, stream_pos1 - 8, SEEK_SET); - PUT_FCCN((stream_pos2-stream_pos1+4L), movie->fp); + PUT_FCCN((stream_pos2 - stream_pos1 + 4L), movie->fp); - fseek (movie->fp, stream_pos2, SEEK_SET); + fseek(movie->fp, stream_pos2, SEEK_SET); } - junk_pos= ftell(movie->fp); + junk_pos = ftell(movie->fp); if (junk_pos < 2024 - 8) { chunk.fcc = FCC("JUNK"); chunk.size = 2024 - 8 - (int)junk_pos; - awrite (movie, &chunk, 1, sizeof(AviChunk), movie->fp, AVI_CHUNK); + awrite(movie, &chunk, 1, sizeof(AviChunk), movie->fp, AVI_CHUNK); - for (i=0; i < chunk.size; i++) + for (i = 0; i < chunk.size; i++) putc(0, movie->fp); } @@ -921,13 +934,13 @@ AviError AVI_open_compress(char *name, AviMovie *movie, int streams, ...) list.size = 0; list.ids = FCC("movi"); - awrite (movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST); + awrite(movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST); - movie->movi_offset = ftell(movie->fp)-8L; + movie->movi_offset = ftell(movie->fp) - 8L; - fseek (movie->fp, AVI_HDRL_SOFF, SEEK_SET); + fseek(movie->fp, AVI_HDRL_SOFF, SEEK_SET); - PUT_FCCN((header_pos2-header_pos1+4L), movie->fp); + PUT_FCCN((header_pos2 - header_pos1 + 4L), movie->fp); return AVI_ERROR_NONE; } @@ -949,93 +962,93 @@ AviError AVI_write_frame(AviMovie *movie, int frame_num, ...) /* Allocate the new memory for the index entry */ - if (frame_num+1 > movie->index_entries) { - temp = (AviIndexEntry *) MEM_mallocN ((frame_num+1) * - (movie->header->Streams+1) * sizeof(AviIndexEntry), "newidxentry"); + if (frame_num + 1 > movie->index_entries) { + temp = (AviIndexEntry *) MEM_mallocN((frame_num + 1) * + (movie->header->Streams + 1) * sizeof(AviIndexEntry), "newidxentry"); if (movie->entries != NULL) { - memcpy (temp, movie->entries, movie->index_entries * (movie->header->Streams+1) - * sizeof(AviIndexEntry)); - MEM_freeN (movie->entries); + memcpy(temp, movie->entries, movie->index_entries * (movie->header->Streams + 1) + * sizeof(AviIndexEntry)); + MEM_freeN(movie->entries); } movie->entries = temp; - movie->index_entries = frame_num+1; + movie->index_entries = frame_num + 1; } /* Slap a new record entry onto the end of the file */ - fseek (movie->fp, 0L, SEEK_END); + fseek(movie->fp, 0L, SEEK_END); list.fcc = FCC("LIST"); list.size = 0; list.ids = FCC("rec "); - awrite (movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST); + awrite(movie, &list, 1, sizeof(AviList), movie->fp, AVI_LIST); - rec_off = ftell (movie->fp)-8L; + rec_off = ftell(movie->fp) - 8L; /* Write a frame for every stream */ - va_start (ap, frame_num); + va_start(ap, frame_num); - for (stream=0; stream < movie->header->Streams; stream++) { - unsigned int tbuf=0; + for (stream = 0; stream < movie->header->Streams; stream++) { + unsigned int tbuf = 0; - format = va_arg (ap, AviFormat); - buffer = va_arg (ap, void*); - size = va_arg (ap, int); + format = va_arg(ap, AviFormat); + buffer = va_arg(ap, void *); + size = va_arg(ap, int); /* Convert the buffer into the output format */ - buffer = avi_format_convert (movie, stream, buffer, format, movie->streams[stream].format, &size); + buffer = avi_format_convert(movie, stream, buffer, format, movie->streams[stream].format, &size); /* Write the header info for this data chunk */ - fseek (movie->fp, 0L, SEEK_END); + fseek(movie->fp, 0L, SEEK_END); - chunk.fcc = avi_get_data_id (format, stream); + chunk.fcc = avi_get_data_id(format, stream); chunk.size = size; - if (size%4) chunk.size += 4 - size%4; + if (size % 4) chunk.size += 4 - size % 4; - awrite (movie, &chunk, 1, sizeof(AviChunk), movie->fp, AVI_CHUNK); + awrite(movie, &chunk, 1, sizeof(AviChunk), movie->fp, AVI_CHUNK); /* Write the index entry for this data chunk */ - movie->entries[frame_num * (movie->header->Streams+1) + stream + 1].ChunkId = chunk.fcc; - movie->entries[frame_num * (movie->header->Streams+1) + stream + 1].Flags = AVIIF_KEYFRAME; - movie->entries[frame_num * (movie->header->Streams+1) + stream + 1].Offset = (int)(ftell(movie->fp) - 12L - movie->movi_offset); - movie->entries[frame_num * (movie->header->Streams+1) + stream + 1].Size = chunk.size; + movie->entries[frame_num * (movie->header->Streams + 1) + stream + 1].ChunkId = chunk.fcc; + movie->entries[frame_num * (movie->header->Streams + 1) + stream + 1].Flags = AVIIF_KEYFRAME; + movie->entries[frame_num * (movie->header->Streams + 1) + stream + 1].Offset = (int)(ftell(movie->fp) - 12L - movie->movi_offset); + movie->entries[frame_num * (movie->header->Streams + 1) + stream + 1].Size = chunk.size; /* Write the chunk */ - awrite (movie, buffer, 1, size, movie->fp, AVI_RAW); - MEM_freeN (buffer); + awrite(movie, buffer, 1, size, movie->fp, AVI_RAW); + MEM_freeN(buffer); - if (size%4) awrite (movie, &tbuf, 1, 4-size%4, movie->fp, AVI_RAW); + if (size % 4) awrite(movie, &tbuf, 1, 4 - size % 4, movie->fp, AVI_RAW); /* Update the stream headers length field */ movie->streams[stream].sh.Length++; - fseek (movie->fp, movie->offset_table[1+stream*2], SEEK_SET); - awrite (movie, &movie->streams[stream].sh, 1, sizeof(AviStreamHeader), movie->fp, AVI_STREAMH); + fseek(movie->fp, movie->offset_table[1 + stream * 2], SEEK_SET); + awrite(movie, &movie->streams[stream].sh, 1, sizeof(AviStreamHeader), movie->fp, AVI_STREAMH); } - va_end (ap); + va_end(ap); /* Record the entry for the new record */ - fseek (movie->fp, 0L, SEEK_END); + fseek(movie->fp, 0L, SEEK_END); - movie->entries[frame_num * (movie->header->Streams+1)].ChunkId = FCC("rec "); - movie->entries[frame_num * (movie->header->Streams+1)].Flags = AVIIF_LIST; - movie->entries[frame_num * (movie->header->Streams+1)].Offset = (int)(rec_off - 8L - movie->movi_offset); - movie->entries[frame_num * (movie->header->Streams+1)].Size = (int)(ftell(movie->fp) - (rec_off + 4L)); + movie->entries[frame_num * (movie->header->Streams + 1)].ChunkId = FCC("rec "); + movie->entries[frame_num * (movie->header->Streams + 1)].Flags = AVIIF_LIST; + movie->entries[frame_num * (movie->header->Streams + 1)].Offset = (int)(rec_off - 8L - movie->movi_offset); + movie->entries[frame_num * (movie->header->Streams + 1)].Size = (int)(ftell(movie->fp) - (rec_off + 4L)); /* Update the record size */ - fseek (movie->fp, rec_off, SEEK_SET); - PUT_FCCN (movie->entries[frame_num * (movie->header->Streams+1)].Size, movie->fp); + fseek(movie->fp, rec_off, SEEK_SET); + PUT_FCCN(movie->entries[frame_num * (movie->header->Streams + 1)].Size, movie->fp); /* Update the main header information in the file */ movie->header->TotalFrames++; - fseek (movie->fp, movie->offset_table[0], SEEK_SET); - awrite (movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH); + fseek(movie->fp, movie->offset_table[0], SEEK_SET); + awrite(movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH); return AVI_ERROR_NONE; } @@ -1044,38 +1057,38 @@ AviError AVI_close_compress(AviMovie *movie) { int temp, movi_size, i; - fseek (movie->fp, 0L, SEEK_END); + fseek(movie->fp, 0L, SEEK_END); movi_size = (int)ftell(movie->fp); - PUT_FCC ("idx1", movie->fp); - PUT_FCCN ((movie->index_entries*(movie->header->Streams+1)*16), movie->fp); + PUT_FCC("idx1", movie->fp); + PUT_FCCN((movie->index_entries * (movie->header->Streams + 1) * 16), movie->fp); - for (temp=0; temp < movie->index_entries*(movie->header->Streams+1); temp++) - awrite (movie, &movie->entries[temp], 1, sizeof(AviIndexEntry), movie->fp, AVI_INDEXE); + for (temp = 0; temp < movie->index_entries * (movie->header->Streams + 1); temp++) + awrite(movie, &movie->entries[temp], 1, sizeof(AviIndexEntry), movie->fp, AVI_INDEXE); temp = (int)ftell(movie->fp); - fseek (movie->fp, AVI_RIFF_SOFF, SEEK_SET); + fseek(movie->fp, AVI_RIFF_SOFF, SEEK_SET); - PUT_FCCN((temp-8L), movie->fp); + PUT_FCCN((temp - 8L), movie->fp); - fseek (movie->fp, movie->movi_offset, SEEK_SET); + fseek(movie->fp, movie->movi_offset, SEEK_SET); - PUT_FCCN((movi_size-(movie->movi_offset+4L)), movie->fp); + PUT_FCCN((movi_size - (movie->movi_offset + 4L)), movie->fp); - fclose (movie->fp); + fclose(movie->fp); - for (i=0; i < movie->header->Streams; i++) { + for (i = 0; i < movie->header->Streams; i++) { if (movie->streams[i].sf != NULL) - MEM_freeN (movie->streams[i].sf); + MEM_freeN(movie->streams[i].sf); } if (movie->header != NULL) - MEM_freeN (movie->header); + MEM_freeN(movie->header); if (movie->entries != NULL) - MEM_freeN (movie->entries); + MEM_freeN(movie->entries); if (movie->streams != NULL) - MEM_freeN (movie->streams); + MEM_freeN(movie->streams); if (movie->offset_table != NULL) - MEM_freeN (movie->offset_table); + MEM_freeN(movie->offset_table); return AVI_ERROR_NONE; } diff --git a/source/blender/avi/intern/avirgb.c b/source/blender/avi/intern/avirgb.c index 36e862708f4..78316990d54 100644 --- a/source/blender/avi/intern/avirgb.c +++ b/source/blender/avi/intern/avirgb.c @@ -42,108 +42,108 @@ /* implementation */ -void *avi_converter_from_avi_rgb (AviMovie *movie, int stream, unsigned char *buffer, int *size) +void *avi_converter_from_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, int *size) { int x, y, i, rowstride; unsigned char *buf; AviBitmapInfoHeader *bi; - short bits= 32; + short bits = 32; (void)size; /* unused */ - bi= (AviBitmapInfoHeader *) movie->streams[stream].sf; - if (bi) bits= bi->BitCount; + bi = (AviBitmapInfoHeader *) movie->streams[stream].sf; + if (bi) bits = bi->BitCount; - if (bits==16) { + if (bits == 16) { unsigned short *pxl; unsigned char *to; #ifdef __BIG_ENDIAN__ unsigned char *pxla; #endif - buf = MEM_mallocN (movie->header->Height * movie->header->Width * 3, "fromavirgbbuf"); + buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromavirgbbuf"); - y= movie->header->Height; - to= buf; + y = movie->header->Height; + to = buf; while (y--) { - pxl= (unsigned short *) (buffer + y * movie->header->Width * 2); + pxl = (unsigned short *) (buffer + y * movie->header->Width * 2); #ifdef __BIG_ENDIAN__ - pxla= (unsigned char *)pxl; + pxla = (unsigned char *)pxl; #endif - x= movie->header->Width; + x = movie->header->Width; while (x--) { #ifdef __BIG_ENDIAN__ - i= pxla[0]; - pxla[0]= pxla[1]; - pxla[1]= i; + i = pxla[0]; + pxla[0] = pxla[1]; + pxla[1] = i; - pxla+=2; + pxla += 2; #endif - *(to++)= ((*pxl>>10)&0x1f)*8; - *(to++)= ((*pxl>>5)&0x1f)*8; - *(to++)= (*pxl&0x1f)*8; + *(to++) = ((*pxl >> 10) & 0x1f) * 8; + *(to++) = ((*pxl >> 5) & 0x1f) * 8; + *(to++) = (*pxl & 0x1f) * 8; pxl++; } } - MEM_freeN (buffer); + MEM_freeN(buffer); return buf; } else { - buf = MEM_mallocN (movie->header->Height * movie->header->Width * 3, "fromavirgbbuf"); + buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromavirgbbuf"); - rowstride = movie->header->Width*3; - if (bits!=16) if (movie->header->Width%2) rowstride++; + rowstride = movie->header->Width * 3; + if (bits != 16) if (movie->header->Width % 2) rowstride++; - for (y=0; y < movie->header->Height; y++) { - memcpy (&buf[y*movie->header->Width*3], &buffer[((movie->header->Height-1)-y)*rowstride], movie->header->Width*3); + for (y = 0; y < movie->header->Height; y++) { + memcpy(&buf[y * movie->header->Width * 3], &buffer[((movie->header->Height - 1) - y) * rowstride], movie->header->Width * 3); } - for (y=0; y < movie->header->Height*movie->header->Width*3; y+=3) { + for (y = 0; y < movie->header->Height * movie->header->Width * 3; y += 3) { i = buf[y]; - buf[y] = buf[y+2]; - buf[y+2] = i; + buf[y] = buf[y + 2]; + buf[y + 2] = i; } - MEM_freeN (buffer); + MEM_freeN(buffer); return buf; } } -void *avi_converter_to_avi_rgb (AviMovie *movie, int stream, unsigned char *buffer, int *size) +void *avi_converter_to_avi_rgb(AviMovie *movie, int stream, unsigned char *buffer, int *size) { int y, x, i, rowstride; unsigned char *buf; (void)stream; /* unused */ - *size= movie->header->Height * movie->header->Width * 3; - if (movie->header->Width%2) *size+= movie->header->Height; + *size = movie->header->Height * movie->header->Width * 3; + if (movie->header->Width % 2) *size += movie->header->Height; - buf = MEM_mallocN (*size, "toavirgbbuf"); + buf = MEM_mallocN(*size, "toavirgbbuf"); - rowstride = movie->header->Width*3; - if (movie->header->Width%2) rowstride++; + rowstride = movie->header->Width * 3; + if (movie->header->Width % 2) rowstride++; - for (y=0; y < movie->header->Height; y++) { - memcpy (&buf[y*rowstride], &buffer[((movie->header->Height-1)-y)*movie->header->Width*3], movie->header->Width*3); + for (y = 0; y < movie->header->Height; y++) { + memcpy(&buf[y * rowstride], &buffer[((movie->header->Height - 1) - y) * movie->header->Width * 3], movie->header->Width * 3); } - for (y=0; y < movie->header->Height; y++) { - for (x=0; x < movie->header->Width*3; x+=3) { - i = buf[y*rowstride+x]; - buf[y*rowstride+x] = buf[y*rowstride+x+2]; - buf[y*rowstride+x+2] = i; + for (y = 0; y < movie->header->Height; y++) { + for (x = 0; x < movie->header->Width * 3; x += 3) { + i = buf[y * rowstride + x]; + buf[y * rowstride + x] = buf[y * rowstride + x + 2]; + buf[y * rowstride + x + 2] = i; } } - MEM_freeN (buffer); + MEM_freeN(buffer); return buf; } diff --git a/source/blender/avi/intern/codecs.c b/source/blender/avi/intern/codecs.c index c99938e7b9e..01e228d570e 100644 --- a/source/blender/avi/intern/codecs.c +++ b/source/blender/avi/intern/codecs.c @@ -39,7 +39,7 @@ #include "mjpeg.h" #include "rgb32.h" -void *avi_format_convert (AviMovie *movie, int stream, void *buffer, AviFormat from, AviFormat to, int *size) +void *avi_format_convert(AviMovie *movie, int stream, void *buffer, AviFormat from, AviFormat to, int *size) { if (from == to) return buffer; @@ -53,32 +53,32 @@ void *avi_format_convert (AviMovie *movie, int stream, void *buffer, AviFormat f } switch (to) { - case AVI_FORMAT_RGB24: - switch (from) { + case AVI_FORMAT_RGB24: + switch (from) { + case AVI_FORMAT_AVI_RGB: + buffer = avi_converter_from_avi_rgb(movie, stream, buffer, size); + break; + case AVI_FORMAT_MJPEG: + buffer = avi_converter_from_mjpeg(movie, stream, buffer, size); + break; + case AVI_FORMAT_RGB32: + buffer = avi_converter_from_rgb32(movie, stream, buffer, size); + break; + default: + break; + } + break; case AVI_FORMAT_AVI_RGB: - buffer = avi_converter_from_avi_rgb (movie, stream, buffer, size); + buffer = avi_converter_to_avi_rgb(movie, stream, buffer, size); break; case AVI_FORMAT_MJPEG: - buffer = avi_converter_from_mjpeg (movie, stream, buffer, size); + buffer = avi_converter_to_mjpeg(movie, stream, buffer, size); break; case AVI_FORMAT_RGB32: - buffer = avi_converter_from_rgb32 (movie, stream, buffer, size); + buffer = avi_converter_to_rgb32(movie, stream, buffer, size); break; default: break; - } - break; - case AVI_FORMAT_AVI_RGB: - buffer = avi_converter_to_avi_rgb (movie, stream, buffer, size); - break; - case AVI_FORMAT_MJPEG: - buffer = avi_converter_to_mjpeg (movie, stream, buffer, size); - break; - case AVI_FORMAT_RGB32: - buffer = avi_converter_to_rgb32 (movie, stream, buffer, size); - break; - default: - break; } return buffer; @@ -88,10 +88,10 @@ int avi_get_data_id(AviFormat format, int stream) { char fcc[5]; - if (avi_get_format_type (format) == FCC("vids")) - sprintf (fcc, "%2.2ddc", stream); - else if (avi_get_format_type (format) == FCC("auds")) - sprintf (fcc, "%2.2ddc", stream); + if (avi_get_format_type(format) == FCC("vids")) + sprintf(fcc, "%2.2ddc", stream); + else if (avi_get_format_type(format) == FCC("auds")) + sprintf(fcc, "%2.2ddc", stream); else return 0; @@ -101,48 +101,48 @@ int avi_get_data_id(AviFormat format, int stream) int avi_get_format_type(AviFormat format) { switch (format) { - case AVI_FORMAT_RGB24: - case AVI_FORMAT_RGB32: - case AVI_FORMAT_AVI_RGB: - case AVI_FORMAT_MJPEG: - return FCC("vids"); - break; - default: - return 0; - break; + case AVI_FORMAT_RGB24: + case AVI_FORMAT_RGB32: + case AVI_FORMAT_AVI_RGB: + case AVI_FORMAT_MJPEG: + return FCC("vids"); + break; + default: + return 0; + break; } } int avi_get_format_fcc(AviFormat format) { switch (format) { - case AVI_FORMAT_RGB24: - case AVI_FORMAT_RGB32: - case AVI_FORMAT_AVI_RGB: - return FCC("DIB "); - break; - case AVI_FORMAT_MJPEG: - return FCC("MJPG"); - break; - default: - return 0; - break; + case AVI_FORMAT_RGB24: + case AVI_FORMAT_RGB32: + case AVI_FORMAT_AVI_RGB: + return FCC("DIB "); + break; + case AVI_FORMAT_MJPEG: + return FCC("MJPG"); + break; + default: + return 0; + break; } } int avi_get_format_compression(AviFormat format) { switch (format) { - case AVI_FORMAT_RGB24: - case AVI_FORMAT_RGB32: - case AVI_FORMAT_AVI_RGB: - return 0; - break; - case AVI_FORMAT_MJPEG: - return FCC("MJPG"); - break; - default: - return 0; - break; + case AVI_FORMAT_RGB24: + case AVI_FORMAT_RGB32: + case AVI_FORMAT_AVI_RGB: + return 0; + break; + case AVI_FORMAT_MJPEG: + return FCC("MJPG"); + break; + default: + return 0; + break; } } diff --git a/source/blender/avi/intern/endian.c b/source/blender/avi/intern/endian.c index fd8cc56f551..c9b95d25810 100644 --- a/source/blender/avi/intern/endian.c +++ b/source/blender/avi/intern/endian.c @@ -46,125 +46,125 @@ #endif #ifdef __BIG_ENDIAN__ -static void invert (int *num) +static void invert(int *num) { - int new=0, i, j; + int new = 0, i, j; - for (j=0; j < 4; j++) { - for (i=0; i<8; i++) { - new |= ((*num>>(j*8+i))&1)<<((3-j)*8+i); + for (j = 0; j < 4; j++) { + for (i = 0; i < 8; i++) { + new |= ((*num >> (j * 8 + i)) & 1) << ((3 - j) * 8 + i); } } *num = new; } -static void sinvert (short int *num) +static void sinvert(short int *num) { - short int new=0; + short int new = 0; int i, j; - for (j=0; j < 2; j++) { - for (i=0; i<8; i++) { - new |= ((*num>>(j*8+i))&1)<<((1-j)*8+i); + for (j = 0; j < 2; j++) { + for (i = 0; i < 8; i++) { + new |= ((*num >> (j * 8 + i)) & 1) << ((1 - j) * 8 + i); } } *num = new; } -static void Ichunk (AviChunk *chunk) +static void Ichunk(AviChunk *chunk) { - invert (&chunk->fcc); - invert (&chunk->size); + invert(&chunk->fcc); + invert(&chunk->size); } #endif #ifdef __BIG_ENDIAN__ -static void Ilist (AviList *list) +static void Ilist(AviList *list) { - invert (&list->fcc); - invert (&list->size); - invert (&list->ids); + invert(&list->fcc); + invert(&list->size); + invert(&list->ids); } -static void Imainh (AviMainHeader *mainh) +static void Imainh(AviMainHeader *mainh) { - invert (&mainh->fcc); - invert (&mainh->size); - invert (&mainh->MicroSecPerFrame); - invert (&mainh->MaxBytesPerSec); - invert (&mainh->PaddingGranularity); - invert (&mainh->Flags); - invert (&mainh->TotalFrames); - invert (&mainh->InitialFrames); - invert (&mainh->Streams); - invert (&mainh->SuggestedBufferSize); - invert (&mainh->Width); - invert (&mainh->Height); - invert (&mainh->Reserved[0]); - invert (&mainh->Reserved[1]); - invert (&mainh->Reserved[2]); - invert (&mainh->Reserved[3]); + invert(&mainh->fcc); + invert(&mainh->size); + invert(&mainh->MicroSecPerFrame); + invert(&mainh->MaxBytesPerSec); + invert(&mainh->PaddingGranularity); + invert(&mainh->Flags); + invert(&mainh->TotalFrames); + invert(&mainh->InitialFrames); + invert(&mainh->Streams); + invert(&mainh->SuggestedBufferSize); + invert(&mainh->Width); + invert(&mainh->Height); + invert(&mainh->Reserved[0]); + invert(&mainh->Reserved[1]); + invert(&mainh->Reserved[2]); + invert(&mainh->Reserved[3]); } -static void Istreamh (AviStreamHeader *streamh) +static void Istreamh(AviStreamHeader *streamh) { - invert (&streamh->fcc); - invert (&streamh->size); - invert (&streamh->Type); - invert (&streamh->Handler); - invert (&streamh->Flags); - sinvert (&streamh->Priority); - sinvert (&streamh->Language); - invert (&streamh->InitialFrames); - invert (&streamh->Scale); - invert (&streamh->Rate); - invert (&streamh->Start); - invert (&streamh->Length); - invert (&streamh->SuggestedBufferSize); - invert (&streamh->Quality); - invert (&streamh->SampleSize); - sinvert (&streamh->left); - sinvert (&streamh->right); - sinvert (&streamh->top); - sinvert (&streamh->bottom); + invert(&streamh->fcc); + invert(&streamh->size); + invert(&streamh->Type); + invert(&streamh->Handler); + invert(&streamh->Flags); + sinvert(&streamh->Priority); + sinvert(&streamh->Language); + invert(&streamh->InitialFrames); + invert(&streamh->Scale); + invert(&streamh->Rate); + invert(&streamh->Start); + invert(&streamh->Length); + invert(&streamh->SuggestedBufferSize); + invert(&streamh->Quality); + invert(&streamh->SampleSize); + sinvert(&streamh->left); + sinvert(&streamh->right); + sinvert(&streamh->top); + sinvert(&streamh->bottom); } -static void Ibitmaph (AviBitmapInfoHeader *bitmaph) +static void Ibitmaph(AviBitmapInfoHeader *bitmaph) { - invert (&bitmaph->fcc); - invert (&bitmaph->size); - invert (&bitmaph->Size); - invert (&bitmaph->Width); - invert (&bitmaph->Height); - sinvert (&bitmaph->Planes); - sinvert (&bitmaph->BitCount); - invert (&bitmaph->Compression); - invert (&bitmaph->SizeImage); - invert (&bitmaph->XPelsPerMeter); - invert (&bitmaph->YPelsPerMeter); - invert (&bitmaph->ClrUsed); - invert (&bitmaph->ClrImportant); + invert(&bitmaph->fcc); + invert(&bitmaph->size); + invert(&bitmaph->Size); + invert(&bitmaph->Width); + invert(&bitmaph->Height); + sinvert(&bitmaph->Planes); + sinvert(&bitmaph->BitCount); + invert(&bitmaph->Compression); + invert(&bitmaph->SizeImage); + invert(&bitmaph->XPelsPerMeter); + invert(&bitmaph->YPelsPerMeter); + invert(&bitmaph->ClrUsed); + invert(&bitmaph->ClrImportant); } -static void Imjpegu (AviMJPEGUnknown *mjpgu) +static void Imjpegu(AviMJPEGUnknown *mjpgu) { - invert (&mjpgu->a); - invert (&mjpgu->b); - invert (&mjpgu->c); - invert (&mjpgu->d); - invert (&mjpgu->e); - invert (&mjpgu->f); - invert (&mjpgu->g); + invert(&mjpgu->a); + invert(&mjpgu->b); + invert(&mjpgu->c); + invert(&mjpgu->d); + invert(&mjpgu->e); + invert(&mjpgu->f); + invert(&mjpgu->g); } -static void Iindexe (AviIndexEntry *indexe) +static void Iindexe(AviIndexEntry *indexe) { - invert (&indexe->ChunkId); - invert (&indexe->Flags); - invert (&indexe->Offset); - invert (&indexe->Size); + invert(&indexe->ChunkId); + invert(&indexe->Flags); + invert(&indexe->Offset); + invert(&indexe->Size); } #endif /* __BIG_ENDIAN__ */ @@ -173,53 +173,53 @@ void awrite(AviMovie *movie, void *datain, int block, int size, FILE *fp, int ty #ifdef __BIG_ENDIAN__ void *data; - data = MEM_mallocN (size, "avi endian"); + data = MEM_mallocN(size, "avi endian"); - memcpy (data, datain, size); + memcpy(data, datain, size); switch (type) { - case AVI_RAW: - fwrite (data, block, size, fp); - break; - case AVI_CHUNK: - Ichunk ((AviChunk *) data); - fwrite (data, block, size, fp); - break; - case AVI_LIST: - Ilist ((AviList *) data); - fwrite (data, block, size, fp); - break; - case AVI_MAINH: - Imainh ((AviMainHeader *) data); - fwrite (data, block, size, fp); - break; - case AVI_STREAMH: - Istreamh ((AviStreamHeader *) data); - fwrite (data, block, size, fp); - break; - case AVI_BITMAPH: - Ibitmaph ((AviBitmapInfoHeader *) data); - if (size==sizeof(AviBitmapInfoHeader) + sizeof(AviMJPEGUnknown)) { - Imjpegu((AviMJPEGUnknown*)((char*)data+sizeof(AviBitmapInfoHeader))); - } - fwrite (data, block, size, fp); - break; - case AVI_MJPEGU: - Imjpegu ((AviMJPEGUnknown *) data); - fwrite (data, block, size, fp); - break; - case AVI_INDEXE: - Iindexe ((AviIndexEntry *) data); - fwrite (data, block, size, fp); - break; - default: - break; + case AVI_RAW: + fwrite(data, block, size, fp); + break; + case AVI_CHUNK: + Ichunk((AviChunk *) data); + fwrite(data, block, size, fp); + break; + case AVI_LIST: + Ilist((AviList *) data); + fwrite(data, block, size, fp); + break; + case AVI_MAINH: + Imainh((AviMainHeader *) data); + fwrite(data, block, size, fp); + break; + case AVI_STREAMH: + Istreamh((AviStreamHeader *) data); + fwrite(data, block, size, fp); + break; + case AVI_BITMAPH: + Ibitmaph((AviBitmapInfoHeader *) data); + if (size == sizeof(AviBitmapInfoHeader) + sizeof(AviMJPEGUnknown)) { + Imjpegu((AviMJPEGUnknown *)((char *)data + sizeof(AviBitmapInfoHeader))); + } + fwrite(data, block, size, fp); + break; + case AVI_MJPEGU: + Imjpegu((AviMJPEGUnknown *) data); + fwrite(data, block, size, fp); + break; + case AVI_INDEXE: + Iindexe((AviIndexEntry *) data); + fwrite(data, block, size, fp); + break; + default: + break; } - MEM_freeN (data); + MEM_freeN(data); #else /* __BIG_ENDIAN__ */ (void)movie; /* unused */ (void)type; /* unused */ - fwrite (datain, block, size, fp); + fwrite(datain, block, size, fp); #endif /* __BIG_ENDIAN__ */ } diff --git a/source/blender/avi/intern/mjpeg.c b/source/blender/avi/intern/mjpeg.c index 29356f8ef28..a700284bf68 100644 --- a/source/blender/avi/intern/mjpeg.c +++ b/source/blender/avi/intern/mjpeg.c @@ -42,14 +42,14 @@ #include "mjpeg.h" -#define PADUP(num, amt) ((num+(amt-1))&~(amt-1)) +#define PADUP(num, amt) ((num + (amt - 1)) & ~(amt - 1)) -static void jpegmemdestmgr_build (j_compress_ptr cinfo, unsigned char *buffer, int bufsize); -static void jpegmemsrcmgr_build (j_decompress_ptr dinfo, unsigned char *buffer, int bufsize); +static void jpegmemdestmgr_build(j_compress_ptr cinfo, unsigned char *buffer, int bufsize); +static void jpegmemsrcmgr_build(j_decompress_ptr dinfo, unsigned char *buffer, int bufsize); static int numbytes; -static void add_huff_table (j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val) +static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val) { if (*htblptr == NULL) *htblptr = jpeg_alloc_huff_table((j_common_ptr) dinfo); @@ -64,25 +64,30 @@ static void add_huff_table (j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const U /* Set up the standard Huffman tables (cf. JPEG standard section K.3) */ /* IMPORTANT: these are only valid for 8-bit data precision! */ -static void std_huff_tables (j_decompress_ptr dinfo) +static void std_huff_tables(j_decompress_ptr dinfo) { static const UINT8 bits_dc_luminance[17] = { /* 0-base */ - 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; + 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 + }; static const UINT8 val_dc_luminance[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 + }; static const UINT8 bits_dc_chrominance[17] = { /* 0-base */ - 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; + 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 + }; static const UINT8 val_dc_chrominance[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 + }; static const UINT8 bits_ac_luminance[17] = { /* 0-base */ - 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d }; + 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d + }; static const UINT8 val_ac_luminance[] = { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, @@ -105,10 +110,12 @@ static void std_huff_tables (j_decompress_ptr dinfo) 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, - 0xf9, 0xfa }; + 0xf9, 0xfa + }; static const UINT8 bits_ac_chrominance[17] = { /* 0-base */ - 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 }; + 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 + }; static const UINT8 val_ac_chrominance[] = { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, @@ -131,16 +138,17 @@ static void std_huff_tables (j_decompress_ptr dinfo) 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, - 0xf9, 0xfa }; + 0xf9, 0xfa + }; add_huff_table(dinfo, &dinfo->dc_huff_tbl_ptrs[0], - bits_dc_luminance, val_dc_luminance); + bits_dc_luminance, val_dc_luminance); add_huff_table(dinfo, &dinfo->ac_huff_tbl_ptrs[0], - bits_ac_luminance, val_ac_luminance); + bits_ac_luminance, val_ac_luminance); add_huff_table(dinfo, &dinfo->dc_huff_tbl_ptrs[1], - bits_dc_chrominance, val_dc_chrominance); + bits_dc_chrominance, val_dc_chrominance); add_huff_table(dinfo, &dinfo->ac_huff_tbl_ptrs[1], - bits_ac_chrominance, val_ac_chrominance); + bits_ac_chrominance, val_ac_chrominance); } static int Decode_JPEG(unsigned char *inBuffer, unsigned char *outBuffer, unsigned int width, unsigned int height, int bufsize) @@ -152,7 +160,7 @@ static int Decode_JPEG(unsigned char *inBuffer, unsigned char *outBuffer, unsign (void)width; /* unused */ - numbytes= 0; + numbytes = 0; dinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&dinfo); @@ -166,8 +174,8 @@ static int Decode_JPEG(unsigned char *inBuffer, unsigned char *outBuffer, unsign jpeg_start_decompress(&dinfo); - rowstride= dinfo.output_width*dinfo.output_components; - for (y= 0; y<dinfo.output_height; y++) { + rowstride = dinfo.output_width * dinfo.output_components; + for (y = 0; y < dinfo.output_height; y++) { jpeg_read_scanlines(&dinfo, (JSAMPARRAY) &outBuffer, 1); outBuffer += rowstride; } @@ -175,18 +183,18 @@ static int Decode_JPEG(unsigned char *inBuffer, unsigned char *outBuffer, unsign if (dinfo.output_height >= height) return 0; - inBuffer+= numbytes; - jpegmemsrcmgr_build(&dinfo, inBuffer, bufsize-numbytes); + inBuffer += numbytes; + jpegmemsrcmgr_build(&dinfo, inBuffer, bufsize - numbytes); - numbytes= 0; + numbytes = 0; jpeg_read_header(&dinfo, TRUE); if (dinfo.dc_huff_tbl_ptrs[0] == NULL) { std_huff_tables(&dinfo); } jpeg_start_decompress(&dinfo); - rowstride= dinfo.output_width*dinfo.output_components; - for (y= 0; y<dinfo.output_height; y++) { + rowstride = dinfo.output_width * dinfo.output_components; + for (y = 0; y < dinfo.output_height; y++) { jpeg_read_scanlines(&dinfo, (JSAMPARRAY) &outBuffer, 1); outBuffer += rowstride; } @@ -214,9 +222,9 @@ static void Compress_JPEG(int quality, unsigned char *outbuffer, unsigned char * cinfo.in_color_space = JCS_RGB; jpeg_set_defaults(&cinfo); - jpeg_set_colorspace (&cinfo, JCS_YCbCr); + jpeg_set_colorspace(&cinfo, JCS_YCbCr); - jpeg_set_quality (&cinfo, quality, TRUE); + jpeg_set_quality(&cinfo, quality, TRUE); cinfo.dc_huff_tbl_ptrs[0]->sent_table = TRUE; cinfo.dc_huff_tbl_ptrs[1]->sent_table = TRUE; @@ -232,24 +240,24 @@ static void Compress_JPEG(int quality, unsigned char *outbuffer, unsigned char * jpeg_start_compress(&cinfo, FALSE); - i=0; + i = 0; marker[i++] = 'A'; marker[i++] = 'V'; marker[i++] = 'I'; marker[i++] = '1'; marker[i++] = 0; - while (i<60) + while (i < 60) marker[i++] = 32; - jpeg_write_marker (&cinfo, JPEG_APP0, marker, 60); + jpeg_write_marker(&cinfo, JPEG_APP0, marker, 60); - i=0; - while (i<60) + i = 0; + while (i < 60) marker[i++] = 0; - jpeg_write_marker (&cinfo, JPEG_COM, marker, 60); + jpeg_write_marker(&cinfo, JPEG_COM, marker, 60); - rowstride= cinfo.image_width*cinfo.input_components; + rowstride = cinfo.image_width * cinfo.input_components; for (y = 0; y < cinfo.image_height; y++) { jpeg_write_scanlines(&cinfo, (JSAMPARRAY) &inBuffer, 1); inBuffer += rowstride; @@ -260,43 +268,43 @@ static void Compress_JPEG(int quality, unsigned char *outbuffer, unsigned char * static void interlace(unsigned char *to, unsigned char *from, int width, int height) { - int i, rowstride= width*3; + int i, rowstride = width * 3; - for (i=0; i<height; i++) { - if (i&1) - memcpy (&to[i*rowstride], &from[(i/2 + height/2)*rowstride], rowstride); + for (i = 0; i < height; i++) { + if (i & 1) + memcpy(&to[i * rowstride], &from[(i / 2 + height / 2) * rowstride], rowstride); else - memcpy (&to[i*rowstride], &from[(i/2)*rowstride], rowstride); + memcpy(&to[i * rowstride], &from[(i / 2) * rowstride], rowstride); } } static void deinterlace(int odd, unsigned char *to, unsigned char *from, int width, int height) { - int i, rowstride= width*3; + int i, rowstride = width * 3; - for (i=0; i<height; i++) { - if ((i&1)==odd) - memcpy (&to[(i/2 + height/2)*rowstride], &from[i*rowstride], rowstride); + for (i = 0; i < height; i++) { + if ((i & 1) == odd) + memcpy(&to[(i / 2 + height / 2) * rowstride], &from[i * rowstride], rowstride); else - memcpy (&to[(i/2)*rowstride], &from[i*rowstride], rowstride); + memcpy(&to[(i / 2) * rowstride], &from[i * rowstride], rowstride); } } static int check_and_decode_jpeg(unsigned char *inbuf, unsigned char *outbuf, int width, int height, int bufsize) { - /* JPEG's are always multiples of 16, extra is cropped out AVI's */ - if ((width&0xF) || (height&0xF)) { + /* JPEG's are always multiples of 16, extra is cropped out AVI's */ + if ((width & 0xF) || (height & 0xF)) { int i, rrowstride, jrowstride; - int jwidth= PADUP(width, 16); - int jheight= PADUP(height, 16); - unsigned char *tmpbuf= MEM_mallocN(jwidth*jheight*3, "avi.check_and_decode_jpeg"); - int ret= Decode_JPEG(inbuf, tmpbuf, jwidth, jheight, bufsize); - - /* crop the tmpbuf into the real buffer */ - rrowstride= width*3; - jrowstride= jwidth*3; - for (i=0; i<height; i++) - memcpy(&outbuf[i*rrowstride], &tmpbuf[i*jrowstride], rrowstride); + int jwidth = PADUP(width, 16); + int jheight = PADUP(height, 16); + unsigned char *tmpbuf = MEM_mallocN(jwidth * jheight * 3, "avi.check_and_decode_jpeg"); + int ret = Decode_JPEG(inbuf, tmpbuf, jwidth, jheight, bufsize); + + /* crop the tmpbuf into the real buffer */ + rrowstride = width * 3; + jrowstride = jwidth * 3; + for (i = 0; i < height; i++) + memcpy(&outbuf[i * rrowstride], &tmpbuf[i * jrowstride], rrowstride); MEM_freeN(tmpbuf); return ret; @@ -308,22 +316,22 @@ static int check_and_decode_jpeg(unsigned char *inbuf, unsigned char *outbuf, in static void check_and_compress_jpeg(int quality, unsigned char *outbuf, unsigned char *inbuf, int width, int height, int bufsize) { - /* JPEG's are always multiples of 16, extra is ignored in AVI's */ - if ((width&0xF) || (height&0xF)) { + /* JPEG's are always multiples of 16, extra is ignored in AVI's */ + if ((width & 0xF) || (height & 0xF)) { int i, rrowstride, jrowstride; - int jwidth= PADUP(width, 16); - int jheight= PADUP(height, 16); - unsigned char *tmpbuf= MEM_mallocN(jwidth*jheight*3, "avi.check_and_compress_jpeg"); - - /* resize the realbuf into the tmpbuf */ - rrowstride= width*3; - jrowstride= jwidth*3; - for (i=0; i<jheight; i++) { - if (i<height) - memcpy(&tmpbuf[i*jrowstride], &inbuf[i*rrowstride], rrowstride); + int jwidth = PADUP(width, 16); + int jheight = PADUP(height, 16); + unsigned char *tmpbuf = MEM_mallocN(jwidth * jheight * 3, "avi.check_and_compress_jpeg"); + + /* resize the realbuf into the tmpbuf */ + rrowstride = width * 3; + jrowstride = jwidth * 3; + for (i = 0; i < jheight; i++) { + if (i < height) + memcpy(&tmpbuf[i * jrowstride], &inbuf[i * rrowstride], rrowstride); else - memset(&tmpbuf[i*jrowstride], 0, rrowstride); - memset(&tmpbuf[i*jrowstride+rrowstride], 0, jrowstride-rrowstride); + memset(&tmpbuf[i * jrowstride], 0, rrowstride); + memset(&tmpbuf[i * jrowstride + rrowstride], 0, jrowstride - rrowstride); } Compress_JPEG(quality, outbuf, tmpbuf, jwidth, jheight, bufsize); @@ -335,57 +343,57 @@ static void check_and_compress_jpeg(int quality, unsigned char *outbuf, unsigned } } -void *avi_converter_from_mjpeg (AviMovie *movie, int stream, unsigned char *buffer, int *size) +void *avi_converter_from_mjpeg(AviMovie *movie, int stream, unsigned char *buffer, int *size) { int deint; unsigned char *buf; (void)stream; /* unused */ - buf= MEM_mallocN (movie->header->Height * movie->header->Width * 3, "avi.avi_converter_from_mjpeg 1"); + buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_from_mjpeg 1"); - deint= check_and_decode_jpeg(buffer, buf, movie->header->Width, movie->header->Height, *size); + deint = check_and_decode_jpeg(buffer, buf, movie->header->Width, movie->header->Height, *size); MEM_freeN(buffer); if (deint) { - buffer = MEM_mallocN (movie->header->Height * movie->header->Width * 3, "avi.avi_converter_from_mjpeg 2"); - interlace (buffer, buf, movie->header->Width, movie->header->Height); - MEM_freeN (buf); + buffer = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_from_mjpeg 2"); + interlace(buffer, buf, movie->header->Width, movie->header->Height); + MEM_freeN(buf); - buf= buffer; + buf = buffer; } return buf; } -void *avi_converter_to_mjpeg (AviMovie *movie, int stream, unsigned char *buffer, int *size) +void *avi_converter_to_mjpeg(AviMovie *movie, int stream, unsigned char *buffer, int *size) { unsigned char *buf; - int bufsize= *size; + int bufsize = *size; numbytes = 0; - *size= 0; + *size = 0; - buf = MEM_mallocN (movie->header->Height * movie->header->Width * 3, "avi.avi_converter_to_mjpeg 1"); + buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_to_mjpeg 1"); if (!movie->interlace) { - check_and_compress_jpeg(movie->streams[stream].sh.Quality/100, buf, buffer, movie->header->Width, movie->header->Height, bufsize); + check_and_compress_jpeg(movie->streams[stream].sh.Quality / 100, buf, buffer, movie->header->Width, movie->header->Height, bufsize); } else { - deinterlace (movie->odd_fields, buf, buffer, movie->header->Width, movie->header->Height); - MEM_freeN (buffer); + deinterlace(movie->odd_fields, buf, buffer, movie->header->Width, movie->header->Height); + MEM_freeN(buffer); - buffer= buf; - buf= MEM_mallocN (movie->header->Height * movie->header->Width * 3, "avi.avi_converter_to_mjpeg 2"); + buffer = buf; + buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "avi.avi_converter_to_mjpeg 2"); - check_and_compress_jpeg(movie->streams[stream].sh.Quality/100, buf, buffer, movie->header->Width, movie->header->Height/2, bufsize/2); - *size+= numbytes; - numbytes=0; - check_and_compress_jpeg(movie->streams[stream].sh.Quality/100, buf+*size, buffer+(movie->header->Height/2)*movie->header->Width*3, movie->header->Width, movie->header->Height/2, bufsize/2); + check_and_compress_jpeg(movie->streams[stream].sh.Quality / 100, buf, buffer, movie->header->Width, movie->header->Height / 2, bufsize / 2); + *size += numbytes; + numbytes = 0; + check_and_compress_jpeg(movie->streams[stream].sh.Quality / 100, buf + *size, buffer + (movie->header->Height / 2) * movie->header->Width * 3, movie->header->Width, movie->header->Height / 2, bufsize / 2); } *size += numbytes; - MEM_freeN (buffer); + MEM_freeN(buffer); return buf; } @@ -405,23 +413,23 @@ static boolean jpegmemdestmgr_empty_output_buffer(j_compress_ptr cinfo) static void jpegmemdestmgr_term_destination(j_compress_ptr cinfo) { - numbytes-= cinfo->dest->free_in_buffer; + numbytes -= cinfo->dest->free_in_buffer; MEM_freeN(cinfo->dest); } static void jpegmemdestmgr_build(j_compress_ptr cinfo, unsigned char *buffer, int bufsize) { - cinfo->dest= MEM_mallocN(sizeof(*(cinfo->dest)), "avi.jpegmemdestmgr_build"); + cinfo->dest = MEM_mallocN(sizeof(*(cinfo->dest)), "avi.jpegmemdestmgr_build"); - cinfo->dest->init_destination= jpegmemdestmgr_init_destination; - cinfo->dest->empty_output_buffer= jpegmemdestmgr_empty_output_buffer; - cinfo->dest->term_destination= jpegmemdestmgr_term_destination; + cinfo->dest->init_destination = jpegmemdestmgr_init_destination; + cinfo->dest->empty_output_buffer = jpegmemdestmgr_empty_output_buffer; + cinfo->dest->term_destination = jpegmemdestmgr_term_destination; - cinfo->dest->next_output_byte= buffer; - cinfo->dest->free_in_buffer= bufsize; + cinfo->dest->next_output_byte = buffer; + cinfo->dest->free_in_buffer = bufsize; - numbytes= bufsize; + numbytes = bufsize; } /* Decompression from memory */ @@ -433,48 +441,48 @@ static void jpegmemsrcmgr_init_source(j_decompress_ptr dinfo) static boolean jpegmemsrcmgr_fill_input_buffer(j_decompress_ptr dinfo) { - unsigned char *buf= (unsigned char*) dinfo->src->next_input_byte-2; + unsigned char *buf = (unsigned char *) dinfo->src->next_input_byte - 2; - /* if we get called, must have run out of data */ + /* if we get called, must have run out of data */ WARNMS(dinfo, JWRN_JPEG_EOF); - buf[0]= (JOCTET) 0xFF; - buf[1]= (JOCTET) JPEG_EOI; + buf[0] = (JOCTET) 0xFF; + buf[1] = (JOCTET) JPEG_EOI; - dinfo->src->next_input_byte= buf; - dinfo->src->bytes_in_buffer= 2; + dinfo->src->next_input_byte = buf; + dinfo->src->bytes_in_buffer = 2; return TRUE; } static void jpegmemsrcmgr_skip_input_data(j_decompress_ptr dinfo, long skipcnt) { - if (dinfo->src->bytes_in_buffer<skipcnt) - skipcnt= dinfo->src->bytes_in_buffer; + if (dinfo->src->bytes_in_buffer < skipcnt) + skipcnt = dinfo->src->bytes_in_buffer; - dinfo->src->next_input_byte+= skipcnt; - dinfo->src->bytes_in_buffer-= skipcnt; + dinfo->src->next_input_byte += skipcnt; + dinfo->src->bytes_in_buffer -= skipcnt; } static void jpegmemsrcmgr_term_source(j_decompress_ptr dinfo) { - numbytes-= dinfo->src->bytes_in_buffer; + numbytes -= dinfo->src->bytes_in_buffer; MEM_freeN(dinfo->src); } static void jpegmemsrcmgr_build(j_decompress_ptr dinfo, unsigned char *buffer, int bufsize) { - dinfo->src= MEM_mallocN(sizeof(*(dinfo->src)), "avi.jpegmemsrcmgr_build"); + dinfo->src = MEM_mallocN(sizeof(*(dinfo->src)), "avi.jpegmemsrcmgr_build"); - dinfo->src->init_source= jpegmemsrcmgr_init_source; - dinfo->src->fill_input_buffer= jpegmemsrcmgr_fill_input_buffer; - dinfo->src->skip_input_data= jpegmemsrcmgr_skip_input_data; - dinfo->src->resync_to_restart= jpeg_resync_to_restart; - dinfo->src->term_source= jpegmemsrcmgr_term_source; + dinfo->src->init_source = jpegmemsrcmgr_init_source; + dinfo->src->fill_input_buffer = jpegmemsrcmgr_fill_input_buffer; + dinfo->src->skip_input_data = jpegmemsrcmgr_skip_input_data; + dinfo->src->resync_to_restart = jpeg_resync_to_restart; + dinfo->src->term_source = jpegmemsrcmgr_term_source; - dinfo->src->bytes_in_buffer= bufsize; - dinfo->src->next_input_byte= buffer; + dinfo->src->bytes_in_buffer = bufsize; + dinfo->src->next_input_byte = buffer; - numbytes= bufsize; + numbytes = bufsize; } diff --git a/source/blender/avi/intern/options.c b/source/blender/avi/intern/options.c index db9719c171d..7de91318ecf 100644 --- a/source/blender/avi/intern/options.c +++ b/source/blender/avi/intern/options.c @@ -54,78 +54,78 @@ AviError AVI_set_compress_option(AviMovie *movie, int option_type, int stream, A return AVI_ERROR_OPTION; switch (option_type) { - case AVI_OPTION_TYPE_MAIN: - switch (option) { - case AVI_OPTION_WIDTH: - movie->header->Width = *((int *) opt_data); - movie->header->SuggestedBufferSize = movie->header->Width*movie->header->Height*3; - - for (i=0; i < movie->header->Streams; i++) { - if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { - ((AviBitmapInfoHeader *) movie->streams[i].sf)->Width = *((int *) opt_data); - movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize; - movie->streams[i].sh.right = *((int *) opt_data); - ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize; - fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET); - awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); - } - } - - break; + case AVI_OPTION_TYPE_MAIN: + switch (option) { + case AVI_OPTION_WIDTH: + movie->header->Width = *((int *) opt_data); + movie->header->SuggestedBufferSize = movie->header->Width * movie->header->Height * 3; + + for (i = 0; i < movie->header->Streams; i++) { + if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { + ((AviBitmapInfoHeader *) movie->streams[i].sf)->Width = *((int *) opt_data); + movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize; + movie->streams[i].sh.right = *((int *) opt_data); + ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize; + fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET); + awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); + } + } + + break; + + case AVI_OPTION_HEIGHT: + movie->header->Height = *((int *) opt_data); + movie->header->SuggestedBufferSize = movie->header->Width * movie->header->Height * 3; + + for (i = 0; i < movie->header->Streams; i++) { + if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { + ((AviBitmapInfoHeader *) movie->streams[i].sf)->Height = *((int *) opt_data); + movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize; + movie->streams[i].sh.bottom = *((int *) opt_data); + ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize; + fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET); + awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); + } + } + + break; + + case AVI_OPTION_QUALITY: + for (i = 0; i < movie->header->Streams; i++) { + if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { + movie->streams[i].sh.Quality = (*((int *) opt_data)) * 100; + fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET); + awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); + } + } + break; + + case AVI_OPTION_FRAMERATE: + useconds = (int)(1000000 / (*((double *) opt_data))); + if (useconds) + movie->header->MicroSecPerFrame = useconds; + + for (i = 0; i < movie->header->Streams; i++) { + if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { + movie->streams[i].sh.Scale = movie->header->MicroSecPerFrame; + fseek(movie->fp, movie->offset_table[1 + i * 2 + 1], SEEK_SET); + awrite(movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); + } + } - case AVI_OPTION_HEIGHT: - movie->header->Height = *((int *) opt_data); - movie->header->SuggestedBufferSize = movie->header->Width*movie->header->Height*3; - - for (i=0; i < movie->header->Streams; i++) { - if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { - ((AviBitmapInfoHeader *) movie->streams[i].sf)->Height = *((int *) opt_data); - movie->streams[i].sh.SuggestedBufferSize = movie->header->SuggestedBufferSize; - movie->streams[i].sh.bottom = *((int *) opt_data); - ((AviBitmapInfoHeader *) movie->streams[i].sf)->SizeImage = movie->header->SuggestedBufferSize; - fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET); - awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); - } } - break; + fseek(movie->fp, movie->offset_table[0], SEEK_SET); + awrite(movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH); - case AVI_OPTION_QUALITY: - for (i=0; i < movie->header->Streams; i++) { - if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { - movie->streams[i].sh.Quality = (*((int *) opt_data))*100; - fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET); - awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); - } - } break; - - case AVI_OPTION_FRAMERATE: - useconds = (int)(1000000/(*((double *) opt_data))); - if (useconds) - movie->header->MicroSecPerFrame = useconds; - - for (i=0; i < movie->header->Streams; i++) { - if (avi_get_format_type(movie->streams[i].format) == FCC("vids")) { - movie->streams[i].sh.Scale = movie->header->MicroSecPerFrame; - fseek (movie->fp, movie->offset_table[1+i*2+1], SEEK_SET); - awrite (movie, movie->streams[i].sf, 1, movie->streams[i].sf_size, movie->fp, AVI_BITMAPH); - } - } - - } - - fseek (movie->fp, movie->offset_table[0], SEEK_SET); - awrite (movie, movie->header, 1, sizeof(AviMainHeader), movie->fp, AVI_MAINH); - - break; - case AVI_OPTION_TYPE_STRH: - break; - case AVI_OPTION_TYPE_STRF: - break; - default: - return AVI_ERROR_OPTION; - break; + case AVI_OPTION_TYPE_STRH: + break; + case AVI_OPTION_TYPE_STRF: + break; + default: + return AVI_ERROR_OPTION; + break; } return AVI_ERROR_NONE; diff --git a/source/blender/avi/intern/rgb32.c b/source/blender/avi/intern/rgb32.c index 7b4958ca026..84630f09fe5 100644 --- a/source/blender/avi/intern/rgb32.c +++ b/source/blender/avi/intern/rgb32.c @@ -39,33 +39,33 @@ #include "MEM_guardedalloc.h" #include "rgb32.h" -void *avi_converter_from_rgb32 (AviMovie *movie, int stream, unsigned char *buffer, int *size) +void *avi_converter_from_rgb32(AviMovie *movie, int stream, unsigned char *buffer, int *size) { int y, x, rowstridea, rowstrideb; unsigned char *buf; (void)stream; /* unused */ - buf = MEM_mallocN (movie->header->Height * movie->header->Width * 3, "fromrgb32buf"); + buf = MEM_mallocN(movie->header->Height * movie->header->Width * 3, "fromrgb32buf"); *size = movie->header->Height * movie->header->Width * 3; - rowstridea = movie->header->Width*3; - rowstrideb = movie->header->Width*4; + rowstridea = movie->header->Width * 3; + rowstrideb = movie->header->Width * 4; - for (y=0; y < movie->header->Height; y++) { - for (x=0; x < movie->header->Width; x++) { - buf[y*rowstridea + x*3 + 0] = buffer[y*rowstrideb + x*4 + 3]; - buf[y*rowstridea + x*3 + 1] = buffer[y*rowstrideb + x*4 + 2]; - buf[y*rowstridea + x*3 + 2] = buffer[y*rowstrideb + x*4 + 1]; + for (y = 0; y < movie->header->Height; y++) { + for (x = 0; x < movie->header->Width; x++) { + buf[y * rowstridea + x * 3 + 0] = buffer[y * rowstrideb + x * 4 + 3]; + buf[y * rowstridea + x * 3 + 1] = buffer[y * rowstrideb + x * 4 + 2]; + buf[y * rowstridea + x * 3 + 2] = buffer[y * rowstrideb + x * 4 + 1]; } } - MEM_freeN (buffer); + MEM_freeN(buffer); return buf; } -void *avi_converter_to_rgb32 (AviMovie *movie, int stream, unsigned char *buffer, int *size) +void *avi_converter_to_rgb32(AviMovie *movie, int stream, unsigned char *buffer, int *size) { int i; unsigned char *buf; @@ -73,20 +73,20 @@ void *avi_converter_to_rgb32 (AviMovie *movie, int stream, unsigned char *buffer (void)stream; /* unused */ - buf= MEM_mallocN (movie->header->Height * movie->header->Width * 4, "torgb32buf"); - *size= movie->header->Height * movie->header->Width * 4; + buf = MEM_mallocN(movie->header->Height * movie->header->Width * 4, "torgb32buf"); + *size = movie->header->Height * movie->header->Width * 4; memset(buf, 255, *size); - to= buf; from= buffer; - i=movie->header->Height*movie->header->Width; + to = buf; from = buffer; + i = movie->header->Height * movie->header->Width; while (i--) { memcpy(to, from, 3); - to+=4; from+=3; + to += 4; from += 3; } - MEM_freeN (buffer); + MEM_freeN(buffer); return buf; } |