Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/RayTracer/src/G4RTJpegCoder.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/RayTracer/src/G4RTJpegCoder.cc (Version 11.3.0) and /visualization/RayTracer/src/G4RTJpegCoder.cc (Version 5.2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
 26 //                                                 23 //
                                                   >>  24 // $Id: G4RTJpegCoder.cc,v 1.4 2001/07/11 10:09:03 gunter Exp $
                                                   >>  25 // GEANT4 tag $Name: geant4-05-02 $
 27 //                                                 26 //
 28 //                                                 27 //
 29 //                                                 28 //
 30                                                    29 
 31 #include <stdlib.h>                                30 #include <stdlib.h>
 32 #include <string.h>                                31 #include <string.h>
 33 #include <cmath>                               <<  32 #include <math.h>
 34                                                    33 
 35 #include "G4RTJpeg.hh"                             34 #include "G4RTJpeg.hh"
 36 #include "G4RTOutBitStream.hh"                     35 #include "G4RTOutBitStream.hh"
 37 #include "G4RTJpegMaker.hh"                        36 #include "G4RTJpegMaker.hh"
 38 #include "G4RTJpegCoder.hh"                        37 #include "G4RTJpegCoder.hh"
 39 #include "G4RTJpegCoderTables.hh"                  38 #include "G4RTJpegCoderTables.hh"
 40                                                    39 
 41                                                    40 
 42 G4JpegCoder::G4JpegCoder(u_char* colorR,u_char     41 G4JpegCoder::G4JpegCoder(u_char* colorR,u_char* colorG,u_char* colorB)
 43 {                                                  42 {
 44   mRgb[0] = colorR;                                43   mRgb[0] = colorR;
 45   mRgb[1] = colorG;                                44   mRgb[1] = colorG;
 46   mRgb[2] = colorB;                                45   mRgb[2] = colorB;
 47                                                    46 
 48   mPreDC[0] = mPreDC[1] = mPreDC[2] = 0;           47   mPreDC[0] = mPreDC[1] = mPreDC[2] = 0;
 49   mOBSP = 0;                                       48   mOBSP = 0;
 50                                                    49 
 51   for(int n=0; n<8; n++)                           50   for(int n=0; n<8; n++)
 52                 for(int im=0; im<8; im++)      <<  51                 for(int m=0; m<8; m++)
 53                                 mCosT[n][im] = <<  52                                 mCosT[n][m] = cos((2 * m + 1) * n * PaiDiv16);
 54 }                                                  53 }
 55                                                    54 
 56 G4JpegCoder::~G4JpegCoder(void)                    55 G4JpegCoder::~G4JpegCoder(void)
 57 {}                                             <<  56 {
                                                   >>  57   if(mOBSP != 0)
                                                   >>  58                 delete mOBSP;
                                                   >>  59 }
 58                                                    60 
 59 void                                               61 void
 60 G4JpegCoder::GetJpegData(char** aJpegData, int     62 G4JpegCoder::GetJpegData(char** aJpegData, int& size)
 61 {                                                  63 {
 62   if (mOBSP != 0){                                 64   if (mOBSP != 0){
 63     *aJpegData = (char*)mOBSP->GetStreamAddres     65     *aJpegData = (char*)mOBSP->GetStreamAddress();
 64         size = mOBSP->GetStreamSize();             66         size = mOBSP->GetStreamSize();
 65         }                                          67         }
 66         else{                                      68         else{
 67           *aJpegData = 0;                          69           *aJpegData = 0;
 68           size = 0;                                70           size = 0;
 69         }                                          71         }
 70                                                    72 
 71 }                                                  73 }
 72                                                    74 
 73 int                                                75 int
 74 G4JpegCoder::DoCoding(void)                        76 G4JpegCoder::DoCoding(void)
 75 {                                                  77 {
 76   mNumVUnits = (mProperty.nRow / 16) + ((mProp     78   mNumVUnits = (mProperty.nRow / 16) + ((mProperty.nRow % 16) ? 1 : 0);
 77   mNumHUnits = (mProperty.nColumn / 16) + ((mP     79   mNumHUnits = (mProperty.nColumn / 16) + ((mProperty.nColumn % 16) ? 1 : 0);
 78                                                    80 
 79   int size = mProperty.nColumn * mProperty.nRo     81   int size = mProperty.nColumn * mProperty.nRow * 3;
 80   if(size < 10240)                                 82   if(size < 10240)
 81     size = 10240;                                  83     size = 10240;
 82                                                    84 
 83   try{                                             85   try{
 84        mOBSP = new G4OutBitStream(size);           86        mOBSP = new G4OutBitStream(size);
 85            WriteHeader();                          87            WriteHeader();
 86            for(int yu=0; yu<mNumVUnits; yu++){     88            for(int yu=0; yu<mNumVUnits; yu++){
 87                    for(int xu=0; xu<mNumHUnits     89                    for(int xu=0; xu<mNumHUnits; xu++){
 88                            makeYCC(xu, yu);        90                            makeYCC(xu, yu);
 89                                                    91 
 90   //mRgb->YCrCb                                    92   //mRgb->YCrCb
 91   #ifdef GRAY                                      93   #ifdef GRAY
 92   for(int i=0; i<64; i++)                          94   for(int i=0; i<64; i++)
 93         mCbBlock[i] = mCrBlock[i] = 0;             95         mCbBlock[i] = mCrBlock[i] = 0;
 94   #endif                                           96   #endif
 95          CodeMCU();                                97          CodeMCU();
 96          }                                         98          }
 97        }                                           99        }
 98        WriteEOI();                                100        WriteEOI();
 99            return M_NoError;                      101            return M_NoError;
100      }                                            102      }
101                                                   103 
102   catch(G4MemoryError &me){                       104   catch(G4MemoryError &me){
103                 return M_RuntimeError;            105                 return M_RuntimeError;
104   }                                               106   }
105   catch(G4BufferError &be){                       107   catch(G4BufferError &be){
106                 return M_RuntimeError;            108                 return M_RuntimeError;
107   }                                               109   }
108   catch(G4IndexError &ie){                        110   catch(G4IndexError &ie){
109                 return M_RuntimeError;            111                 return M_RuntimeError;
110   }                                               112   }
111 }                                                 113 }
112                                                   114 
113 //MCU                                             115 //MCU
114 void                                              116 void
115 G4JpegCoder::CodeMCU(void)                        117 G4JpegCoder::CodeMCU(void)
116 {                                                 118 {
117   for(int n=0; n<4; n++){                         119   for(int n=0; n<4; n++){
118                 ForwardDCT(mYBlock[n]);           120                 ForwardDCT(mYBlock[n]);
119                 Quantization(0);                  121                 Quantization(0);
120                 CodeHuffman(0);                   122                 CodeHuffman(0);
121   }                                               123   }
122   ForwardDCT(mCbBlock);                           124   ForwardDCT(mCbBlock);
123   Quantization(1);                                125   Quantization(1);
124   CodeHuffman(1);                                 126   CodeHuffman(1);
125                                                   127 
126   ForwardDCT(mCrBlock);                           128   ForwardDCT(mCrBlock);
127   Quantization(2);                                129   Quantization(2);
128   CodeHuffman(2);                                 130   CodeHuffman(2);
129 }                                                 131 }
130                                                   132 
131 void                                              133 void
132 G4JpegCoder::makeYCC(int ux, int uy)              134 G4JpegCoder::makeYCC(int ux, int uy)
133 {                                                 135 {
134   u_char  rv, gv, bv;                             136   u_char  rv, gv, bv;
135   int tCrBlock[4][64];                            137   int tCrBlock[4][64];
136   int tCbBlock[4][64];                            138   int tCbBlock[4][64];
137                                                   139 
138   for(int u=0; u<4; u++){                         140   for(int u=0; u<4; u++){
139         int *yp = mYBlock[u];                     141         int *yp = mYBlock[u];
140         int *cbp = tCbBlock[u];                   142         int *cbp = tCbBlock[u];
141         int *crp = tCrBlock[u];                   143         int *crp = tCrBlock[u];
142                                                   144 
143         int sx = ux * 16 + ((u&1) ? 8 : 0);       145         int sx = ux * 16 + ((u&1) ? 8 : 0);
144         int ex = sx + 8;                          146         int ex = sx + 8;
145         int sy = uy * 16 + ((u>1) ? 8 : 0);       147         int sy = uy * 16 + ((u>1) ? 8 : 0);
146         int ey = sy + 8;                          148         int ey = sy + 8;
147                                                   149 
148      for(int iv=sy; iv<ey; iv++){                 150      for(int iv=sy; iv<ey; iv++){
149           int ii = iv < mProperty.nRow ? iv :     151           int ii = iv < mProperty.nRow ? iv : mProperty.nRow - 1;
150           for(int ih=sx; ih<ex; ih++){            152           for(int ih=sx; ih<ex; ih++){
151             int jj = ih < mProperty.nColumn ?     153             int jj = ih < mProperty.nColumn ? ih : mProperty.nColumn - 1;
152                 int index = ii * mProperty.nCo    154                 int index = ii * mProperty.nColumn + jj;
153                 rv = mRgb[0][index];              155                 rv = mRgb[0][index];
154                 gv = mRgb[1][index];              156                 gv = mRgb[1][index];
155                 bv = mRgb[2][index];              157                 bv = mRgb[2][index];
156                                                   158 
157                 *yp++ = int((0.2990 * rv) + (0    159                 *yp++ = int((0.2990 * rv) + (0.5870 * gv) + (0.1140 * bv) - 128)
158 ;                                                 160 ;
159                 *cbp++ = int(-(0.1687 * rv) -     161                 *cbp++ = int(-(0.1687 * rv) - (0.3313 * gv) + (0.5000 * bv));
160                 *crp++ = int((0.5000 * rv) - (    162                 *crp++ = int((0.5000 * rv) - (0.4187 * gv) - (0.0813 * bv));
161                                 }       // ih     163                                 }       // ih
162                            }    //iv              164                            }    //iv
163   }     //u                                       165   }     //u
164                                                   166 
165  int   n = 0;                                     167  int   n = 0;
166   for(int b=0; b<4; b++){                         168   for(int b=0; b<4; b++){
167         switch(b){                                169         switch(b){
168                 case 0:         n=0;    break;    170                 case 0:         n=0;    break;
169                 case 1:         n=4;    break;    171                 case 1:         n=4;    break;
170                 case 2:         n=32;   break;    172                 case 2:         n=32;   break;
171                 case 3:         n=36;             173                 case 3:         n=36;
172         }                                         174         }
173         for(int y=0; y<8; y+=2){                  175         for(int y=0; y<8; y+=2){
174                 for(int x=0; x<8; x+=2){          176                 for(int x=0; x<8; x+=2){
175                         int idx = y * 8 + x;      177                         int idx = y * 8 + x;
176                         mCrBlock[n] = tCrBlock    178                         mCrBlock[n] = tCrBlock[b][idx];
177                         mCbBlock[n] = tCbBlock    179                         mCbBlock[n] = tCbBlock[b][idx];
178                         n++;                      180                         n++;
179                 }                                 181                 }
180                 n += 4;                           182                 n += 4;
181         }                                         183         }
182   }                                               184   }
183 }                                                 185 }
184                                                   186 
185 void                                              187 void
186 G4JpegCoder::CodeHuffman(int cs)                  188 G4JpegCoder::CodeHuffman(int cs)
187 {                                                 189 {
188   const G4HuffmanCodeTable& dcT = cs ? CDcHuff    190   const G4HuffmanCodeTable& dcT = cs ? CDcHuffmanT : YDcHuffmanT;
189   const G4HuffmanCodeTable& acT = cs ? CAcHuff    191   const G4HuffmanCodeTable& acT = cs ? CAcHuffmanT : YAcHuffmanT;
190   const int eobIdx = cs ? CEOBidx : YEOBidx;      192   const int eobIdx = cs ? CEOBidx : YEOBidx;
191   const int zrlIdx = cs ? CZRLidx : YZRLidx;      193   const int zrlIdx = cs ? CZRLidx : YZRLidx;
192                                                   194 
193   int diff = mDCTData[0] - mPreDC[cs];            195   int diff = mDCTData[0] - mPreDC[cs];
194   mPreDC[cs] = mDCTData[0];                       196   mPreDC[cs] = mDCTData[0];
195   int absDiff = std::abs(diff);                << 197   int absDiff = abs(diff);
196   int dIdx = 0;                                   198   int dIdx = 0;
197                                                   199 
198   while(absDiff > 0){                             200   while(absDiff > 0){
199         absDiff >>= 1;                            201         absDiff >>= 1;
200         dIdx++;                                   202         dIdx++;
201   }                                               203   }
202   if(dIdx > dcT.numOfElement)                     204   if(dIdx > dcT.numOfElement)
203         throw(G4IndexError(dcT.numOfElement, d    205         throw(G4IndexError(dcT.numOfElement, dIdx, "CodeHuffman:DC"));
204   mOBSP->SetBits((dcT.CodeT)[dIdx], (dcT.SizeT    206   mOBSP->SetBits((dcT.CodeT)[dIdx], (dcT.SizeT)[dIdx]);
205                                                   207 
206   if(dIdx){                                       208   if(dIdx){
207         if(diff < 0)                              209         if(diff < 0)
208                 diff--;                           210                 diff--;
209         mOBSP->SetBits(diff, dIdx);               211         mOBSP->SetBits(diff, dIdx);
210   }                                               212   }
211                                                   213 
212   int run = 0;                                    214   int run = 0;
213   for(int n=1; n<64; n++){                        215   for(int n=1; n<64; n++){
214         int absCoefficient = std::abs( mDCTDat << 216         int absCoefficient = abs( mDCTData[ Zigzag[n] ] );
215         if( absCoefficient ){                     217         if( absCoefficient ){
216                 while( run > 15 ){                218                 while( run > 15 ){
217                 mOBSP->SetBits((acT.CodeT)[zrl    219                 mOBSP->SetBits((acT.CodeT)[zrlIdx], (acT.SizeT)[zrlIdx]);
218                 run -= 16;                        220                 run -= 16;
219                 }                                 221                 }
220                 int is = 0;                    << 222                 int s = 0;
221                 while( absCoefficient > 0 ){      223                 while( absCoefficient > 0 ){
222                         absCoefficient >>= 1;     224                         absCoefficient >>= 1;
223                         is++;                  << 225                         s++;
224                 }                                 226                 }
225                 int     aIdx = run * 10 + is + << 227                 int     aIdx = run * 10 + s + (run == 15);
226                 if( aIdx >= acT.numOfElement )    228                 if( aIdx >= acT.numOfElement ) 
227                   throw( G4IndexError( acT.num    229                   throw( G4IndexError( acT.numOfElement, aIdx, "CodeHuffman:AC" )
228  );                                               230  );
229   mOBSP->SetBits( (acT.CodeT)[aIdx], (acT.Size    231   mOBSP->SetBits( (acT.CodeT)[aIdx], (acT.SizeT)[aIdx] );
230                 int     v = mDCTData[ Zigzag[n    232                 int     v = mDCTData[ Zigzag[n] ];
231                 if( v < 0 )                       233                 if( v < 0 )
232                   v--;                            234                   v--;
233                 mOBSP->SetBits( v, is );       << 235                 mOBSP->SetBits( v, s );
234                 run = 0;                          236                 run = 0;
235                 }                                 237                 }
236                 else{                             238                 else{
237                   if(n == 63)                     239                   if(n == 63)
238                   mOBSP->SetBits( (acT.CodeT)[    240                   mOBSP->SetBits( (acT.CodeT)[eobIdx], (acT.SizeT)[eobIdx] );
239                 else                              241                 else
240                 run++;                            242                 run++;
241                 }                                 243                 }
242         }                                         244         }
243 }                                                 245 }
244                                                   246 
245                                                   247 
246 void                                              248 void
247 G4JpegCoder::Quantization(int cs)                 249 G4JpegCoder::Quantization(int cs)
248 {                                                 250 {
249   int* qt = (int*)(cs ? CQuantumT : YQuantumT)    251   int* qt = (int*)(cs ? CQuantumT : YQuantumT);
250   for( int i=0; i<64; i++ ){                      252   for( int i=0; i<64; i++ ){
251     mDCTData[i] /= qt[i];                         253     mDCTData[i] /= qt[i];
252   }                                               254   }
253 }                                                 255 }
254                                                   256 
255                                                   257 
256 void                                              258 void
257 G4JpegCoder::ForwardDCT(int* picData)             259 G4JpegCoder::ForwardDCT(int* picData)
258 {                                                 260 {
259   for( int v=0; v<8; v++ ){                       261   for( int v=0; v<8; v++ ){
260     double cv = v ? 1.0 : DisSqrt2;               262     double cv = v ? 1.0 : DisSqrt2;
261     for( int u=0; u<8; u++ ){                     263     for( int u=0; u<8; u++ ){
262       double cu = u ? 1.0 : DisSqrt2;             264       double cu = u ? 1.0 : DisSqrt2;
263       double sum = 0;                             265       double sum = 0;
                                                   >> 266 
264       for( int y=0; y<8; y++ )                    267       for( int y=0; y<8; y++ )
265         for( int x=0; x<8; x++ )                  268         for( int x=0; x<8; x++ )
266           sum += picData[ y * 8 + x ] * mCosT[    269           sum += picData[ y * 8 + x ] * mCosT[u][x] * mCosT[v][y];
267       mDCTData[ v * 8 + u ] = int( sum * cu *  << 270           mDCTData[ v * 8 + u ] = int( sum * cu * cv / 4 );
                                                   >> 271         }
268     }                                             272     }
269   }                                            << 
270 }                                                 273 }
271                                                   274 
272                                                   275 
273 void                                              276 void
274 G4JpegCoder::WriteHeader( void )                  277 G4JpegCoder::WriteHeader( void )
275 {                                                 278 {
276   int i = 0;    //counter                         279   int i = 0;    //counter
277   //SOI                                           280   //SOI
278   mOBSP->SetByte( M_Marker );   //FF              281   mOBSP->SetByte( M_Marker );   //FF
279   mOBSP->SetByte( M_SOI );      //SOI             282   mOBSP->SetByte( M_SOI );      //SOI
280                                                   283 
281   //APP0(JFIF Header)                             284   //APP0(JFIF Header)
282   mOBSP->SetByte( M_Marker );   //FF              285   mOBSP->SetByte( M_Marker );   //FF
283   mOBSP->SetByte( M_APP0 );     //APP0            286   mOBSP->SetByte( M_APP0 );     //APP0
284   mOBSP->SetWord( JFIFLength );        //param    287   mOBSP->SetWord( JFIFLength );        //parameter
285   mOBSP->CopyByte( (char*)JFIF, 5 );   //"JFIF    288   mOBSP->CopyByte( (char*)JFIF, 5 );   //"JFIF\0"
286   mOBSP->SetWord( JFIFVersion );       //Versi    289   mOBSP->SetWord( JFIFVersion );       //Version
287   mOBSP->SetByte( mProperty.Units );              290   mOBSP->SetByte( mProperty.Units );
288   mOBSP->SetWord( mProperty.HDensity );           291   mOBSP->SetWord( mProperty.HDensity );
289   mOBSP->SetWord( mProperty.VDensity );           292   mOBSP->SetWord( mProperty.VDensity );
290   mOBSP->SetByte( 0 );                            293   mOBSP->SetByte( 0 );
291   mOBSP->SetByte( 0 );                            294   mOBSP->SetByte( 0 );
292                                                   295 
293  //comment                                        296  //comment
294   if( mProperty.Comment != 0 ){                   297   if( mProperty.Comment != 0 ){
295     mOBSP->SetByte( M_Marker ); //FF              298     mOBSP->SetByte( M_Marker ); //FF
296     mOBSP->SetByte( M_COM );    //comment         299     mOBSP->SetByte( M_COM );    //comment
297     int length = (int)strlen( mProperty.Commen << 300     int length = strlen( mProperty.Comment ) + 1;
298     mOBSP->SetWord( length + 2 );                 301     mOBSP->SetWord( length + 2 );
299     mOBSP->CopyByte( mProperty.Comment, length    302     mOBSP->CopyByte( mProperty.Comment, length );
300   }                                               303   }
301                                                   304 
302   //DQT                                           305   //DQT
303   mOBSP->SetByte( M_Marker );                     306   mOBSP->SetByte( M_Marker );
304   mOBSP->SetByte( M_DQT );                        307   mOBSP->SetByte( M_DQT );
305   mOBSP->SetWord( 67 );                           308   mOBSP->SetWord( 67 );
306   mOBSP->SetByte( 0 );                            309   mOBSP->SetByte( 0 );
307   for( i=0; i<64; i++ )                           310   for( i=0; i<64; i++ )
308         mOBSP->SetByte( u_char( YQuantumT[Zigz    311         mOBSP->SetByte( u_char( YQuantumT[Zigzag[i]] ) );
309   mOBSP->SetByte( M_Marker );                     312   mOBSP->SetByte( M_Marker );
310   mOBSP->SetByte( M_DQT );                        313   mOBSP->SetByte( M_DQT );
311   mOBSP->SetWord( 67 );                           314   mOBSP->SetWord( 67 );
312   mOBSP->SetByte( 1 );                            315   mOBSP->SetByte( 1 );
313   for( i=0; i<64; i++ )                           316   for( i=0; i<64; i++ )
314         mOBSP->SetByte( u_char( CQuantumT[Zigz    317         mOBSP->SetByte( u_char( CQuantumT[Zigzag[i]] ) );
315    // DHT                                         318    // DHT
316   mOBSP->CopyByte( (char*)YDcDht, DcDhtLength     319   mOBSP->CopyByte( (char*)YDcDht, DcDhtLength );
317   mOBSP->CopyByte( (char*)CDcDht, DcDhtLength     320   mOBSP->CopyByte( (char*)CDcDht, DcDhtLength );
318   mOBSP->CopyByte( (char*)YAcDht, AcDhtLength     321   mOBSP->CopyByte( (char*)YAcDht, AcDhtLength );
319   mOBSP->CopyByte( (char*)CAcDht, AcDhtLength     322   mOBSP->CopyByte( (char*)CAcDht, AcDhtLength );
320                                                   323 
321   // Frame Header                                 324   // Frame Header
322   mOBSP->SetByte( M_Marker );   // FF             325   mOBSP->SetByte( M_Marker );   // FF
323   mOBSP->SetByte( M_SOF0 );                       326   mOBSP->SetByte( M_SOF0 );
324   mOBSP->SetWord( 3 * mProperty.Dimension + 8     327   mOBSP->SetWord( 3 * mProperty.Dimension + 8 );
325   mOBSP->SetByte( mProperty.SamplePrecision );    328   mOBSP->SetByte( mProperty.SamplePrecision );
326   mOBSP->SetWord( mProperty.nRow );               329   mOBSP->SetWord( mProperty.nRow );
327   mOBSP->SetWord( mProperty.nColumn );            330   mOBSP->SetWord( mProperty.nColumn );
328   mOBSP->SetByte( mProperty.Dimension );          331   mOBSP->SetByte( mProperty.Dimension );
329                                                   332 
330   mOBSP->SetByte( 0 );                            333   mOBSP->SetByte( 0 );
331   mOBSP->SetByte( YSampleF );                     334   mOBSP->SetByte( YSampleF );
332   mOBSP->SetByte( 0 );                            335   mOBSP->SetByte( 0 );
333                                                   336 
334   mOBSP->SetByte( 1 );                            337   mOBSP->SetByte( 1 );
335   mOBSP->SetByte( CSampleF );                     338   mOBSP->SetByte( CSampleF );
336                                                   339 
337   mOBSP->SetByte( 1 );                            340   mOBSP->SetByte( 1 );
338   mOBSP->SetByte( 2 );                            341   mOBSP->SetByte( 2 );
339   mOBSP->SetByte( CSampleF );                     342   mOBSP->SetByte( CSampleF );
340   mOBSP->SetByte( 1 );                            343   mOBSP->SetByte( 1 );
341                                                   344 
342   //Scan Header                                   345   //Scan Header
343   mOBSP->SetByte( M_Marker );                     346   mOBSP->SetByte( M_Marker );
344   mOBSP->SetByte( M_SOS );                        347   mOBSP->SetByte( M_SOS );
345   mOBSP->SetWord( 2 * mProperty.Dimension + 6     348   mOBSP->SetWord( 2 * mProperty.Dimension + 6 );
346   mOBSP->SetByte( mProperty.Dimension );          349   mOBSP->SetByte( mProperty.Dimension );
347   for( i=0; i<mProperty.Dimension; i++ ){         350   for( i=0; i<mProperty.Dimension; i++ ){
348         mOBSP->SetByte( i );                      351         mOBSP->SetByte( i );
349         mOBSP->SetByte( i==0 ? 0 : 0x11 );        352         mOBSP->SetByte( i==0 ? 0 : 0x11 );
350   }                                               353   }
351   mOBSP->SetByte( 0 );  //Ss                      354   mOBSP->SetByte( 0 );  //Ss
352   mOBSP->SetByte( 63 ); //Se                      355   mOBSP->SetByte( 63 ); //Se
353   mOBSP->SetByte( 0 );  //Ah,Al                   356   mOBSP->SetByte( 0 );  //Ah,Al
354 }                                                 357 }
355                                                   358 
356 //EOI                                             359 //EOI
357 void                                              360 void
358 G4JpegCoder::WriteEOI( void )                     361 G4JpegCoder::WriteEOI( void )
359 {                                                 362 {
360   mOBSP->SetByte( M_Marker );                     363   mOBSP->SetByte( M_Marker );
361   mOBSP->SetByte( M_EOI );                        364   mOBSP->SetByte( M_EOI );
362 }                                                 365 }
363                                                   366 
364 //SetJpegProperty                                 367 //SetJpegProperty
365 void                                              368 void
366 G4JpegCoder::SetJpegProperty(const G4JpegPrope    369 G4JpegCoder::SetJpegProperty(const G4JpegProperty& aProperty )
367 {                                                 370 {
368   mProperty = aProperty;                          371   mProperty = aProperty;
369   mProperty.Dimension = 3;                        372   mProperty.Dimension = 3;
370   mProperty.SamplePrecision = 8;                  373   mProperty.SamplePrecision = 8;
371   mProperty.Format = 1;                           374   mProperty.Format = 1;
372   mProperty.MajorRevisions = 1;                   375   mProperty.MajorRevisions = 1;
373   mProperty.MinorRevisions = 2;                   376   mProperty.MinorRevisions = 2;
374   mProperty.HThumbnail = 0;                       377   mProperty.HThumbnail = 0;
375   mProperty.VThumbnail = 0;                       378   mProperty.VThumbnail = 0;
376 }                                                 379 }
377                                                   380