libpgf  6.11.42
PGF - Progressive Graphics File
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PGFimage.h
Go to the documentation of this file.
1 /*
2  * The Progressive Graphics File; http://www.libpgf.org
3  *
4  * $Date: 2007-02-03 13:04:21 +0100 (Sa, 03 Feb 2007) $
5  * $Revision: 280 $
6  *
7  * This file Copyright (C) 2006 xeraina GmbH, Switzerland
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  */
23 
28 
29 #ifndef PGF_PGFIMAGE_H
30 #define PGF_PGFIMAGE_H
31 
32 #include "PGFstream.h"
33 
34 class CDecoder;
35 class CEncoder;
36 class CWaveletTransform;
37 
51 class CPGFImage {
52 public:
53 
56  CPGFImage();
57 
60  virtual ~CPGFImage();
61 
65  virtual void Close();
66 
70  virtual void Destroy();
71 
77  void Open(CPGFStream* stream) THROW_;
78 
81  bool IsOpen() const { return m_decoder != NULL; }
82 
95  void Read(int level = 0, CallbackPtr cb = NULL, void *data = NULL) THROW_;
96 
97 #ifdef __PGFROISUPPORT__
98 
99 
100 
101 
102 
103 
104 
105 
106 
107  void Read(PGFRect& rect, int level = 0, CallbackPtr cb = NULL, void *data = NULL) THROW_;
108 #endif
109 
115  void ReadPreview() THROW_ { Read(Levels() - 1); }
116 
122  void Reconstruct(int level = 0) THROW_;
123 
141  void GetBitmap(int pitch, UINT8* buff, BYTE bpp, int channelMap[] = NULL, CallbackPtr cb = NULL, void *data = NULL) const THROW_; // throws IOException
142 
158  void GetYUV(int pitch, DataT* buff, BYTE bpp, int channelMap[] = NULL, CallbackPtr cb = NULL, void *data = NULL) const THROW_; // throws IOException
159 
176  void ImportBitmap(int pitch, UINT8 *buff, BYTE bpp, int channelMap[] = NULL, CallbackPtr cb = NULL, void *data = NULL) THROW_;
177 
193  void ImportYUV(int pitch, DataT *buff, BYTE bpp, int channelMap[] = NULL, CallbackPtr cb = NULL, void *data = NULL) THROW_;
194 
210  void Write(CPGFStream* stream, UINT32* nWrittenBytes = NULL, CallbackPtr cb = NULL, void *data = NULL) THROW_;
211 
219  UINT32 WriteHeader(CPGFStream* stream) THROW_;
220 
221 #ifdef __PGFROISUPPORT__
222 
223 
224 
225 
226 
227 
228 
229 
230 
231 
232 
233 
234 
235 
236 
237  UINT32 Write(int level, CallbackPtr cb = NULL, void *data = NULL) THROW_;
238 #endif
239 
244  void ConfigureEncoder(bool useOMP = true, bool favorSpeedOverSize = false) { m_useOMPinEncoder = useOMP; m_favorSpeedOverSize = favorSpeedOverSize; }
245 
249  void ConfigureDecoder(bool useOMP = true) { m_useOMPinDecoder = useOMP; }
250 
254  //void SetBackground(const RGBTRIPLE* bg);
255 
261  //void SetBackground(BYTE red, BYTE green, BYTE blue) { /*m_backgroundSet = true;*/ m_header.background.rgbtRed = red; m_header.background.rgbtGreen = green; m_header.background.rgbtBlue = blue; }
262 
267  void SetChannel(DataT* channel, int c = 0) { ASSERT(c >= 0 && c < MaxChannels); m_channel[c] = channel; }
268 
277  void SetHeader(const PGFHeader& header, BYTE flags = 0, UINT8* userData = 0, UINT32 userDataLength = 0) THROW_; // throws IOException
278 
283  void SetMaxValue(UINT32 maxValue);
284 
289  BYTE UsedBitsPerChannel() const;
290 
296  void SetRefreshCallback(RefreshCB callback, void* arg) { m_cb = callback; m_cbArg = arg; }
297 
304  void SetColorTable(UINT32 iFirstColor, UINT32 nColors, const RGBQUAD* prgbColors) THROW_;
305 
309  //RGBTRIPLE Background() const { return m_header.background; }
310 
315  DataT* GetChannel(int c = 0) { ASSERT(c >= 0 && c < MaxChannels); return m_channel[c]; }
316 
323  void GetColorTable(UINT32 iFirstColor, UINT32 nColors, RGBQUAD* prgbColors) const THROW_;
324 
326  // Returns address of internal color table
328  const RGBQUAD* GetColorTable() const { return m_postHeader.clut; }
329 
333  const PGFHeader* GetHeader() const { return &m_header; }
334 
339  UINT32 GetMaxValue() const { return (1 << m_header.usedBitsPerChannel) - 1; }
340 
345  const UINT8* GetUserData(UINT32& size) const;
346 
351  UINT32 GetEncodedHeaderLength() const;
352 
358  UINT32 GetEncodedLevelLength(int level) const { ASSERT(level >= 0 && level < m_header.nLevels); return m_levelLength[m_header.nLevels - level - 1]; }
359 
362  void ResetStreamPos() THROW_;
363 
371  UINT32 ReadEncodedHeader(UINT8* target, UINT32 targetLen) const THROW_;
372 
382  UINT32 ReadEncodedData(int level, UINT8* target, UINT32 targetLen) const THROW_;
383 
389  UINT32 ChannelWidth(int c = 0) const { ASSERT(c >= 0 && c < MaxChannels); return m_width[c]; }
390 
396  UINT32 ChannelHeight(int c = 0) const { ASSERT(c >= 0 && c < MaxChannels); return m_height[c]; }
397 
402 
408  UINT32 Width(int level = 0) const { ASSERT(level >= 0); return LevelWidth(m_header.width, level); }
409 
415  UINT32 Height(int level = 0) const { ASSERT(level >= 0); return LevelHeight(m_header.height, level); }
416 
422  BYTE Level() const { return (BYTE)m_currentLevel; }
423 
427  BYTE Levels() const { return m_header.nLevels; }
428 
433  BYTE Quality() const { return m_header.quality; }
434 
439  BYTE Channels() const { return m_header.channels; }
440 
446  BYTE Mode() const { return m_header.mode; }
447 
452  BYTE BPP() const { return m_header.bpp; }
453 
457  bool ROIisSupported() const { return (m_preHeader.version & PGFROI) == PGFROI; }
458 
462  BYTE Version() const { return CurrentVersion(m_preHeader.version); }
463 
464  //class methods
465 
470  static bool ImportIsSupported(BYTE mode);
471 
477  static UINT32 LevelWidth(UINT32 width, int level) { ASSERT(level >= 0); UINT32 w = (width >> level); return ((w << level) == width) ? w : w + 1; }
478 
484  static UINT32 LevelHeight(UINT32 height, int level) { ASSERT(level >= 0); UINT32 h = (height >> level); return ((h << level) == height) ? h : h + 1; }
485 
489  static BYTE CurrentVersion(BYTE version = PGFVersion);
490 
494  static BYTE CurrentChannelDepth(BYTE version = PGFVersion) { return (version & PGF32) ? 32 : 16; }
495 
496 protected:
501  UINT32* m_levelLength;
508  BYTE m_quant;
513 #ifdef __PGFROISUPPORT__
514  bool m_levelwise;
517 #endif
518 
519 private:
521  void *m_cbArg;
522 
523  void ComputeLevels();
524  void CompleteHeader();
525  void RgbToYuv(int pitch, UINT8* rgbBuff, BYTE bpp, int channelMap[], CallbackPtr cb, void *data) THROW_;
526  void Downsample(int nChannel);
527  void WriteLevel() THROW_;
528 
529 #ifdef __PGFROISUPPORT__
530  void SetROI(PGFRect rect);
531 #endif
532 
533  UINT8 Clamp4(DataT v) const {
534  if (v & 0xFFFFFFF0) return (v < 0) ? (UINT8)0: (UINT8)15; else return (UINT8)v;
535  }
536  UINT16 Clamp6(DataT v) const {
537  if (v & 0xFFFFFFC0) return (v < 0) ? (UINT16)0: (UINT16)63; else return (UINT16)v;
538  }
539  UINT8 Clamp8(DataT v) const {
540  // needs only one test in the normal case
541  if (v & 0xFFFFFF00) return (v < 0) ? (UINT8)0 : (UINT8)255; else return (UINT8)v;
542  }
543  UINT16 Clamp16(DataT v) const {
544  if (v & 0xFFFF0000) return (v < 0) ? (UINT16)0: (UINT16)65535; else return (UINT16)v;
545  }
546  UINT32 Clamp31(DataT v) const {
547  return (v < 0) ? 0 : (UINT32)v;
548  }
549 };
550 
551 #endif //PGF_PGFIMAGE_H