Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4JpegCoder Class Reference

#include <G4RTJpegCoder.hh>

Collaboration diagram for G4JpegCoder:

Public Member Functions

 G4JpegCoder (u_char *colorR, u_char *colorG, u_char *colorB)
 
 ~G4JpegCoder (void)
 
void GetJpegData (char **aJpegData, int &size)
 
void SetJpegProperty (const G4JpegProperty &aProperty)
 
int DoCoding (void)
 

Protected Member Functions

void CodeMCU ()
 
void makeYCC (int ux, int uy)
 
void CodeHuffman (int cs)
 
void ForwardDCT (int *picData)
 
void Quantization (int cs)
 
void WriteHeader (void)
 
void WriteEOI (void)
 

Protected Attributes

u_charmRgb [3]
 
int mYBlock [4][64]
 
int mCbBlock [64]
 
int mCrBlock [64]
 
double mCosT [8][8]
 
int mDCTData [64]
 
int mPreDC [3]
 
G4JpegProperty mProperty
 
int mNumVUnits
 
int mNumHUnits
 
G4OutBitStreammOBSP
 

Detailed Description

Definition at line 51 of file G4RTJpegCoder.hh.

Constructor & Destructor Documentation

G4JpegCoder::G4JpegCoder ( u_char colorR,
u_char colorG,
u_char colorB 
)

Definition at line 43 of file G4RTJpegCoder.cc.

44 {
45  mRgb[0] = colorR;
46  mRgb[1] = colorG;
47  mRgb[2] = colorB;
48 
49  mPreDC[0] = mPreDC[1] = mPreDC[2] = 0;
50  mOBSP = 0;
51 
52  for(int n=0; n<8; n++)
53  for(int im=0; im<8; im++)
54  mCosT[n][im] = std::cos((2 * im + 1) * n * PaiDiv16);
55 }
const double PaiDiv16
Definition: G4RTJpeg.hh:48
const G4int n
G4OutBitStream * mOBSP
double mCosT[8][8]
u_char * mRgb[3]
G4JpegCoder::~G4JpegCoder ( void  )

Definition at line 57 of file G4RTJpegCoder.cc.

58 {}

Member Function Documentation

void G4JpegCoder::CodeHuffman ( int  cs)
protected

Definition at line 187 of file G4RTJpegCoder.cc.

188 {
189  const G4HuffmanCodeTable& dcT = cs ? CDcHuffmanT : YDcHuffmanT;
190  const G4HuffmanCodeTable& acT = cs ? CAcHuffmanT : YAcHuffmanT;
191  const int eobIdx = cs ? CEOBidx : YEOBidx;
192  const int zrlIdx = cs ? CZRLidx : YZRLidx;
193 
194  int diff = mDCTData[0] - mPreDC[cs];
195  mPreDC[cs] = mDCTData[0];
196  int absDiff = std::abs(diff);
197  int dIdx = 0;
198 
199  while(absDiff > 0){
200  absDiff >>= 1;
201  dIdx++;
202  }
203  if(dIdx > dcT.numOfElement)
204  throw(G4IndexError(dcT.numOfElement, dIdx, "CodeHuffman:DC"));
205  mOBSP->SetBits((dcT.CodeT)[dIdx], (dcT.SizeT)[dIdx]);
206 
207  if(dIdx){
208  if(diff < 0)
209  diff--;
210  mOBSP->SetBits(diff, dIdx);
211  }
212 
213  int run = 0;
214  for(int n=1; n<64; n++){
215  int absCoefficient = std::abs( mDCTData[ Zigzag[n] ] );
216  if( absCoefficient ){
217  while( run > 15 ){
218  mOBSP->SetBits((acT.CodeT)[zrlIdx], (acT.SizeT)[zrlIdx]);
219  run -= 16;
220  }
221  int is = 0;
222  while( absCoefficient > 0 ){
223  absCoefficient >>= 1;
224  is++;
225  }
226  int aIdx = run * 10 + is + (run == 15);
227  if( aIdx >= acT.numOfElement )
228  throw( G4IndexError( acT.numOfElement, aIdx, "CodeHuffman:AC" )
229  );
230  mOBSP->SetBits( (acT.CodeT)[aIdx], (acT.SizeT)[aIdx] );
231  int v = mDCTData[ Zigzag[n] ];
232  if( v < 0 )
233  v--;
234  mOBSP->SetBits( v, is );
235  run = 0;
236  }
237  else{
238  if(n == 63)
239  mOBSP->SetBits( (acT.CodeT)[eobIdx], (acT.SizeT)[eobIdx] );
240  else
241  run++;
242  }
243  }
244 }
static const int YEOBidx
int mDCTData[64]
static const G4HuffmanCodeTable YAcHuffmanT
static const G4HuffmanCodeTable CAcHuffmanT
static const int Zigzag[64]
Definition: G4RTJpeg.hh:51
static const G4HuffmanCodeTable YDcHuffmanT
const G4int n
static const int YZRLidx
tuple v
Definition: test.py:18
G4OutBitStream * mOBSP
static const int CZRLidx
static const int CEOBidx
static const G4HuffmanCodeTable CDcHuffmanT
void SetBits(int v, int numBits)

Here is the call graph for this function:

Here is the caller graph for this function:

void G4JpegCoder::CodeMCU ( void  )
protected

Definition at line 116 of file G4RTJpegCoder.cc.

117 {
118  for(int n=0; n<4; n++){
119  ForwardDCT(mYBlock[n]);
120  Quantization(0);
121  CodeHuffman(0);
122  }
124  Quantization(1);
125  CodeHuffman(1);
126 
128  Quantization(2);
129  CodeHuffman(2);
130 }
void ForwardDCT(int *picData)
void CodeHuffman(int cs)
void Quantization(int cs)
int mCbBlock[64]
const G4int n
int mYBlock[4][64]
int mCrBlock[64]

Here is the call graph for this function:

Here is the caller graph for this function:

int G4JpegCoder::DoCoding ( void  )

Definition at line 75 of file G4RTJpegCoder.cc.

76 {
77  mNumVUnits = (mProperty.nRow / 16) + ((mProperty.nRow % 16) ? 1 : 0);
78  mNumHUnits = (mProperty.nColumn / 16) + ((mProperty.nColumn % 16) ? 1 : 0);
79 
80  int size = mProperty.nColumn * mProperty.nRow * 3;
81  if(size < 10240)
82  size = 10240;
83 
84  try{
85  mOBSP = new G4OutBitStream(size);
86  WriteHeader();
87  for(int yu=0; yu<mNumVUnits; yu++){
88  for(int xu=0; xu<mNumHUnits; xu++){
89  makeYCC(xu, yu);
90 
91  //mRgb->YCrCb
92  #ifdef GRAY
93  for(int i=0; i<64; i++)
94  mCbBlock[i] = mCrBlock[i] = 0;
95  #endif
96  CodeMCU();
97  }
98  }
99  WriteEOI();
100  return M_NoError;
101  }
102 
103  catch(G4MemoryError &me){
104  return M_RuntimeError;
105  }
106  catch(G4BufferError &be){
107  return M_RuntimeError;
108  }
109  catch(G4IndexError &ie){
110  return M_RuntimeError;
111  }
112 }
void WriteEOI(void)
void WriteHeader(void)
int mCbBlock[64]
G4JpegProperty mProperty
G4OutBitStream * mOBSP
void makeYCC(int ux, int uy)
int mCrBlock[64]

Here is the call graph for this function:

Here is the caller graph for this function:

void G4JpegCoder::ForwardDCT ( int picData)
protected

Definition at line 258 of file G4RTJpegCoder.cc.

259 {
260  for( int v=0; v<8; v++ ){
261  double cv = v ? 1.0 : DisSqrt2;
262  for( int u=0; u<8; u++ ){
263  double cu = u ? 1.0 : DisSqrt2;
264  double sum = 0;
265  for( int y=0; y<8; y++ )
266  for( int x=0; x<8; x++ )
267  sum += picData[ y * 8 + x ] * mCosT[u][x] * mCosT[v][y];
268  mDCTData[ v * 8 + u ] = int( sum * cu * cv / 4 );
269  }
270  }
271 }
int mDCTData[64]
const double DisSqrt2
Definition: G4RTJpeg.hh:47
tuple x
Definition: test.py:50
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
tuple v
Definition: test.py:18
double mCosT[8][8]

Here is the call graph for this function:

Here is the caller graph for this function:

void G4JpegCoder::GetJpegData ( char **  aJpegData,
int size 
)

Definition at line 61 of file G4RTJpegCoder.cc.

62 {
63  if (mOBSP != 0){
64  *aJpegData = (char*)mOBSP->GetStreamAddress();
65  size = mOBSP->GetStreamSize();
66  }
67  else{
68  *aJpegData = 0;
69  size = 0;
70  }
71 
72 }
G4OutBitStream * mOBSP
int GetStreamSize(void)
u_char * GetStreamAddress(void)

Here is the call graph for this function:

Here is the caller graph for this function:

void G4JpegCoder::makeYCC ( int  ux,
int  uy 
)
protected

Definition at line 133 of file G4RTJpegCoder.cc.

134 {
135  u_char rv, gv, bv;
136  int tCrBlock[4][64];
137  int tCbBlock[4][64];
138 
139  for(int u=0; u<4; u++){
140  int *yp = mYBlock[u];
141  int *cbp = tCbBlock[u];
142  int *crp = tCrBlock[u];
143 
144  int sx = ux * 16 + ((u&1) ? 8 : 0);
145  int ex = sx + 8;
146  int sy = uy * 16 + ((u>1) ? 8 : 0);
147  int ey = sy + 8;
148 
149  for(int iv=sy; iv<ey; iv++){
150  int ii = iv < mProperty.nRow ? iv : mProperty.nRow - 1;
151  for(int ih=sx; ih<ex; ih++){
152  int jj = ih < mProperty.nColumn ? ih : mProperty.nColumn - 1;
153  int index = ii * mProperty.nColumn + jj;
154  rv = mRgb[0][index];
155  gv = mRgb[1][index];
156  bv = mRgb[2][index];
157 
158  *yp++ = int((0.2990 * rv) + (0.5870 * gv) + (0.1140 * bv) - 128)
159 ;
160  *cbp++ = int(-(0.1687 * rv) - (0.3313 * gv) + (0.5000 * bv));
161  *crp++ = int((0.5000 * rv) - (0.4187 * gv) - (0.0813 * bv));
162  } // ih
163  } //iv
164  } //u
165 
166  int n = 0;
167  for(int b=0; b<4; b++){
168  switch(b){
169  case 0: n=0; break;
170  case 1: n=4; break;
171  case 2: n=32; break;
172  case 3: n=36;
173  }
174  for(int y=0; y<8; y+=2){
175  for(int x=0; x<8; x+=2){
176  int idx = y * 8 + x;
177  mCrBlock[n] = tCrBlock[b][idx];
178  mCbBlock[n] = tCbBlock[b][idx];
179  n++;
180  }
181  n += 4;
182  }
183  }
184 }
tuple x
Definition: test.py:50
tuple b
Definition: test.py:12
int mCbBlock[64]
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
const G4int n
G4JpegProperty mProperty
int mYBlock[4][64]
unsigned char u_char
Definition: G4RTJpeg.hh:40
int mCrBlock[64]
u_char * mRgb[3]

Here is the call graph for this function:

Here is the caller graph for this function:

void G4JpegCoder::Quantization ( int  cs)
protected

Definition at line 248 of file G4RTJpegCoder.cc.

249 {
250  int* qt = (int*)(cs ? CQuantumT : YQuantumT);
251  for( int i=0; i<64; i++ ){
252  mDCTData[i] /= qt[i];
253  }
254 }
int mDCTData[64]
static const int CQuantumT[]
static const int YQuantumT[]

Here is the caller graph for this function:

void G4JpegCoder::SetJpegProperty ( const G4JpegProperty aProperty)

Definition at line 367 of file G4RTJpegCoder.cc.

368 {
369  mProperty = aProperty;
370  mProperty.Dimension = 3;
372  mProperty.Format = 1;
375  mProperty.HThumbnail = 0;
376  mProperty.VThumbnail = 0;
377 }
u_char MinorRevisions
Definition: G4RTJpeg.hh:164
int SamplePrecision
Definition: G4RTJpeg.hh:160
G4JpegProperty mProperty
u_char MajorRevisions
Definition: G4RTJpeg.hh:163

Here is the caller graph for this function:

void G4JpegCoder::WriteEOI ( void  )
protected

Definition at line 359 of file G4RTJpegCoder.cc.

360 {
361  mOBSP->SetByte( M_Marker );
362  mOBSP->SetByte( M_EOI );
363 }
void SetByte(u_char dat)
G4OutBitStream * mOBSP

Here is the call graph for this function:

Here is the caller graph for this function:

void G4JpegCoder::WriteHeader ( void  )
protected

Definition at line 275 of file G4RTJpegCoder.cc.

276 {
277  int i = 0; //counter
278  //SOI
279  mOBSP->SetByte( M_Marker ); //FF
280  mOBSP->SetByte( M_SOI ); //SOI
281 
282  //APP0(JFIF Header)
283  mOBSP->SetByte( M_Marker ); //FF
284  mOBSP->SetByte( M_APP0 ); //APP0
285  mOBSP->SetWord( JFIFLength ); //parameter
286  mOBSP->CopyByte( (char*)JFIF, 5 ); //"JFIF\0"
287  mOBSP->SetWord( JFIFVersion ); //Version
291  mOBSP->SetByte( 0 );
292  mOBSP->SetByte( 0 );
293 
294  //comment
295  if( mProperty.Comment != 0 ){
296  mOBSP->SetByte( M_Marker ); //FF
297  mOBSP->SetByte( M_COM ); //comment
298  int length = strlen( mProperty.Comment ) + 1;
299  mOBSP->SetWord( length + 2 );
300  mOBSP->CopyByte( mProperty.Comment, length );
301  }
302 
303  //DQT
304  mOBSP->SetByte( M_Marker );
305  mOBSP->SetByte( M_DQT );
306  mOBSP->SetWord( 67 );
307  mOBSP->SetByte( 0 );
308  for( i=0; i<64; i++ )
309  mOBSP->SetByte( u_char( YQuantumT[Zigzag[i]] ) );
310  mOBSP->SetByte( M_Marker );
311  mOBSP->SetByte( M_DQT );
312  mOBSP->SetWord( 67 );
313  mOBSP->SetByte( 1 );
314  for( i=0; i<64; i++ )
315  mOBSP->SetByte( u_char( CQuantumT[Zigzag[i]] ) );
316  // DHT
317  mOBSP->CopyByte( (char*)YDcDht, DcDhtLength );
318  mOBSP->CopyByte( (char*)CDcDht, DcDhtLength );
319  mOBSP->CopyByte( (char*)YAcDht, AcDhtLength );
320  mOBSP->CopyByte( (char*)CAcDht, AcDhtLength );
321 
322  // Frame Header
323  mOBSP->SetByte( M_Marker ); // FF
324  mOBSP->SetByte( M_SOF0 );
325  mOBSP->SetWord( 3 * mProperty.Dimension + 8 );
330 
331  mOBSP->SetByte( 0 );
332  mOBSP->SetByte( YSampleF );
333  mOBSP->SetByte( 0 );
334 
335  mOBSP->SetByte( 1 );
336  mOBSP->SetByte( CSampleF );
337 
338  mOBSP->SetByte( 1 );
339  mOBSP->SetByte( 2 );
340  mOBSP->SetByte( CSampleF );
341  mOBSP->SetByte( 1 );
342 
343  //Scan Header
344  mOBSP->SetByte( M_Marker );
345  mOBSP->SetByte( M_SOS );
346  mOBSP->SetWord( 2 * mProperty.Dimension + 6 );
348  for( i=0; i<mProperty.Dimension; i++ ){
349  mOBSP->SetByte( i );
350  mOBSP->SetByte( i==0 ? 0 : 0x11 );
351  }
352  mOBSP->SetByte( 0 ); //Ss
353  mOBSP->SetByte( 63 ); //Se
354  mOBSP->SetByte( 0 ); //Ah,Al
355 }
static const int AcDhtLength
const u_char YSampleF
void SetWord(u_int dat)
static const int CQuantumT[]
const u_int JFIFVersion
static const u_char CAcDht[]
static const u_char CDcDht[]
void SetByte(u_char dat)
int SamplePrecision
Definition: G4RTJpeg.hh:160
static const int Zigzag[64]
Definition: G4RTJpeg.hh:51
G4JpegProperty mProperty
G4OutBitStream * mOBSP
unsigned char u_char
Definition: G4RTJpeg.hh:40
static const int DcDhtLength
void CopyByte(const char *src, int n)
static const u_char YDcDht[]
const u_char CSampleF
const u_int JFIFLength
const char * Comment
Definition: G4RTJpeg.hh:161
const char JFIF[]
Definition: G4RTJpeg.hh:43
static const u_char YAcDht[]
static const int YQuantumT[]

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

int G4JpegCoder::mCbBlock[64]
protected

Definition at line 67 of file G4RTJpegCoder.hh.

double G4JpegCoder::mCosT[8][8]
protected

Definition at line 69 of file G4RTJpegCoder.hh.

int G4JpegCoder::mCrBlock[64]
protected

Definition at line 68 of file G4RTJpegCoder.hh.

int G4JpegCoder::mDCTData[64]
protected

Definition at line 70 of file G4RTJpegCoder.hh.

int G4JpegCoder::mNumHUnits
protected

Definition at line 75 of file G4RTJpegCoder.hh.

int G4JpegCoder::mNumVUnits
protected

Definition at line 74 of file G4RTJpegCoder.hh.

G4OutBitStream* G4JpegCoder::mOBSP
protected

Definition at line 77 of file G4RTJpegCoder.hh.

int G4JpegCoder::mPreDC[3]
protected

Definition at line 71 of file G4RTJpegCoder.hh.

G4JpegProperty G4JpegCoder::mProperty
protected

Definition at line 73 of file G4RTJpegCoder.hh.

u_char* G4JpegCoder::mRgb[3]
protected

Definition at line 65 of file G4RTJpegCoder.hh.

int G4JpegCoder::mYBlock[4][64]
protected

Definition at line 66 of file G4RTJpegCoder.hh.


The documentation for this class was generated from the following files: