4 static int s_resample_width = 256;
5 static int s_resample_height = 256;
10 #define BTC_COMPRESSION 1
12 static int s_compression_method = BTC_COMPRESSION;
14 static const char *CIN_EXTENSION = "cn2";
15 static const int CIN_SIGNATURE = ( 'C' << 24 ) | ( 'I' << 16 ) | ( 'N' << 8 ) | ( '2' );
17 static byte *s_soundtrack;
18 static char s_base[32];
19 static char s_output_base[32];
22 ===============================================================================
26 ===============================================================================
36 int dataofs; // chunk starts this many bytes from file start
47 static int s_samplecounts[0x10000];
48 static wavinfo_t s_wavinfo;
50 short GetLittleShort(void)
54 val = val + (*(data_p+1)<<8);
59 int GetLittleLong(void)
63 val = val + (*(data_p+1)<<8);
64 val = val + (*(data_p+2)<<16);
65 val = val + (*(data_p+3)<<24);
70 void FindNextChunk(char *name)
76 if (data_p >= iff_end)
77 { // didn't find the chunk
83 iff_chunk_len = GetLittleLong();
84 if (iff_chunk_len < 0)
89 // if (iff_chunk_len > 1024*1024)
90 // Sys_Error ("FindNextChunk: %i length is past the 1 meg sanity limit", iff_chunk_len);
92 last_chunk = data_p + 8 + ( (iff_chunk_len + 1) & ~1 );
93 if (!strncmp(data_p, name, 4))
98 void FindChunk(char *name)
100 last_chunk = iff_data;
101 FindNextChunk (name);
105 void DumpChunks(void)
113 memcpy (str, data_p, 4);
115 iff_chunk_len = GetLittleLong();
116 printf ("0x%x : %s (%d)\n", (int)(data_p - 4), str, iff_chunk_len);
117 data_p += (iff_chunk_len + 1) & ~1;
118 } while (data_p < iff_end);
126 wavinfo_t GetWavinfo (char *name, byte *wav, int wavlength)
133 memset (&info, 0, sizeof(info));
139 iff_end = wav + wavlength;
143 if (!(data_p && !strncmp(data_p+8, "WAVE", 4)))
145 printf("Missing RIFF/WAVE chunks\n");
150 iff_data = data_p + 12;
156 printf("Missing fmt chunk\n");
160 format = GetLittleShort();
163 printf("Microsoft PCM format only\n");
167 info.channels = GetLittleShort();
168 info.rate = GetLittleLong();
170 info.width = GetLittleShort() / 8;
177 info.loopstart = GetLittleLong();
178 // Com_Printf("loopstart=%d\n", sfx->loopstart);
180 // if the next chunk is a LIST chunk, look for a cue length marker
181 FindNextChunk ("LIST");
184 if (!strncmp (data_p + 28, "mark", 4))
185 { // this is not a proper parse, but it works with cooledit...
187 i = GetLittleLong (); // samples in loop
188 info.samples = info.loopstart + i;
199 printf("Missing data chunk\n");
204 samples = GetLittleLong ();
208 if (samples < info.samples)
209 Error ("Sound %s has a bad loop length", name);
212 info.samples = samples;
214 info.dataofs = data_p - wav;
219 //=====================================================================
226 void LoadSoundtrack (void)
234 sprintf (name, "%svideo/%s/%s.wav", gamedir, s_base, s_base);
235 printf ("WAV: %s\n", name);
236 f = fopen (name, "rb");
239 printf ("no soundtrack for %s\n", s_base);
242 len = Q_filelength(f);
243 s_soundtrack = malloc(len);
244 fread (s_soundtrack, 1, len, f);
247 s_wavinfo = GetWavinfo (name, s_soundtrack, len);
249 // count samples for compression
250 memset (s_samplecounts, 0, sizeof(s_samplecounts));
252 j = s_wavinfo.samples/2;
253 for (i=0 ; i<j ; i++)
255 val = ((unsigned short *)( s_soundtrack + s_wavinfo.dataofs))[i];
256 s_samplecounts[val]++;
259 for (i=0 ; i<0x10000 ; i++)
260 if (s_samplecounts[i])
263 printf ("%i unique sample values\n", val);
271 void WriteSound (FILE *output, int frame)
280 width = s_wavinfo.width * s_wavinfo.channels;
282 start = frame*s_wavinfo.rate/14;
283 end = (frame+1)*s_wavinfo.rate/14;
286 for (i=0 ; i<count ; i++)
289 if (sample > s_wavinfo.samples || !s_soundtrack)
290 fwrite (&empty, 1, width, output);
292 fwrite (s_soundtrack + s_wavinfo.dataofs + sample*width, 1, width,output);
296 //==========================================================================
298 static float s_resampleXRatio;
299 static float s_resampleYRatio;
301 static void BoxFilterHorizontalElements( unsigned char *dst, unsigned char *src, float s0, float s1 )
304 float rSum = 0, gSum = 0, bSum = 0;
308 for ( x = s0; x < s1; x++, src += 4 )
312 w = ( int ) ( s0 + 1 ) - x;
314 else if ( x + 1 >= s1 )
333 dst[0] = ( unsigned char ) ( rSum + 0.5 );
334 dst[1] = ( unsigned char ) ( gSum + 0.5 );
335 dst[2] = ( unsigned char ) ( bSum + 0.5 );
338 static void BoxFilterVerticalElements( unsigned char *dst, // destination of the filter process
339 unsigned char *src, // source pixels
340 int srcStep, // stride of the source pixels
344 float rSum = 0, gSum = 0, bSum = 0;
348 for ( y = s0; y < ( int ) ( s1 + 1 ) ; y++, src += srcStep )
352 w = ( int ) ( s0 + 1 ) - y;
354 else if ( y + 1 >= s1 )
373 dst[0] = ( unsigned char ) ( rSum + 0.5 );
374 dst[1] = ( unsigned char ) ( gSum + 0.5 );
375 dst[2] = ( unsigned char ) ( bSum + 0.5 );
380 static void BoxFilterRow( unsigned char *dstStart, cblock_t *in, int dstRow, int rowWidth )
383 unsigned char *indata = ( unsigned char * ) in->data;
385 indata += 4 * dstRow * in->width;
387 for ( i = 0; i < rowWidth; i++ )
389 float c0 = i * s_resampleXRatio;
390 float c1 = ( i + 1 ) * s_resampleXRatio;
392 BoxFilterHorizontalElements( &dstStart[i*4], &indata[( ( int ) c0 ) * 4], c0, c1 );
396 static void BoxFilterColumn( unsigned char *dstStart, unsigned char *srcStart, int dstCol, int dstRowWidth, int dstColHeight, int srcRowWidthInPels )
401 for ( i = 0; i < dstColHeight; i++ )
403 c0 = i * s_resampleYRatio;
404 c1 = ( i + 1 ) * s_resampleYRatio;
406 BoxFilterVerticalElements( &dstStart[i*4*dstRowWidth], &srcStart[(int)c0*srcRowWidthInPels*4], srcRowWidthInPels*4, c0, c1 );
410 #define DROP_SAMPLE 0
413 static void ResampleFrame( cblock_t *in, unsigned char *out, int method, int outWidth, int outHeight )
416 unsigned char *indata = ( unsigned char * ) in->data;
418 s_resampleXRatio = in->width / ( float ) outWidth;
419 s_resampleYRatio = in->height / ( float ) outHeight;
421 if ( method == DROP_SAMPLE )
423 for ( row = 0; row < outHeight; row++ )
425 int r = ( int ) ( row * s_resampleYRatio );
427 for ( column = 0; column < outWidth; column++ )
429 int c = ( int ) ( column * s_resampleXRatio );
431 out[(row*outWidth+column)*4+0] = indata[(r*in->width+c)*4+0];
432 out[(row*outWidth+column)*4+1] = indata[(r*in->width+c)*4+1];
433 out[(row*outWidth+column)*4+2] = indata[(r*in->width+c)*4+2];
434 out[(row*outWidth+column)*4+3] = 0xff;
438 else if ( method == BOX_FILTER )
440 unsigned char intermediate[1024*1024*4];
442 assert( in->height <= 1024 );
443 assert( in->width <= 1024 );
446 // filter our M x N source image into a RESAMPLE_WIDTH x N horizontally filtered image
448 for ( row = 0; row < in->height; row++ )
450 BoxFilterRow( &intermediate[row*4*outWidth], in, row, outWidth );
454 // filter our RESAMPLE_WIDTH x N horizontally filtered image into a RESAMPLE_WIDTH x RESAMPLE_HEIGHT filtered image
456 for ( column = 0; column < outWidth; column++ )
458 BoxFilterColumn( &out[column*4], &intermediate[column*4], column, outWidth, outHeight, s_resample_width );
463 static float BTCDistanceSquared( float a[3], float b[3] )
465 return ( b[0] - a[0] ) * ( b[0] - a[0] ) +
466 ( b[1] - a[1] ) * ( b[1] - a[1] ) +
467 ( b[2] - a[2] ) * ( b[2] - a[2] );
470 static void BTCFindEndpoints( float inBlock[4][4][3], unsigned int endPoints[2][2] )
472 float longestDistance = -1;
477 // find the two points farthest from each other
479 for ( bY = 0; bY < 4; bY++ )
481 for ( bX = 0; bX < 4; bX++ )
487 // check the rest of the current row
489 for ( cX = bX + 1; cX < 4; cX++ )
491 if ( ( d = BTCDistanceSquared( inBlock[bY][bX], inBlock[bY][cX] ) ) > longestDistance )
494 endPoints[0][0] = bX;
495 endPoints[0][1] = bY;
496 endPoints[1][0] = cX;
497 endPoints[1][1] = bY;
502 // check remaining rows and columns
504 for ( cY = bY+1; cY < 4; cY++ )
506 for ( cX = 0; cX < 4; cX++ )
508 if ( ( d = BTCDistanceSquared( inBlock[bY][bX], inBlock[cY][cX] ) ) > longestDistance )
511 endPoints[0][0] = bX;
512 endPoints[0][1] = bY;
513 endPoints[1][0] = cX;
514 endPoints[1][1] = cY;
522 static float BTCQuantizeBlock( float inBlock[4][4][3], unsigned long endPoints[2][2], int btcQuantizedBlock[4][4], float bestError )
529 float colorLine[4][3];
532 // build the color line
534 dR = inBlock[endPoints[1][1]][endPoints[1][0]][0] -
535 inBlock[endPoints[0][1]][endPoints[0][0]][0];
536 dG = inBlock[endPoints[1][1]][endPoints[1][0]][1] -
537 inBlock[endPoints[0][1]][endPoints[0][0]][1];
538 dB = inBlock[endPoints[1][1]][endPoints[1][0]][2] -
539 inBlock[endPoints[0][1]][endPoints[0][0]][2];
545 R = inBlock[endPoints[0][1]][endPoints[0][0]][0];
546 G = inBlock[endPoints[0][1]][endPoints[0][0]][1];
547 B = inBlock[endPoints[0][1]][endPoints[0][0]][2];
549 for ( i = 0; i < 4; i++ )
561 // quantize each pixel into the appropriate range
563 for ( blockY = 0; blockY < 4; blockY++ )
565 for ( blockX = 0; blockX < 4; blockX++ )
567 float distance = 10000000000;
570 for ( i = 0; i < 4; i++ )
574 if ( ( d = BTCDistanceSquared( inBlock[blockY][blockX], colorLine[i] ) ) < distance )
584 // if bestError is not -1 then that means this is a speculative quantization
586 if ( bestError != -1 )
588 if ( error > bestError )
592 btcQuantizedBlock[blockY][blockX] = shortest;
600 ** float BTCCompressBlock
602 static float BTCCompressBlock( float inBlock[4][4][3], unsigned long out[2] )
605 int btcQuantizedBlock[4][4]; // values should be [0..3]
606 unsigned long encodedEndPoints, encodedBitmap;
607 unsigned int endPoints[2][2]; // endPoints[0] = color start, endPoints[1] = color end
610 float bestError = 10000000000;
611 unsigned int bestEndPoints[2][2];
615 // find the "ideal" end points for the color vector
617 BTCFindEndpoints( inBlock, endPoints );
618 error = BTCQuantizeBlock( inBlock, endPoints, btcQuantizedBlock );
619 memcpy( bestEndPoints, endPoints, sizeof( bestEndPoints ) );
621 for ( blockY = 0; blockY < 4; blockY++ )
623 for ( blockX = 0; blockX < 4; blockX++ )
627 for ( y2 = 0; y2 < 4; y2++ )
629 for ( x2 = 0; x2 < 4; x2++ )
631 if ( ( x2 == blockX ) && ( y2 == blockY ) )
634 endPoints[0][0] = blockX;
635 endPoints[0][1] = blockY;
636 endPoints[1][0] = x2;
637 endPoints[1][1] = y2;
639 error = BTCQuantizeBlock( inBlock, endPoints, btcQuantizedBlock, -1 ); //bestError );
641 if ( error < bestError )
644 memcpy( bestEndPoints, endPoints, sizeof( bestEndPoints ) );
651 error = BTCQuantizeBlock( inBlock, bestEndPoints, btcQuantizedBlock, -1.0f );
655 // encode the results
658 for ( blockY = 0; blockY < 4; blockY++ )
660 for ( blockX = 0; blockX < 4; blockX++ )
662 int shift = ( blockX + blockY * 4 ) * 2;
663 encodedBitmap |= btcQuantizedBlock[blockY][blockX] << shift;
670 encodedEndPoints = 0;
671 for ( i = 0; i < 2; i++ )
675 iR = ( ( int ) inBlock[bestEndPoints[i][1]][bestEndPoints[i][0]][0] );
682 iG = ( ( int ) inBlock[bestEndPoints[i][1]][bestEndPoints[i][0]][1] );
689 iB = ( ( int ) inBlock[bestEndPoints[i][1]][bestEndPoints[i][0]][2] );
697 encodedEndPoints |= ( ( ( iR << 11 ) | ( iG << 5 ) | ( iB ) ) << ( i * 16 ) );
703 out[0] = encodedBitmap;
704 out[1] = encodedEndPoints;
710 ** void BTCDecompressFrame
712 static void BTCDecompressFrame( unsigned long *src, unsigned char *dst )
717 float colorStart[3], colorEnd[3];
718 unsigned char colorRampABGR[4][4];
721 memset( colorRampABGR, 0xff, sizeof( colorRampABGR ) );
723 for ( y = 0; y < s_resample_height / 4; y++ )
725 for ( x = 0; x < s_resample_width / 4; x++ )
727 unsigned colorStartPacked = src[(y*s_resample_width/4 + x)*2 + 1] & 0xffff;
728 unsigned colorEndPacked = src[(y*s_resample_width/4 + x)*2 + 1] >> 16;
731 // grab the end points
735 iR = ( ( colorStartPacked >> 11 ) & ( ( 1 << 5 ) - 1 ) );
736 iR = ( iR << 3 ) | ( iR >> 2 );
737 iG = ( ( colorStartPacked >> 5 ) & ( ( 1 << 6 ) - 1 ) );
738 iG = ( iG << 2 ) | ( iG >> 4 );
739 iB = ( ( colorStartPacked ) & ( ( 1 << 5 ) - 1 ) );
740 iB = ( iB << 3 ) | ( iB >> 2 );
745 colorRampABGR[0][0] = iR;
746 colorRampABGR[0][1] = iG;
747 colorRampABGR[0][2] = iB;
749 iR = ( ( colorEndPacked >> 11 ) & ( ( 1 << 5 ) - 1 ) );
750 iR = ( iR << 3 ) | ( iR >> 2 );
751 iG = ( ( colorEndPacked >> 5 ) & ( ( 1 << 6 ) - 1 ) );
752 iG = ( iG << 2 ) | ( iG >> 4 );
753 iB = ( colorEndPacked & ( ( 1 << 5 ) - 1 ) );
754 iB = ( iB << 3 ) | ( iB >> 2 );
759 colorRampABGR[3][0] = iR;
760 colorRampABGR[3][1] = iG;
761 colorRampABGR[3][2] = iB;
764 // compute this block's color ramp
765 // FIXME: This needs to be reversed on big-endian machines
768 colorRampABGR[1][0] = colorStart[0] * 0.66f + colorEnd[0] * 0.33f;
769 colorRampABGR[1][1] = colorStart[1] * 0.66f + colorEnd[1] * 0.33f;
770 colorRampABGR[1][2] = colorStart[2] * 0.66f + colorEnd[2] * 0.33f;
772 colorRampABGR[2][0] = colorStart[0] * 0.33f + colorEnd[0] * 0.66f;
773 colorRampABGR[2][1] = colorStart[1] * 0.33f + colorEnd[1] * 0.66f;
774 colorRampABGR[2][2] = colorStart[2] * 0.33f + colorEnd[2] * 0.66f;
777 // decode the color data
778 // information is encoded in 2-bit pixels, with low order bits corresponding
779 // to upper left pixels. These 2-bit values are indexed into the block's
780 // computer color ramp.
782 encoded = src[(y*s_resample_width/4 + x)*2 + 0];
784 for ( dstY = 0; dstY < 4; dstY++ )
786 for ( dstX = 0; dstX < 4; dstX++ )
788 memcpy( &dst[(y*4+dstY)*s_resample_width*4+x*4*4+dstX*4], colorRampABGR[encoded&3], sizeof( colorRampABGR[0] ) );
799 ** Perform a BTC compression using a 2-bit encoding at each pixel. This
800 ** compression method is performed by decomposing the incoming image into
801 ** a sequence of 4x4 blocks. At each block two color values are computed
802 ** that define the endpoints of a vector in color space that represent
803 ** the two colors "farthest apart".
805 static float BTCCompressFrame( unsigned char *src, unsigned long *dst )
809 float btcBlock[4][4][3];
813 for ( y = 0; y < s_resample_height / 4; y++ )
815 for ( x = 0; x < s_resample_width / 4; x++ )
818 // fill in the BTC block with raw values
820 for ( bY = 0; bY < 4; bY++ )
822 for ( bX = 0; bX < 4; bX++ )
824 btcBlock[bY][bX][0] = src[(y*4+bY)*s_resample_width*4 + (x*4+bX)*4 + 0];
825 btcBlock[bY][bX][1] = src[(y*4+bY)*s_resample_width*4 + (x*4+bX)*4 + 1];
826 btcBlock[bY][bX][2] = src[(y*4+bY)*s_resample_width*4 + (x*4+bX)*4 + 2];
830 error += BTCCompressBlock( btcBlock, &dst[(y*s_resample_width/4+x)*2] );
834 return error / ( ( s_resample_width / 4 ) * ( s_resample_height / 4 ) );
842 cblock_t LoadFrame (char *base, int frame, int digits, byte **palette)
844 int ten3, ten2, ten1, ten0;
854 ten2 = (frame-ten3*1000)/100;
855 ten1 = (frame-ten3*1000-ten2*100)/10;
859 sprintf (name, "%svideo/%s/%s%i%i%i%i.tga", gamedir, base, base, ten3, ten2, ten1, ten0);
861 sprintf (name, "%svideo/%s/%s%i%i%i.tga", gamedir, base, base, ten2, ten1, ten0);
863 f = fopen(name, "rb");
872 LoadTGA( name, ( unsigned char ** ) &in.data, &width, &height );
875 // Load256Image (name, &in.data, palette, &width, &height);
876 in.count = width*height;
879 // FIXME: map 0 and 255!
896 video <directory> <framedigits>
899 void Cmd_Video (void)
901 float sumError = 0, error = 0, maxError = 0;
905 int startframe, frame;
913 unsigned char *resampled;
914 unsigned long *compressed;
918 strcpy (s_base, token);
921 // sprintf (savename, "video/%s.cin", token);
922 // ReleaseFile (savename);
927 strcpy( s_output_base, token );
930 digits = atoi(token);
934 if ( !strcmp( token, "btc" ) )
936 s_compression_method = BTC_COMPRESSION;
937 printf( "Compression: BTC\n" );
939 else if ( !strcmp( token, "uc" ) )
941 s_compression_method = UNCOMPRESSED;
942 printf( "Compression: none\n" );
946 Error( "Uknown compression method '%s'\n", token );
950 s_resample_width = atoi( token );
953 s_resample_height = atoi( token );
955 resampled = malloc( sizeof( unsigned char ) * 4 * s_resample_width * s_resample_height );
956 compressed = malloc( sizeof( long ) * 2 * ( s_resample_width / 4 ) * ( s_resample_height / 4 ) );
958 printf( "Resample width: %d\n", s_resample_width );
959 printf( "Resample height: %d\n", s_resample_height );
961 // optionally skip frames
962 if (TokenAvailable ())
965 startframe = atoi(token);
970 sprintf (savename, "%svideo/%s.%s", writedir, s_output_base, CIN_EXTENSION );
972 // load the entire sound wav file if present
976 sprintf (name, "%svideo/%s/%s0000.tga", gamedir, s_base, s_base);
978 sprintf (name, "%svideo/%s/%s000.tga", gamedir, s_base, s_base);
980 printf ("%s\n", name);
981 LoadTGA( name, NULL, &width, &height);
983 output = fopen (savename, "wb");
985 Error ("Can't open %s", savename);
988 i = LittleLong( CIN_SIGNATURE );
989 fwrite (&i, 4, 1, output );
990 i = LittleLong (s_resample_width);
991 fwrite (&i, 4, 1, output);
992 i = LittleLong (s_resample_height);
993 fwrite (&i, 4, 1, output);
994 i = LittleLong (s_wavinfo.rate);
995 fwrite (&i, 4, 1, output);
996 i = LittleLong (s_wavinfo.width);
997 fwrite (&i, 4, 1, output);
998 i = LittleLong (s_wavinfo.channels);
999 fwrite (&i, 4, 1, output);
1000 i = LittleLong ( s_compression_method );
1001 fwrite (&i, 4, 1, output );
1005 // perform compression on a per frame basis
1006 for ( frame=startframe ; ; frame++)
1008 printf ("%02d: ", frame);
1009 in = LoadFrame (s_base, frame, digits, 0 );
1013 ResampleFrame( &in, ( unsigned char * ) resampled, BOX_FILTER, s_resample_width, s_resample_height );
1015 if ( s_compression_method == UNCOMPRESSED )
1018 fwrite( resampled, 1, sizeof( unsigned char ) * s_resample_width * s_resample_height * 4, output );
1025 for ( y = 0; y < s_resample_height/2; y++ )
1027 for ( x = 0; x < s_resample_width; x++ )
1029 unsigned char tmp[4];
1031 tmp[0] = resampled[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 0];
1032 tmp[1] = resampled[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 1];
1033 tmp[2] = resampled[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 2];
1034 tmp[3] = resampled[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 3];
1036 resampled[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 0] = resampled[y*s_resample_width*4 + x*4 + 0];
1037 resampled[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 1] = resampled[y*s_resample_width*4 + x*4 + 1];
1038 resampled[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 2] = resampled[y*s_resample_width*4 + x*4 + 2];
1039 resampled[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 3] = resampled[y*s_resample_width*4 + x*4 + 3];
1041 resampled[y*s_resample_width*4 + x*4 + 0] = tmp[0];
1042 resampled[y*s_resample_width*4 + x*4 + 1] = tmp[1];
1043 resampled[y*s_resample_width*4 + x*4 + 2] = tmp[2];
1044 resampled[y*s_resample_width*4 + x*4 + 3] = tmp[3];
1048 sprintf( buffer, "%svideo/%s/uc%04d.tga", gamedir, s_base, frame );
1049 WriteTGA( buffer, resampled, s_resample_width, s_resample_height );
1053 else if ( s_compression_method == BTC_COMPRESSION )
1055 error = BTCCompressFrame( resampled, compressed );
1059 if ( error > maxError )
1062 printf( " (error = %f)\n", error );
1063 fwrite( compressed, 1, 2 * sizeof( long ) * ( s_resample_width / 4 ) * ( s_resample_height / 4 ), output );
1068 unsigned char *uncompressed;
1071 uncompressed = malloc( sizeof( unsigned char ) * 4 * s_resample_width * s_resample_height );
1072 BTCDecompressFrame( compressed, uncompressed );
1074 for ( y = 0; y < s_resample_height/2; y++ )
1076 for ( x = 0; x < s_resample_width; x++ )
1078 unsigned char tmp[4];
1080 tmp[0] = uncompressed[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 0];
1081 tmp[1] = uncompressed[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 1];
1082 tmp[2] = uncompressed[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 2];
1083 tmp[3] = uncompressed[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 3];
1085 uncompressed[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 0] = uncompressed[y*s_resample_width*4 + x*4 + 0];
1086 uncompressed[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 1] = uncompressed[y*s_resample_width*4 + x*4 + 1];
1087 uncompressed[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 2] = uncompressed[y*s_resample_width*4 + x*4 + 2];
1088 uncompressed[(s_resample_height-1-y)*s_resample_width*4 + x*4 + 3] = uncompressed[y*s_resample_width*4 + x*4 + 3];
1090 uncompressed[y*s_resample_width*4 + x*4 + 0] = tmp[0];
1091 uncompressed[y*s_resample_width*4 + x*4 + 1] = tmp[1];
1092 uncompressed[y*s_resample_width*4 + x*4 + 2] = tmp[2];
1093 uncompressed[y*s_resample_width*4 + x*4 + 3] = tmp[3];
1098 sprintf( buffer, "%svideo/%s/btc%04d.tga", gamedir, s_base, frame );
1099 WriteTGA( buffer, uncompressed, s_resample_width, s_resample_height );
1101 free( uncompressed );
1106 WriteSound( output, frame );
1114 printf ("Total size: %i\n", ftell( output ) );
1115 printf ("Average error: %f\n", sumError / ( frame - startframe ) );
1116 printf ("Max error: %f\n", maxError );
1118 fseconds = ( stop - start ) / 1000.0f;
1119 minutes = fseconds / 60;
1120 remSeconds = fseconds - minutes * 60;
1122 printf ("Total time: %d s (%d m %d s)\n", ( int ) fseconds, minutes, remSeconds );
1123 printf ("Time/frame: %.2f seconds\n", fseconds / ( frame - startframe ) );
1129 free( s_soundtrack );