libpgf: PGFimage.h Source File

| libpgf 7.21.2 PGF - Progressive Graphics File

Loading...
Searching...
No Matches
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// prototypes
36class CDecoder;
37class CEncoder;
38class CWaveletTransform;
39
53 class CPGFImage {
54public:
55
58 CPGFImage();
59
62 virtual ~CPGFImage();
63
65 // Destroy internal data structures. Object state after this is the same as after CPGFImage().
66 void Destroy();
67
73 void Open(CPGFStream* stream);
74
77 bool IsOpen() const { return m_decoder != nullptr; }
78
91 void Read(int level = 0, CallbackPtr cb = nullptr, void *data = nullptr);
92
93#ifdef __PGFROISUPPORT__
103 void Read(PGFRect& rect, int level = 0, CallbackPtr cb = nullptr, void *data = nullptr);
104#endif
105
111 void ReadPreview() { Read(Levels() - 1); }
112
118 void Reconstruct(int level = 0);
119
137 void GetBitmap(int pitch, UINT8* buff, BYTE bpp, int channelMap[] = nullptr, CallbackPtr cb = nullptr, void *data = nullptr) const; // throws IOException
138
154 void GetYUV(int pitch, DataT* buff, BYTE bpp, int channelMap[] = nullptr, CallbackPtr cb = nullptr, void *data = nullptr) const; // throws IOException
155
172 void ImportBitmap(int pitch, UINT8 *buff, BYTE bpp, int channelMap[] = nullptr, CallbackPtr cb = nullptr, void *data = nullptr);
173
189 void ImportYUV(int pitch, DataT *buff, BYTE bpp, int channelMap[] = nullptr, CallbackPtr cb = nullptr, void *data = nullptr);
190
204 void Write(CPGFStream* stream, UINT32* nWrittenBytes = nullptr, CallbackPtr cb = nullptr, void *data = nullptr);
205
213 UINT32 WriteHeader(CPGFStream* stream);
214
225 UINT32 WriteImage(CPGFStream* stream, CallbackPtr cb = nullptr, void *data = nullptr);
226
227#ifdef __PGFROISUPPORT__
243 UINT32 Write(int level, CallbackPtr cb = nullptr, void *data = nullptr);
244#endif
245
250 void ConfigureEncoder(bool useOMP = true, bool favorSpeedOverSize = false) { m_useOMPinEncoder = useOMP; m_favorSpeedOverSize = favorSpeedOverSize; }
251
260 void ConfigureDecoder(bool useOMP = true, UserdataPolicy policy = UP_CacheAll, UINT32 prefixSize = 0) { ASSERT(prefixSize <= MaxUserDataSize); m_useOMPinDecoder = useOMP; m_userDataPolicy = (UP_CachePrefix) ? prefixSize : 0xFFFFFFFF - policy; }
261
266 void ResetStreamPos(bool startOfData);
267
272 void SetChannel(DataT* channel, int c = 0) { ASSERT(c >= 0 && c < MaxChannels); m_channel[c] = channel; }
273
282 void SetHeader(const PGFHeader& header, BYTE flags = 0, const UINT8* userData = 0, UINT32 userDataLength = 0); // throws IOException
283
288 void SetMaxValue(UINT32 maxValue);
289
296 void SetProgressMode(ProgressMode pm) { m_progressMode = pm; }
297
303 void SetRefreshCallback(RefreshCB callback, void* arg) { m_cb = callback; m_cbArg = arg; }
304
311 void SetColorTable(UINT32 iFirstColor, UINT32 nColors, const RGBQUAD* prgbColors);
312
317 DataT* GetChannel(int c = 0) { ASSERT(c >= 0 && c < MaxChannels); return m_channel[c]; }
318
325 void GetColorTable(UINT32 iFirstColor, UINT32 nColors, RGBQUAD* prgbColors) const;
326
328 // Returns address of internal color table
330 const RGBQUAD* GetColorTable() const { return m_postHeader.clut; }
331
335 const PGFHeader* GetHeader() const { return &m_header; }
336
341 UINT32 GetMaxValue() const { return (1 << m_header.usedBitsPerChannel) - 1; }
342
346 UINT64 GetUserDataPos() const { return m_userDataPos; }
347
354 const UINT8* GetUserData(UINT32& cachedSize, UINT32* pTotalSize = nullptr) const;
355
360 UINT32 GetEncodedHeaderLength() const;
361
367 UINT32 GetEncodedLevelLength(int level) const { ASSERT(level >= 0 && level < m_header.nLevels); return m_levelLength[m_header.nLevels - level - 1]; }
368
376 UINT32 ReadEncodedHeader(UINT8* target, UINT32 targetLen) const;
377
387 UINT32 ReadEncodedData(int level, UINT8* target, UINT32 targetLen) const;
388
394 UINT32 ChannelWidth(int c = 0) const { ASSERT(c >= 0 && c < MaxChannels); return m_width[c]; }
395
401 UINT32 ChannelHeight(int c = 0) const { ASSERT(c >= 0 && c < MaxChannels); return m_height[c]; }
402
406 BYTE ChannelDepth() const { return MaxChannelDepth(m_preHeader.version); }
407
413 UINT32 Width(int level = 0) const { ASSERT(level >= 0); return LevelSizeL(m_header.width, level); }
414
420 UINT32 Height(int level = 0) const { ASSERT(level >= 0); return LevelSizeL(m_header.height, level); }
421
427 BYTE Level() const { return (BYTE)m_currentLevel; }
428
432 BYTE Levels() const { return m_header.nLevels; }
433
436 bool IsFullyRead() const { return m_currentLevel == 0; }
437
442 BYTE Quality() const { return m_header.quality; }
443
448 BYTE Channels() const { return m_header.channels; }
449
455 BYTE Mode() const { return m_header.mode; }
456
461 BYTE BPP() const { return m_header.bpp; }
462
466 bool ROIisSupported() const { return (m_preHeader.version & PGFROI) == PGFROI; }
467
468#ifdef __PGFROISUPPORT__
472 PGFRect ComputeLevelROI() const;
473#endif
474
479 BYTE UsedBitsPerChannel() const;
480
484 BYTE Version() const { BYTE ver = CodecMajorVersion(m_preHeader.version); return (ver <= 7) ? ver : (BYTE)m_header.version.major; }
485
486 //class methods
487
492 static bool ImportIsSupported(BYTE mode);
493
499 static UINT32 LevelSizeL(UINT32 size, int level) { ASSERT(level >= 0); UINT32 d = 1 << level; return (size + d - 1) >> level; }
500
506 static UINT32 LevelSizeH(UINT32 size, int level) { ASSERT(level >= 0); UINT32 d = 1 << (level - 1); return (size + d - 1) >> level; }
507
512 static BYTE CodecMajorVersion(BYTE version = PGFVersion);
513
518 static BYTE MaxChannelDepth(BYTE version = PGFVersion) { return (version & PGF32) ? 32 : 16; }
519
520protected:
521 CWaveletTransform* m_wtChannel[MaxChannels];
522 DataT* m_channel[MaxChannels];
523 CDecoder* m_decoder;
524 CEncoder* m_encoder;
525 UINT32* m_levelLength;
526 UINT32 m_width[MaxChannels];
527 UINT32 m_height[MaxChannels];
528 PGFPreHeader m_preHeader;
529 PGFHeader m_header;
530 PGFPostHeader m_postHeader;
531 UINT64 m_userDataPos;
532 int m_currentLevel;
533 UINT32 m_userDataPolicy;
534 BYTE m_quant;
535 bool m_downsample;
536 bool m_favorSpeedOverSize;
537 bool m_useOMPinEncoder;
538 bool m_useOMPinDecoder;
539#ifdef __PGFROISUPPORT__
540 bool m_streamReinitialized;
541 PGFRect m_roi;
542#endif
543
544private:
545 RefreshCB m_cb;
546 void *m_cbArg;
547 double m_percent;
548 ProgressMode m_progressMode;
549
550 void Init();
551 void ComputeLevels();
552 bool CompleteHeader();
553 void RgbToYuv(int pitch, UINT8* rgbBuff, BYTE bpp, int channelMap[], CallbackPtr cb, void *data);
554 void Downsample(int nChannel);
555 UINT32 UpdatePostHeaderSize();
556 void WriteLevel();
557
558#ifdef __PGFROISUPPORT__
559 PGFRect GetAlignedROI(int c = 0) const;
560 void SetROI(PGFRect rect);
561#endif
562
563 UINT8 Clamp4(DataT v) const {
564 if (v & 0xFFFFFFF0) return (v < 0) ? (UINT8)0: (UINT8)15; else return (UINT8)v;
565 }
566 UINT16 Clamp6(DataT v) const {
567 if (v & 0xFFFFFFC0) return (v < 0) ? (UINT16)0: (UINT16)63; else return (UINT16)v;
568 }
569 UINT8 Clamp8(DataT v) const {
570 // needs only one test in the normal case
571 if (v & 0xFFFFFF00) return (v < 0) ? (UINT8)0 : (UINT8)255; else return (UINT8)v;
572 }
573 UINT16 Clamp16(DataT v) const {
574 if (v & 0xFFFF0000) return (v < 0) ? (UINT16)0: (UINT16)65535; else return (UINT16)v;
575 }
576 UINT32 Clamp31(DataT v) const {
577 return (v < 0) ? 0 : (UINT32)v;
578 }
579};
580
581#endif //PGF_PGFIMAGE_H
PGFstream.h
PGF stream class.
ProgressMode
ProgressMode
Definition PGFtypes.h:100
PGFROI
#define PGFROI
supports Regions Of Interest
Definition PGFtypes.h:70
UserdataPolicy
UserdataPolicy
Definition PGFtypes.h:101
UP_CachePrefix
@ UP_CachePrefix
Definition PGFtypes.h:101
UP_CacheAll
@ UP_CacheAll
Definition PGFtypes.h:101
MaxUserDataSize
#define MaxUserDataSize
Definition PGFtypes.h:284
RefreshCB
void(* RefreshCB)(void *p)
Definition PGFtypes.h:274
MaxChannels
#define MaxChannels
maximum number of (color) channels
Definition PGFtypes.h:64
PGF32
#define PGF32
32 bit values are used -> allows at maximum 30 input bits, otherwise 16 bit values are used -> allows...
Definition PGFtypes.h:69
PGFVersion
#define PGFVersion
current standard version
Definition PGFtypes.h:76
DataT
INT32 DataT
Definition PGFtypes.h:269
CDecoder
PGF decoder.
Definition Decoder.h:46
CEncoder
PGF encoder.
Definition Encoder.h:46
CPGFImage::m_useOMPinDecoder
bool m_useOMPinDecoder
use Open MP in decoder
Definition PGFimage.h:538
CPGFImage::Clamp31
UINT32 Clamp31(DataT v) const
Definition PGFimage.h:576
CPGFImage::ChannelHeight
UINT32 ChannelHeight(int c=0) const
Definition PGFimage.h:401
CPGFImage::WriteImage
UINT32 WriteImage(CPGFStream *stream, CallbackPtr cb=nullptr, void *data=nullptr)
Definition PGFimage.cpp:1150
CPGFImage::CompleteHeader
bool CompleteHeader()
Definition PGFimage.cpp:218
CPGFImage::m_decoder
CDecoder * m_decoder
PGF decoder.
Definition PGFimage.h:523
CPGFImage::WriteLevel
void WriteLevel()
Definition PGFimage.cpp:1068
CPGFImage::ReadPreview
void ReadPreview()
Definition PGFimage.h:111
CPGFImage::m_useOMPinEncoder
bool m_useOMPinEncoder
use Open MP in encoder
Definition PGFimage.h:537
CPGFImage::Clamp6
UINT16 Clamp6(DataT v) const
Definition PGFimage.h:566
CPGFImage::m_levelLength
UINT32 * m_levelLength
length of each level in bytes; first level starts immediately after this array
Definition PGFimage.h:525
CPGFImage::m_height
UINT32 m_height[MaxChannels]
height of each channel at current level
Definition PGFimage.h:527
CPGFImage::m_userDataPolicy
UINT32 m_userDataPolicy
user data (metadata) policy during open
Definition PGFimage.h:533
CPGFImage::m_header
PGFHeader m_header
PGF file header.
Definition PGFimage.h:529
CPGFImage::GetAlignedROI
PGFRect GetAlignedROI(int c=0) const
Definition PGFimage.cpp:598
CPGFImage::~CPGFImage
virtual ~CPGFImage()
Destructor.
Definition PGFimage.cpp:117
CPGFImage::WriteHeader
UINT32 WriteHeader(CPGFStream *stream)
Definition PGFimage.cpp:979
CPGFImage::Downsample
void Downsample(int nChannel)
Definition PGFimage.cpp:810
CPGFImage::SetHeader
void SetHeader(const PGFHeader &header, BYTE flags=0, const UINT8 *userData=0, UINT32 userDataLength=0)
Definition PGFimage.cpp:894
CPGFImage::GetMaxValue
UINT32 GetMaxValue() const
Definition PGFimage.h:341
CPGFImage::GetUserDataPos
UINT64 GetUserDataPos() const
Definition PGFimage.h:346
CPGFImage::m_currentLevel
int m_currentLevel
transform level of current image
Definition PGFimage.h:532
CPGFImage::SetChannel
void SetChannel(DataT *channel, int c=0)
Definition PGFimage.h:272
CPGFImage::ConfigureEncoder
void ConfigureEncoder(bool useOMP=true, bool favorSpeedOverSize=false)
Definition PGFimage.h:250
CPGFImage::Width
UINT32 Width(int level=0) const
Definition PGFimage.h:413
CPGFImage::SetColorTable
void SetColorTable(UINT32 iFirstColor, UINT32 nColors, const RGBQUAD *prgbColors)
Definition PGFimage.cpp:1364
CPGFImage::MaxChannelDepth
static BYTE MaxChannelDepth(BYTE version=PGFVersion)
Definition PGFimage.h:518
CPGFImage::m_channel
DataT * m_channel[MaxChannels]
untransformed channels in YUV format
Definition PGFimage.h:522
CPGFImage::GetYUV
void GetYUV(int pitch, DataT *buff, BYTE bpp, int channelMap[]=nullptr, CallbackPtr cb=nullptr, void *data=nullptr) const
Definition PGFimage.cpp:2550
CPGFImage::IsFullyRead
bool IsFullyRead() const
Return true if all levels have been read.
Definition PGFimage.h:436
CPGFImage::ImportBitmap
void ImportBitmap(int pitch, UINT8 *buff, BYTE bpp, int channelMap[]=nullptr, CallbackPtr cb=nullptr, void *data=nullptr)
Definition PGFimage.cpp:792
CPGFImage::ChannelWidth
UINT32 ChannelWidth(int c=0) const
Definition PGFimage.h:394
CPGFImage::m_cbArg
void * m_cbArg
refresh callback argument
Definition PGFimage.h:546
CPGFImage::Level
BYTE Level() const
Definition PGFimage.h:427
CPGFImage::ConfigureDecoder
void ConfigureDecoder(bool useOMP=true, UserdataPolicy policy=UP_CacheAll, UINT32 prefixSize=0)
Definition PGFimage.h:260
CPGFImage::Read
void Read(int level=0, CallbackPtr cb=nullptr, void *data=nullptr)
Definition PGFimage.cpp:402
CPGFImage::Destroy
void Destroy()
Definition PGFimage.cpp:124
CPGFImage::ReadEncodedHeader
UINT32 ReadEncodedHeader(UINT8 *target, UINT32 targetLen) const
Definition PGFimage.cpp:660
CPGFImage::ImportYUV
void ImportYUV(int pitch, DataT *buff, BYTE bpp, int channelMap[]=nullptr, CallbackPtr cb=nullptr, void *data=nullptr)
Definition PGFimage.cpp:2661
CPGFImage::ReadEncodedData
UINT32 ReadEncodedData(int level, UINT8 *target, UINT32 targetLen) const
Definition PGFimage.cpp:707
CPGFImage::m_quant
BYTE m_quant
quantization parameter
Definition PGFimage.h:534
CPGFImage::CodecMajorVersion
static BYTE CodecMajorVersion(BYTE version=PGFVersion)
Return major version.
Definition PGFimage.cpp:768
CPGFImage::ImportIsSupported
static bool ImportIsSupported(BYTE mode)
Definition PGFimage.cpp:1305
CPGFImage::ChannelDepth
BYTE ChannelDepth() const
Definition PGFimage.h:406
CPGFImage::Clamp16
UINT16 Clamp16(DataT v) const
Definition PGFimage.h:573
CPGFImage::m_favorSpeedOverSize
bool m_favorSpeedOverSize
favor encoding speed over compression ratio
Definition PGFimage.h:536
CPGFImage::SetMaxValue
void SetMaxValue(UINT32 maxValue)
Definition PGFimage.cpp:738
CPGFImage::GetBitmap
void GetBitmap(int pitch, UINT8 *buff, BYTE bpp, int channelMap[]=nullptr, CallbackPtr cb=nullptr, void *data=nullptr) const
Definition PGFimage.cpp:1789
CPGFImage::UsedBitsPerChannel
BYTE UsedBitsPerChannel() const
Definition PGFimage.cpp:756
CPGFImage::Quality
BYTE Quality() const
Definition PGFimage.h:442
CPGFImage::ComputeLevelROI
PGFRect ComputeLevelROI() const
Definition PGFimage.cpp:583
CPGFImage::m_encoder
CEncoder * m_encoder
PGF encoder.
Definition PGFimage.h:524
CPGFImage::IsOpen
bool IsOpen() const
Returns true if the PGF has been opened for reading.
Definition PGFimage.h:77
CPGFImage::Clamp8
UINT8 Clamp8(DataT v) const
Definition PGFimage.h:569
CPGFImage::m_roi
PGFRect m_roi
region of interest
Definition PGFimage.h:541
CPGFImage::RgbToYuv
void RgbToYuv(int pitch, UINT8 *rgbBuff, BYTE bpp, int channelMap[], CallbackPtr cb, void *data)
Definition PGFimage.cpp:1389
CPGFImage::GetHeader
const PGFHeader * GetHeader() const
Definition PGFimage.h:335
CPGFImage::ResetStreamPos
void ResetStreamPos(bool startOfData)
Definition PGFimage.cpp:682
CPGFImage::SetROI
void SetROI(PGFRect rect)
Definition PGFimage.cpp:615
CPGFImage::m_progressMode
ProgressMode m_progressMode
progress mode used in Read and Write; PM_Relative is default mode
Definition PGFimage.h:548
CPGFImage::Mode
BYTE Mode() const
Definition PGFimage.h:455
CPGFImage::UpdatePostHeaderSize
UINT32 UpdatePostHeaderSize()
Definition PGFimage.cpp:1124
CPGFImage::m_downsample
bool m_downsample
chrominance channels are downsampled
Definition PGFimage.h:535
CPGFImage::LevelSizeH
static UINT32 LevelSizeH(UINT32 size, int level)
Definition PGFimage.h:506
CPGFImage::GetEncodedLevelLength
UINT32 GetEncodedLevelLength(int level) const
Definition PGFimage.h:367
CPGFImage::ROIisSupported
bool ROIisSupported() const
Definition PGFimage.h:466
CPGFImage::GetUserData
const UINT8 * GetUserData(UINT32 &cachedSize, UINT32 *pTotalSize=nullptr) const
Definition PGFimage.cpp:337
CPGFImage::Version
BYTE Version() const
Definition PGFimage.h:484
CPGFImage::Height
UINT32 Height(int level=0) const
Definition PGFimage.h:420
CPGFImage::Init
void Init()
Definition PGFimage.cpp:69
CPGFImage::Levels
BYTE Levels() const
Definition PGFimage.h:432
CPGFImage::m_width
UINT32 m_width[MaxChannels]
width of each channel at current level
Definition PGFimage.h:526
CPGFImage::m_postHeader
PGFPostHeader m_postHeader
PGF post-header.
Definition PGFimage.h:530
CPGFImage::GetChannel
DataT * GetChannel(int c=0)
Definition PGFimage.h:317
CPGFImage::SetRefreshCallback
void SetRefreshCallback(RefreshCB callback, void *arg)
Definition PGFimage.h:303
CPGFImage::Reconstruct
void Reconstruct(int level=0)
Definition PGFimage.cpp:348
CPGFImage::m_cb
RefreshCB m_cb
pointer to refresh callback procedure
Definition PGFimage.h:545
CPGFImage::GetColorTable
const RGBQUAD * GetColorTable() const
Definition PGFimage.h:330
CPGFImage::Write
void Write(CPGFStream *stream, UINT32 *nWrittenBytes=nullptr, CallbackPtr cb=nullptr, void *data=nullptr)
Definition PGFimage.cpp:1221
CPGFImage::BPP
BYTE BPP() const
Definition PGFimage.h:461
CPGFImage::m_userDataPos
UINT64 m_userDataPos
stream position of user data
Definition PGFimage.h:531
CPGFImage::GetEncodedHeaderLength
UINT32 GetEncodedHeaderLength() const
Definition PGFimage.cpp:648
CPGFImage::ComputeLevels
void ComputeLevels()
Definition PGFimage.cpp:854
CPGFImage::SetProgressMode
void SetProgressMode(ProgressMode pm)
Definition PGFimage.h:296
CPGFImage::m_preHeader
PGFPreHeader m_preHeader
PGF pre-header.
Definition PGFimage.h:528
CPGFImage::LevelSizeL
static UINT32 LevelSizeL(UINT32 size, int level)
Definition PGFimage.h:499
CPGFImage::Open
void Open(CPGFStream *stream)
Definition PGFimage.cpp:141
CPGFImage::m_percent
double m_percent
progress [0..1]
Definition PGFimage.h:547
CPGFImage::Clamp4
UINT8 Clamp4(DataT v) const
Definition PGFimage.h:563
CPGFImage::m_wtChannel
CWaveletTransform * m_wtChannel[MaxChannels]
wavelet transformed color channels
Definition PGFimage.h:521
CPGFImage::m_streamReinitialized
bool m_streamReinitialized
stream has been reinitialized
Definition PGFimage.h:540
CPGFImage::Channels
BYTE Channels() const
Definition PGFimage.h:448
CPGFImage::CPGFImage
CPGFImage()
Standard constructor.
Definition PGFimage.cpp:64
CPGFStream
Abstract stream base class.
Definition PGFstream.h:39
CWaveletTransform
PGF wavelet transform.
Definition WaveletTransform.h:55
PGFHeader
PGF header.
Definition PGFtypes.h:151
PGFPostHeader
Optional PGF post-header.
Definition PGFtypes.h:169
PGFPreHeader
PGF pre-header.
Definition PGFtypes.h:123
PGFRect
Rectangle.
Definition PGFtypes.h:225