about summary refs log tree commit diff
path: root/converter/ppm/ppmtompeg/iframe.c
diff options
context:
space:
mode:
Diffstat (limited to 'converter/ppm/ppmtompeg/iframe.c')
-rw-r--r--converter/ppm/ppmtompeg/iframe.c109
1 files changed, 56 insertions, 53 deletions
diff --git a/converter/ppm/ppmtompeg/iframe.c b/converter/ppm/ppmtompeg/iframe.c
index 66f5ea3b..2bc50196 100644
--- a/converter/ppm/ppmtompeg/iframe.c
+++ b/converter/ppm/ppmtompeg/iframe.c
@@ -239,7 +239,7 @@ void
 SetBlocksPerSlice(void) {
 
     int     totalBlocks;
-    
+
     totalBlocks = (Fsize_y>>4)*(Fsize_x>>4);
 
     if ( slicesPerFrame > totalBlocks ) {
@@ -296,7 +296,7 @@ CalcDistortion(MpegFrame * const current,
     Block decblk;
     FlatBlock fblk;
     int datarate = 0;
-  
+
     for (qscale = 1; qscale < 32; qscale ++) {
         distort = 0;
         datarate = 0;
@@ -361,7 +361,7 @@ CalcDistortion(MpegFrame * const current,
  *
  *===========================================================================*/
 void
-GenIFrame(BitBucket * const bb, 
+GenIFrame(BitBucket * const bb,
           MpegFrame * const current) {
 
     int x, y;
@@ -391,25 +391,25 @@ GenIFrame(BitBucket * const bb,
             lastIFrame = current->id;
         } else {
             /* ASSUMES 30 FRAMES PER SECOND */
-    
+
             if (! realQuiet) {
                 fprintf(stdout, "I-to-I (frames %5d to %5d) bitrate:  %8d\n",
                         lastIFrame, current->id-1,
                         ((bb->cumulativeBits-lastNumBits)*30)/
                         (current->id-lastIFrame));
             }
-    
+
             fprintf(bitRateFile, "I-to-I (frames %5d to %5d) bitrate:  %8d\n",
                     lastIFrame, current->id-1,
                     ((bb->cumulativeBits-lastNumBits)*30)/
                     (current->id-lastIFrame));
-            lastNumBits = bb->cumulativeBits;       
+            lastNumBits = bb->cumulativeBits;
             lastIFrame = current->id;
         }
     }
-    
+
     startTime = time_elapsed();
-    
+
     Frame_AllocBlocks(current);
     BlockifyFrame(current);
 
@@ -435,13 +435,13 @@ GenIFrame(BitBucket * const bb,
         }
     }
     Mhead_GenSliceHeader(bb, 1, QScale, NULL, 0);
-    
+
     if ( referenceFrame == DECODED_FRAME ) {
         Frame_AllocDecoded(current, TRUE);
     } else if ( printSNR ) {
         Frame_AllocDecoded(current, FALSE);
     }
-    
+
     y_dc_pred = cr_dc_pred = cb_dc_pred = 128;
     totalBits = bb->cumulativeBits;
     mbAddress = 0;
@@ -449,24 +449,24 @@ GenIFrame(BitBucket * const bb,
     /* DCT the macroblocks */
     for (y = 0;  y < (Fsize_y >> 3);  y += 2) {
         for (x = 0;  x < (Fsize_x >> 3);  x += 2) {
-            if (collect_quant && (collect_quant_detailed & 1)) 
+            if (collect_quant && (collect_quant_detailed & 1))
                 fprintf(collect_quant_fp, "l\n");
             if (DoLaplace) {LaplaceCnum = 0;}
             mp_fwd_dct_block2(current->y_blocks[y][x], dct[y][x]);
             mp_fwd_dct_block2(current->y_blocks[y][x+1], dct[y][x+1]);
             mp_fwd_dct_block2(current->y_blocks[y+1][x], dct[y+1][x]);
             mp_fwd_dct_block2(current->y_blocks[y+1][x+1], dct[y+1][x+1]);
-            if (collect_quant && (collect_quant_detailed & 1)) 
+            if (collect_quant && (collect_quant_detailed & 1))
                 fprintf(collect_quant_fp, "c\n");
             if (DoLaplace) {LaplaceCnum = 1;}
-            mp_fwd_dct_block2(current->cb_blocks[y>>1][x>>1], 
+            mp_fwd_dct_block2(current->cb_blocks[y>>1][x>>1],
                               dctb[y>>1][x>>1]);
             if (DoLaplace) {LaplaceCnum = 2;}
-            mp_fwd_dct_block2(current->cr_blocks[y>>1][x>>1], 
+            mp_fwd_dct_block2(current->cr_blocks[y>>1][x>>1],
                               dctr[y>>1][x>>1]);
         }
     }
-    
+
     if (DoLaplace)
         CalcLambdas();
 
@@ -474,13 +474,13 @@ GenIFrame(BitBucket * const bb,
         for (x = 0;  x < (Fsize_x >> 3);  x += 2) {
             /* Check for Qscale change */
             if (specificsOn) {
-                newQScale = 
+                newQScale =
                     SpecLookup(current->id, 2, mbAddress, &info, QScale);
                 if (newQScale != -1) {
                     QScale = newQScale;
                 }
             }
-    
+
             /*  Determine if new Qscale needed for Rate Control purposes  */
             if (bitstreamMode == FIXED_RATE) {
                 rc_blockStart = bb->cumulativeBits;
@@ -493,20 +493,20 @@ GenIFrame(BitBucket * const bb,
                     QScale = newQScale;
                 }
             }
-    
+
             if ( (mbAddress % blocksPerSlice == 0) && (mbAddress != 0) ) {
                 /* create a new slice */
                 if (specificsOn) {
                     /* Make sure no slice Qscale change */
                     newQScale = SpecLookup(current->id, 1,
-                                           mbAddress/blocksPerSlice, &info, 
+                                           mbAddress/blocksPerSlice, &info,
                                            QScale);
                     if (newQScale != -1) QScale = newQScale;
                 }
                 Mhead_GenSliceEnder(bb);
                 Mhead_GenSliceHeader(bb, 1+(y>>1), QScale, NULL, 0);
                 y_dc_pred = cr_dc_pred = cb_dc_pred = 128;
-      
+
                 GEN_I_BLOCK(I_FRAME, current, bb, 1+(x>>1), QScale);
             } else {
                 GEN_I_BLOCK(I_FRAME, current, bb, 1, QScale);
@@ -515,23 +515,23 @@ GenIFrame(BitBucket * const bb,
             if (WriteDistortionNumbers) {
                 CalcDistortion(current, y, x);
             }
-    
+
             if ( decodeRefFrames ) {
                 /* now, reverse the DCT transform */
                 LaplaceCnum = 0;
                 for ( index = 0; index < 6; index++ ) {
                     if (!DoLaplace) {
-                        Mpost_UnQuantZigBlock(fb[index], dec[index], QScale, 
+                        Mpost_UnQuantZigBlock(fb[index], dec[index], QScale,
                                               TRUE);
                     } else {
                         if (index == 4) {LaplaceCnum = 1;}
                         if (index == 5) {LaplaceCnum = 2;}
-                        Mpost_UnQuantZigBlockLaplace(fb[index], dec[index], 
+                        Mpost_UnQuantZigBlockLaplace(fb[index], dec[index],
                                                      QScale, TRUE);
                     }
-                    mpeg_jrevdct((int16 *)dec[index]);      
+                    mpeg_jrevdct((int16 *)dec[index]);
                 }
-      
+
                 /* now, unblockify */
                 BlockToData(current->decoded_y, dec[0], y, x);
                 BlockToData(current->decoded_y, dec[1], y, x+1);
@@ -540,7 +540,7 @@ GenIFrame(BitBucket * const bb,
                 BlockToData(current->decoded_cb, dec[4], y>>1, x>>1);
                 BlockToData(current->decoded_cr, dec[5], y>>1, x>>1);
             }
-    
+
             numBlocks++;
             mbAddress++;
             /*   Rate Control */
@@ -551,43 +551,43 @@ GenIFrame(BitBucket * const bb,
             }
         }
     }
-    
+
     if ( printSNR ) {
         BlockComputeSNR(current,snr,psnr);
         totalSNR += snr[0];
         totalPSNR += psnr[0];
     }
-    
+
     numBits += (bb->cumulativeBits-totalBits);
-    
+
     DBG_PRINT(("End of frame\n"));
-    
+
     Mhead_GenSliceEnder(bb);
     /*   Rate Control  */
     if (bitstreamMode == FIXED_RATE) {
         updateRateControl(TYPE_IFRAME);
     }
-    
+
     endTime = time_elapsed();
     totalTime += (endTime-startTime);
-    
+
     numFrameBits += (bb->cumulativeBits-totalFrameBits);
-    
+
     if ( showBitRatePerFrame ) {
         /* ASSUMES 30 FRAMES PER SECOND */
         fprintf(bitRateFile, "%5d\t%8d\n", current->id,
                 30*(bb->cumulativeBits-totalFrameBits));
     }
-    
+
     if ( frameSummary && !realQuiet ) {
-        
+
         /* ASSUMES 30 FRAMES PER SECOND */
-        fprintf(stdout, 
-                "FRAME %d (I):  %ld seconds  (%d bits/s output)\n", 
+        fprintf(stdout,
+                "FRAME %d (I):  %ld seconds  (%d bits/s output)\n",
                 current->id, (long)((endTime-startTime)/TIME_RATE),
                 30*(bb->cumulativeBits-totalFrameBits));
         if ( printSNR ) {
-            fprintf(stdout, 
+            fprintf(stdout,
                     "FRAME %d:  SNR:  %.1f\t%.1f\t%.1f\t"
                     "PSNR:  %.1f\t%.1f\t%.1f\n",
                         current->id, snr[0], snr[1], snr[2],
@@ -628,8 +628,8 @@ IFrameTotalTime(void) {
 
 
 void
-ShowIFrameSummary(unsigned int const inputFrameBits, 
-                  unsigned int const totalBits, 
+ShowIFrameSummary(unsigned int const inputFrameBits,
+                  unsigned int const totalBits,
                   FILE *       const fpointer) {
 /*----------------------------------------------------------------------------
    Print out statistics on all I frames.
@@ -697,12 +697,12 @@ EncodeYDC(int32       const dc_term,
 
     ydiff = (dc_term - (*pred_term));
     if (ydiff > 255) {
-#ifdef BLEAH 
+#ifdef BLEAH
       fprintf(stdout, "TRUNCATED\n");
 #endif
     ydiff = 255;
     } else if (ydiff < -255) {
-#ifdef BLEAH 
+#ifdef BLEAH
       fprintf(stdout, "TRUNCATED\n");
 #endif
     ydiff = -255;
@@ -753,12 +753,12 @@ EncodeCDC(int32       const dc_term,
     cdiff = (dc_term - (*pred_term));
     if (cdiff > 255) {
 #ifdef BLEAH
-        fprintf(stdout, "TRUNCATED\n"); 
+        fprintf(stdout, "TRUNCATED\n");
 #endif
         cdiff = 255;
     } else if (cdiff < -255) {
 #ifdef BLEAH
-        fprintf(stdout, "TRUNCATED\n"); 
+        fprintf(stdout, "TRUNCATED\n");
 #endif
         cdiff = -255;
     }
@@ -789,21 +789,21 @@ BlockComputeSNR(MpegFrame * const current,
     int32 varDiff[3];
     double    ratio[3];
     double    total[3];
-    uint8 **origY=current->orig_y, **origCr=current->orig_cr, 
+    uint8 **origY=current->orig_y, **origCr=current->orig_cr,
         **origCb=current->orig_cb;
-    uint8 **newY=current->decoded_y, **newCr=current->decoded_cr, 
+    uint8 **newY=current->decoded_y, **newCr=current->decoded_cr,
         **newCb=current->decoded_cb;
     static int32       **SignalY,  **NoiseY;
     static int32       **SignalCb, **NoiseCb;
     static int32       **SignalCr, **NoiseCr;
     static short   ySize[3], xSize[3];
     static boolean needs_init=TRUE;
-  
+
     /* Init */
     if (needs_init) {
         int ysz = (Fsize_y>>3) * sizeof(int32 *);
         int xsz = (Fsize_x>>3);
-    
+
         needs_init = FALSE;
         for (y=0; y<3; y++) {
             varDiff[y] = ratio[y] = total[y] = 0.0;
@@ -817,7 +817,7 @@ BlockComputeSNR(MpegFrame * const current,
         NoiseCb  = (int32 **) malloc(ysz);
         SignalCr = (int32 **) malloc(ysz);
         NoiseCr  = (int32 **) malloc(ysz);
-        if (SignalY == NULL || NoiseY == NULL || SignalCr == NULL || 
+        if (SignalY == NULL || NoiseY == NULL || SignalCr == NULL ||
             NoiseCb == NULL || SignalCb == NULL || NoiseCr == NULL) {
             fprintf(stderr, "Out of memory in BlockComputeSNR\n");
             exit(-1);
@@ -840,7 +840,7 @@ BlockComputeSNR(MpegFrame * const current,
             memset((char *) &SignalCr[y][0], 0, (xSize[0]>>3) * 4);
         }
     }
-  
+
     /* find all the signal and noise */
     for (y = 0; y < ySize[0]; y++) {
         for (x = 0; x < xSize[0]; x++) {
@@ -863,7 +863,7 @@ BlockComputeSNR(MpegFrame * const current,
             tempInt = origCr[y][x];
             SignalCr[y>>3][x>>3] += tempInt*tempInt;
         }}
-  
+
     /* Now sum up that noise */
     for(y=0; y<Fsize_y>>4; y++){
         for(x=0; x<Fsize_x>>4; x++){
@@ -874,7 +874,7 @@ BlockComputeSNR(MpegFrame * const current,
         }
         if (printMSE) puts("");
     }
-  
+
     /* Now look at those ratios! */
     for(y=0; y<Fsize_y>>4; y++){
         for(x=0; x<Fsize_x>>4; x++){
@@ -882,7 +882,7 @@ BlockComputeSNR(MpegFrame * const current,
             ratio[1] += (double)SignalCb[y][x]/(double)varDiff[1];
             ratio[2] += (double)SignalCr[y][x]/(double)varDiff[2];
         }}
-  
+
     for (x=0; x<3; x++) {
         snr[x] = 10.0 * log10(ratio[x]);
         psnr[x] = 20.0 * log10(255.0/sqrt((double)varDiff[x]/
@@ -983,3 +983,6 @@ int32 time_elapsed(void) {
     return timeBuffer.tms_utime + timeBuffer.tms_stime;
 #endif
 }
+
+
+