OFFIS DCMTK  Version 3.6.0
streams.h
1 //
2 // (C) Jan de Vaan 2007-2010, all rights reserved. See the accompanying "License.txt" for licensed use.
3 //
4 #ifndef CHARLS_STREAMS
5 #define CHARLS_STREAMS
6 
7 #include "dcmtk/ofstd/ofvector.h"
8 #include "dcmtk/ofstd/ofbmanip.h"
9 #include "util.h"
10 
11 
12 
13 // This file defines JPEG-LS streams: The header and the actual pixel data. Header markers have fixed length, the pixeldata not.
14 
15 
16 
17 class JpegSegment;
18 
19 enum JPEGLS_ColorXForm
20 {
21  // default (RGB)
22  COLORXFORM_NONE = 0,
23 
24  // Color transforms as defined by HP
25  COLORXFORM_HP1,
26  COLORXFORM_HP2,
27  COLORXFORM_HP3,
28 
29  // Defined by HP but not supported by CharLS
30  COLORXFORM_RGB_AS_YUV_LOSSY,
31  COLORXFORM_MATRIX
32 };
33 
34 //
35 // JLSOutputStream: minimal implementation to write JPEG header streams
36 //
38 {
39  friend class JpegMarkerSegment;
40  friend class JpegImageDataSegment;
41 
42 public:
44  virtual ~JLSOutputStream();
45 
46  void Init(Size size, LONG bitsPerSample, LONG ccomp);
47  void AddScan(const void* compareData, const JlsParameters* pparams);
48  void AddLSE(const JlsCustomParameters* pcustom);
49  void AddColorTransform(int i);
50  size_t GetBytesWritten()
51  { return _cbyteOffset; }
52 
53  size_t GetLength()
54  { return _cbyteLength - _cbyteOffset; }
55 
56  size_t Write(BYTE* pdata, size_t cbyteLength);
57 
58  void EnableCompare(bool bCompare)
59  { _bCompare = bCompare; }
60 private:
61  BYTE* GetPos() const
62  { return _pdata + _cbyteOffset; }
63 
64  void WriteByte(BYTE val)
65  {
66  ASSERT(!_bCompare || _pdata[_cbyteOffset] == val);
67 
68  _pdata[_cbyteOffset++] = val;
69  }
70 
71  void WriteBytes(const OFVector<BYTE>& rgbyte)
72  {
73  for (size_t i = 0; i < rgbyte.size(); ++i)
74  {
75  WriteByte(rgbyte[i]);
76  }
77  }
78 
79  void WriteWord(USHORT val)
80  {
81  WriteByte(BYTE(val / 0x100));
82  WriteByte(BYTE(val % 0x100));
83  }
84 
85 
86  void Seek(size_t byteCount)
87  { _cbyteOffset += byteCount; }
88 
89  bool _bCompare;
90 
91 private:
92  BYTE* _pdata;
93  size_t _cbyteOffset;
94  size_t _cbyteLength;
95  LONG _icompLast;
96  OFVector<JpegSegment*> _segments;
97 };
98 
99 
100 
102 {
103 public:
104  Presets()
105  {
106  MAXVAL = 0;
107  T1 = 0;
108  T2 = 0;
109  T3 = 0;
110  RESET = 0;
111  }
112 };
113 
114 
115 //
116 // JLSInputStream: minimal implementation to read JPEG header streams
117 //
119 {
120 public:
121  JLSInputStream(const BYTE* pdata, LONG cbyteLength);
122 
123  size_t GetBytesRead()
124  { return _cbyteOffset; }
125 
126  const JlsParameters& GetMetadata() const
127  { return _info; }
128 
129  const JlsCustomParameters& GetCustomPreset() const
130  { return _info.custom; }
131 
132  void Read(void* pvoid, LONG cbyteAvailable);
133  void ReadHeader();
134 
135  void EnableCompare(bool bCompare)
136  { _bCompare = bCompare; }
137 
138  void SetInfo(JlsParameters* info) { _info = *info; }
139 
140  void SetRect(JlsRect rect) { _rect = rect; }
141 
142 private:
143  void ReadPixels(void* pvoid, LONG cbyteAvailable);
144  void ReadScan(void*);
145  void ReadStartOfScan();
146  void ReadPresetParameters();
147  void ReadComment();
148  void ReadStartOfFrame();
149  BYTE ReadByte();
150  int ReadWord();
151  void ReadNBytes(OFVector<char>& dst, int byteCount);
152 
153  // JFIF
154  void ReadJfif();
155  // Color Transform Application Markers & Code Stream (HP extension)
156  void ReadColorSpace();
157  void ReadColorXForm();
158 
159 private:
160  const BYTE* _pdata;
161  size_t _cbyteOffset;
162  size_t _cbyteLength;
163  bool _bCompare;
164  JlsParameters _info;
165  JlsRect _rect;
166 };
167 
168 
169 
170 
171 #endif


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2