00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "iq.h"
00012 #include <stdio.h>
00013
00014 IQ::IQ(
00015 const Id& n,
00016 In<Marker>& markerIn,
00017 In<VYApixel>& Cin,
00018 In<VYAimageDepth>& imageDepthIn,
00019 In<VYAimageComponent>& imageComponentIdIn,
00020 In<VYAimageH>& imageHIn,
00021 In<VYAimageV>& imageVIn,
00022 In<VYAimageDepth>& scanDepthIn,
00023 In<VYAimageComponent>& scanComponentIdIn,
00024 In<Bits>& QTableIn,
00025 In<VYAid>& QTableIdIn,
00026 Out<VYApixel>& Cout)
00027 :
00028 Process(n),
00029 markerInP( id("markerInP"), markerIn),
00030 CinP( id("CinP"), Cin),
00031 imageDepthInP( id("imageDepthInP"), imageDepthIn),
00032 imageComponentIdInP( id("imageComponentIdInP"),imageComponentIdIn),
00033 imageHInP( id("imageHInP"), imageHIn),
00034 imageVInP( id("imageVInP"), imageVIn),
00035 scanDepthInP( id("scanDepthInP"), scanDepthIn),
00036 scanComponentIdInP( id("scanComponentIdInP"), scanComponentIdIn),
00037 QTableInP( id("QTableInP"), QTableIn),
00038 QTableIdInP( id("QTableIdInP"), QTableIdIn),
00039 CoutP( id("CoutP"), Cout)
00040 {
00041 }
00042
00043 void IQ::main()
00044 {
00045 VYAimageDepth nrOfImageComponents;
00046 VYAimageComponent* imageComponent;
00047 VYAimageH* H;
00048 VYAimageV* V;
00049 VYAid* tid;
00050 VYApixel Cin;
00051 VYApixel Cout;
00052 Marker marker;
00053
00054 read(markerInP, marker);
00055 while (marker == DQT_MK)
00056 {
00057 load_quant_tables();
00058 read(markerInP, marker);
00059 }
00060
00061 read(imageDepthInP, nrOfImageComponents);
00062
00063 imageComponent = new VYAimageComponent[nrOfImageComponents];
00064 H = new VYAimageH[nrOfImageComponents];
00065 V = new VYAimageV[nrOfImageComponents];
00066 tid = new VYAid[nrOfImageComponents];
00067
00068 for(unsigned int i=0; i<nrOfImageComponents; i++)
00069 {
00070 read(imageComponentIdInP, imageComponent[i]);
00071 read(imageHInP, H[i]);
00072 read(imageVInP, V[i]);
00073 read(QTableIdInP, tid[i]);
00074 }
00075
00076 while (true)
00077 {
00078 VYAimageDepth nrOfScanComponents;
00079 VYAimageComponent* scanComponentId;
00080
00081 read(scanDepthInP, nrOfScanComponents);
00082 assert(nrOfScanComponents == 3);
00083
00084 scanComponentId = new VYAimageComponent[nrOfScanComponents];
00085
00086 for(unsigned int i=0; i<nrOfScanComponents; i++)
00087 {
00088 read(scanComponentIdInP, scanComponentId[i]);
00089 }
00090
00091 while (true)
00092 {
00093 for(unsigned int i=0; i<nrOfScanComponents; i++)
00094 {
00095 int hi = H[scanComponentId[i]];
00096 int vi = V[scanComponentId[i]];
00097 int ti = tid[scanComponentId[i]];
00098
00099 for(int j=0; j<hi; j++)
00100 {
00101 for(int k=0; k<vi; k++)
00102 {
00103 for(unsigned int l=0; l<64; l++)
00104 {
00105 read(CinP, Cin);
00106 Cout = QTable[ti][l]*Cin;
00107 write(CoutP, Cout);
00108 }
00109 }
00110 }
00111 }
00112 }
00113 }
00114
00115 delete [] imageComponent;
00116 delete [] H;
00117 delete [] V;
00118 delete [] tid;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127 int IQ::load_quant_tables()
00128 {
00129 Bits aux;
00130 unsigned int size, n, i, tid, x;
00131 int result;
00132
00133 get_size(size);
00134 n = (size-2)/65;
00135
00136 for (i=0; i<n; i++)
00137 {
00138 read(QTableInP, aux);
00139 if (first_quad(aux) > 0)
00140 {
00141 printf("%s:\n\tERROR:\tBad QTable precision!\n", fullName());
00142 result = -1;
00143 return result;
00144 }
00145 tid = second_quad(aux);
00146 #ifdef VERBOSE
00147 printf("%s:\n\tLoading Quantization Table %d\n", fullName(), tid);
00148 #endif
00149 for (x=0;x<64;x++)
00150 {
00151 read(QTableInP, aux);
00152 QTable[tid][x] = aux;
00153 }
00154 }
00155 result = 0;
00156 return result;
00157 }
00158
00159 void IQ::get_size(unsigned int& size)
00160 {
00161 Bits firstc;
00162 Bits nextc;
00163
00164 read(QTableInP, firstc);
00165 size = firstc;
00166 read(QTableInP, nextc);
00167 size = (size<<8) | nextc;
00168 }
00169