Main Page | Namespace List | Compound List | File List | Compound Members | File Members

sof.cc

Go to the documentation of this file.
00001 /*--------------------------------------------------------------------
00002  *
00003  * (C) Copyright Koninklijke Philips Electronics NV 2006. 
00004  * All rights reserved. This software is licensed under the terms of
00005  * version 2.1 of the GNU Lesser General Public License as published 
00006  * by the Free Software Foundation. For licensing and warranty
00007  * information, see the file COPYING in the main directory.
00008  *
00009  *------------------------------------------------------------------*/
00010 
00011 #include "sof.h"
00012 #include <stdio.h>
00013 
00014 SOF::SOF(
00015   const Id&     n, 
00016   In<Bits>&     frameHeaderBitsIn,
00017   Out<VYAimageDepth>& imageDepthOut,
00018   Out<VYAimageComponent>& imageComponentIdOut,
00019   Out<VYAimageWidth>& imageWidthOut,
00020   Out<VYAimageHeight>&  imageHeightOut,
00021   Out<VYAimageH>&   imageHOut,
00022   Out<VYAimageV>&   imageVOut,
00023   Out<VYAid>&   QtableIdOut)
00024 :
00025         Process(    n),
00026         frameHeaderBitsInP( id("frameHeaderBitsInP"), frameHeaderBitsIn),
00027         imageDepthOutP(   id("imageDepthOutP"),     imageDepthOut),
00028   imageComponentIdOutP( id("imageComponentIdOutP"), imageComponentIdOut),
00029         imageWidthOutP(   id("imageWidthOutP"),     imageWidthOut),
00030         imageHeightOutP(  id("imageHeightOutP"),    imageHeightOut),
00031         imageHOutP(   id("imageHOutP"),   imageHOut),
00032         imageVOutP(   id("imageVOutP"),     imageVOut),
00033   QtableIdOutP(   id("QtableIdOutP"),     QtableIdOut)  
00034 { 
00035 }
00036 
00037 void SOF::get_size(unsigned int& size)
00038 {
00039   Bits firstc;
00040   Bits nextc;
00041 
00042   read(frameHeaderBitsInP, firstc);
00043   size = firstc;
00044   read(frameHeaderBitsInP, nextc);
00045   size = (size<<8) | nextc; // big endian
00046 }
00047 
00048 
00049 void SOF::main()
00050 {
00051   Bits      aux;  
00052   VYAimageDepth   numberOfComponents;
00053   VYAimageComponent imageComponentId;
00054   VYAimageWidth   imageWidth;
00055   VYAimageHeight    imageHeight;
00056   VYAimageH     imageH;
00057   VYAimageV     imageV;
00058   VYAid     QTableId;
00059   
00060   unsigned int    numberOfBlocks = 0;
00061   
00062   while (true)
00063   {
00064     read(frameHeaderBitsInP, aux);      // section length (1st byte)
00065     read(frameHeaderBitsInP, aux);      // section length (2nd byte)
00066     read(frameHeaderBitsInP, aux);      // sample precision
00067     get_size(imageHeight);        // vertical resolution
00068     write(imageHeightOutP, imageHeight);
00069     get_size(imageWidth);       // horizontal resolution
00070     write(imageWidthOutP, imageWidth);
00071 
00072     read(frameHeaderBitsInP, numberOfComponents);   // number of image components
00073     write(imageDepthOutP, numberOfComponents);
00074     
00075     int* format = new int [numberOfComponents];
00076     for (unsigned int i=0; i<numberOfComponents; i++) 
00077     {
00078             /* component specifiers */
00079             read(frameHeaderBitsInP, aux);      // component ID
00080       imageComponentId = aux-1;       // map ID domain from {1,2,3} to {0,1,2}
00081       write(imageComponentIdOutP,imageComponentId);
00082             read(frameHeaderBitsInP, aux);      // sampling factor
00083             imageH = first_quad(aux);
00084       write(imageHOutP, imageH);
00085             imageV = second_quad(aux);
00086       write(imageVOutP, imageV);
00087       format[i] = imageH*imageV;
00088             read(frameHeaderBitsInP, QTableId);   // quantization table ID
00089       write(QtableIdOutP, QTableId);
00090     
00091       numberOfBlocks += imageH * imageV;
00092             if (numberOfBlocks > 10)
00093       {
00094                     printf("%s:\tERROR:\tMax subsampling exceeded!\n",fullName());
00095               abort();
00096                 }
00097  
00098         }
00099 
00100     #ifdef VERBOSE
00101         if (numberOfComponents == 3) 
00102       {
00103         if ((format[0] == format[1]) && (format[0] == format[2])) {
00104           printf("%s:\n\tImage size is %d by %d\n\tColor format is 4:4:4\n", fullName(), imageWidth, imageHeight);
00105         } else if ((format[0] == 2*format[1]) && (format[0] == 2*format[2])) {
00106           printf("%s:\n\tImage size is %d by %d\n\tColor format is 4:2:2\n", fullName(), imageWidth, imageHeight);
00107         } else if ((format[0] == 4*format[1]) && (format[0] == 4*format[2])) {
00108           printf("%s:\n\tImage size is %d by %d\n\tColor format is 4:2:0\n", fullName(), imageWidth, imageHeight);
00109         }
00110       } else if (numberOfComponents == 1) {
00111         printf("%s:\n\tImage size is %d by %d\n\tMonochrome JPEG image\n", fullName(), imageWidth, imageHeight);
00112       } else {
00113         printf("%s:\n\tImage size is %d by %d\n\tColor format is no JPEG File Interchange Format (JFIF)!\n", fullName(), imageWidth, imageHeight);
00114         exit(1);  
00115       }
00116     #endif
00117     
00118     delete [] format;
00119   }
00120 }

Generated on Wed Feb 15 14:52:45 2006 for jpegdec by doxygen 1.3.2