libpgf  6.13.45
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 
35 // types
37 
39 // prototypes
40 class CDecoder;
41 class CEncoder;
42 class CWaveletTransform;
43 
57 class CPGFImage {
58 public:
59 
62  CPGFImage();
63 
66  virtual ~CPGFImage();
67 
71  virtual void Close();
72 
76  virtual void Destroy();
77 
83  void Open(CPGFStream* stream) THROW_;
84 
87  bool IsOpen() const { return m_decoder != NULL; }
88 
101  void Read(int level = 0, CallbackPtr cb = NULL, void *data = NULL) THROW_;
102 
103 #ifdef __PGFROISUPPORT__
104 
105 
106 
107 
108 
109 
110 
111 
112 
113  void Read(PGFRect& rect, int level = 0, CallbackPtr cb = NULL, void *data = NULL) THROW_;
114 #endif
115 
121  void ReadPreview() THROW_ { Read(Levels() - 1); }
122 
128  void Reconstruct(int level = 0) THROW_;
129 
147  void GetBitmap(int pitch, UINT8* buff, BYTE bpp, int channelMap[] = NULL, CallbackPtr cb = NULL, void *data = NULL) const THROW_; // throws IOException
148 
164  void GetYUV(int pitch, DataT* buff, BYTE bpp, int channelMap[] = NULL, CallbackPtr cb = NULL, void *data = NULL) const THROW_; // throws IOException
165 
182  void ImportBitmap(int pitch, UINT8 *buff, BYTE bpp, int channelMap[] = NULL, CallbackPtr cb = NULL, void *data = NULL) THROW_;
183 
199  void ImportYUV(int pitch, DataT *buff, BYTE bpp, int channelMap[] = NULL, CallbackPtr cb = NULL, void *data = NULL) THROW_;
200 
214  void Write(CPGFStream* stream, UINT32* nWrittenBytes = NULL, CallbackPtr cb = NULL, void *data = NULL) THROW_;
215 
223  UINT32 WriteHeader(CPGFStream* stream) THROW_;
224 
235  UINT32 WriteImage(CPGFStream* stream, CallbackPtr cb = NULL, void *data = NULL) THROW_;
236 
237 #ifdef __PGFROISUPPORT__
238 
239 
240 
241 
242 
243 
244 
245 
246 
247 
248 
249 
250 
251 
252 
253  UINT32 Write(int level, CallbackPtr cb = NULL, void *data = NULL) THROW_;
254 #endif
255 
260  void ConfigureEncoder(bool useOMP = true, bool favorSpeedOverSize = false) { m_useOMPinEncoder = useOMP; m_favorSpeedOverSize = favorSpeedOverSize; }
261 
266  void ConfigureDecoder(bool useOMP = true, bool skipUserData = false) { m_useOMPinDecoder = useOMP; m_skipUserData = skipUserData; }
267 
270  void ResetStreamPos() THROW_;
271 
276  void SetChannel(DataT* channel, int c = 0) { ASSERT(c >= 0 && c < MaxChannels); m_channel[c] = channel; }
277 
286  void SetHeader(const PGFHeader& header, BYTE flags = 0, UINT8* userData = 0, UINT32 userDataLength = 0) THROW_; // throws IOException
287 
292  void SetMaxValue(UINT32 maxValue);
293 
301 
307  void SetRefreshCallback(RefreshCB callback, void* arg) { m_cb = callback; m_cbArg = arg; }
308 
315  void SetColorTable(UINT32 iFirstColor, UINT32 nColors, const RGBQUAD* prgbColors) THROW_;
316 
321  DataT* GetChannel(int c = 0) { ASSERT(c >= 0 && c < MaxChannels); return m_channel[c]; }
322 
329  void GetColorTable(UINT32 iFirstColor, UINT32 nColors, RGBQUAD* prgbColors) const THROW_;
330 
332  // Returns address of internal color table
334  const RGBQUAD* GetColorTable() const { return m_postHeader.clut; }
335 
339  const PGFHeader* GetHeader() const { return &m_header; }
340 
345  UINT32 GetMaxValue() const { return (1 << m_header.usedBitsPerChannel) - 1; }
346 
350  UINT64 GetUserDataPos() const { return m_userDataPos; }
351 
357  const UINT8* GetUserData(UINT32& size) const;
358 
363  UINT32 GetEncodedHeaderLength() const;
364 
370  UINT32 GetEncodedLevelLength(int level) const { ASSERT(level >= 0 && level < m_header.nLevels); return m_levelLength[m_header.nLevels - level - 1]; }
371 
379  UINT32 ReadEncodedHeader(UINT8* target, UINT32 targetLen) const THROW_;
380 
390  UINT32 ReadEncodedData(int level, UINT8* target, UINT32 targetLen) const THROW_;
391 
397  UINT32 ChannelWidth(int c = 0) const { ASSERT(c >= 0 && c < MaxChannels); return m_width[c]; }
398 
404  UINT32 ChannelHeight(int c = 0) const { ASSERT(c >= 0 && c < MaxChannels); return m_height[c]; }
405 
410 
416  UINT32 Width(int level = 0) const { ASSERT(level >= 0); return LevelWidth(m_header.width, level); }
417 
423  UINT32 Height(int level = 0) const { ASSERT(level >= 0); return LevelHeight(m_header.height, level); }
424 
430  BYTE Level() const { return (BYTE)m_currentLevel; }
431 
435  BYTE Levels() const { return m_header.nLevels; }
436 
441  BYTE Quality() const { return m_header.quality; }
442 
447  BYTE Channels() const { return m_header.channels; }
448 
454  BYTE Mode() const { return m_header.mode; }
455 
460  BYTE BPP() const { return m_header.bpp; }
461 
465  bool ROIisSupported() const { return (m_preHeader.version & PGFROI) == PGFROI; }
466 
471  BYTE UsedBitsPerChannel() const;
472 
476  BYTE Version() const { return CurrentVersion(m_preHeader.version); }
477 
478  //class methods
479 
484  static bool ImportIsSupported(BYTE mode);
485 
491  static UINT32 LevelWidth(UINT32 width, int level) { ASSERT(level >= 0); UINT32 w = (width >> level); return ((w << level) == width) ? w : w + 1; }
492 
498  static UINT32 LevelHeight(UINT32 height, int level) { ASSERT(level >= 0); UINT32 h = (height >> level); return ((h << level) == height) ? h : h + 1; }
499 
503  static BYTE CurrentVersion(BYTE version = PGFVersion);
504 
508  static BYTE CurrentChannelDepth(BYTE version = PGFVersion) { return (version & PGF32) ? 32 : 16; }
509 
510 protected:
515  UINT32* m_levelLength;
521  UINT64 m_userDataPos;
523  BYTE m_quant;
529 #ifdef __PGFROISUPPORT__
532 #endif
533 
534 private:
536  void *m_cbArg;
537  double m_percent;
539 
540  void ComputeLevels();
541  void CompleteHeader();
542  void RgbToYuv(int pitch, UINT8* rgbBuff, BYTE bpp, int channelMap[], CallbackPtr cb, void *data) THROW_;
543  void Downsample(int nChannel);
544  UINT32 UpdatePostHeaderSize() THROW_;
545  void WriteLevel() THROW_;
546 
547 #ifdef __PGFROISUPPORT__
548  void SetROI(PGFRect rect);
549 #endif
550 
551  UINT8 Clamp4(DataT v) const {
552  if (v & 0xFFFFFFF0) return (v < 0) ? (UINT8)0: (UINT8)15; else return (UINT8)v;
553  }
554  UINT16 Clamp6(DataT v) const {
555  if (v & 0xFFFFFFC0) return (v < 0) ? (UINT16)0: (UINT16)63; else return (UINT16)v;
556  }
557  UINT8 Clamp8(DataT v) const {
558  // needs only one test in the normal case
559  if (v & 0xFFFFFF00) return (v < 0) ? (UINT8)0 : (UINT8)255; else return (UINT8)v;
560  }
561  UINT16 Clamp16(DataT v) const {
562  if (v & 0xFFFF0000) return (v < 0) ? (UINT16)0: (UINT16)65535; else return (UINT16)v;
563  }
564  UINT32 Clamp31(DataT v) const {
565  return (v < 0) ? 0 : (UINT32)v;
566  }
567 };
568 
569 #endif //PGF_PGFIMAGE_H