libpgf 7.26.45
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#pragma once
30
31#include "PGFstream.h"
32
33namespace pgf {
35 // prototypes
36 class CDecoder;
37 class CEncoder;
39
53 class CPGFImage {
54 public:
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_t* buff, uint8_t bpp, int channelMap[] = nullptr, CallbackPtr cb = nullptr, void* data = nullptr) const; // throws IOException
138
154 void GetYUV(int pitch, DataT* buff, uint8_t bpp, int channelMap[] = nullptr, CallbackPtr cb = nullptr, void* data = nullptr) const; // throws IOException
155
172 void ImportBitmap(int pitch, uint8_t* buff, uint8_t bpp, int channelMap[] = nullptr, CallbackPtr cb = nullptr, void* data = nullptr);
173
189 void ImportYUV(int pitch, DataT* buff, uint8_t bpp, int channelMap[] = nullptr, CallbackPtr cb = nullptr, void* data = nullptr);
190
204 void Write(CPGFStream* stream, uint32_t* nWrittenBytes = nullptr, CallbackPtr cb = nullptr, void* data = nullptr);
205
213 uint32_t WriteHeader(CPGFStream* stream);
214
225 uint32_t WriteImage(CPGFStream* stream, CallbackPtr cb = nullptr, void* data = nullptr);
226
227#ifdef __PGFROISUPPORT__
243 uint32_t 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, UP::Policy policy = UP::CacheAll, uint32_t prefixSize = 0) {
261 ASSERT(prefixSize <= MaxUserDataSize);
262 m_useOMPinDecoder = useOMP;
263 m_userDataPolicy = (policy == UP::CachePrefix) ? prefixSize : 0xFFFFFFFF - policy;
264 }
265
270 void ResetStreamPos(bool startOfData);
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, uint8_t flags = 0, const uint8_t* userData = 0, uint32_t userDataLength = 0); // throws IOException
287
292 void SetMaxValue(uint32_t maxValue);
293
301
307 void SetRefreshCallback(RefreshCB callback, void* arg) { m_cb = callback; m_cbArg = arg; }
308
315 void SetColorTable(uint32_t iFirstColor, uint32_t nColors, const RGBQUAD* prgbColors);
316
321 DataT* GetChannel(int c = 0) { ASSERT(c >= 0 && c < MaxChannels); return m_channel[c]; }
322
329 void GetColorTable(uint32_t iFirstColor, uint32_t nColors, RGBQUAD* prgbColors) const;
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_t GetMaxValue() const { return (1 << m_header.usedBitsPerChannel) - 1; }
346
350 uint64_t GetUserDataPos() const { return m_userDataPos; }
351
358 const uint8_t* GetUserData(uint32_t& cachedSize, uint32_t* pTotalSize = nullptr) const;
359
364 uint32_t GetEncodedHeaderLength() const;
365
371 uint32_t GetEncodedLevelLength(int level) const { ASSERT(level >= 0 && level < m_header.nLevels); return m_levelLength[m_header.nLevels - level - 1]; }
372
380 uint32_t ReadEncodedHeader(uint8_t* target, uint32_t targetLen) const;
381
391 uint32_t ReadEncodedData(int level, uint8_t* target, uint32_t targetLen) const;
392
398 uint32_t ChannelWidth(int c = 0) const { ASSERT(c >= 0 && c < MaxChannels); return m_width[c]; }
399
405 uint32_t ChannelHeight(int c = 0) const { ASSERT(c >= 0 && c < MaxChannels); return m_height[c]; }
406
410 uint8_t ChannelDepth() const { return MaxChannelDepth(m_preHeader.version); }
411
417 uint32_t Width(int level = 0) const { ASSERT(level >= 0); return LevelSizeL(m_header.width, level); }
418
424 uint32_t Height(int level = 0) const { ASSERT(level >= 0); return LevelSizeL(m_header.height, level); }
425
431 uint8_t Level() const { return (uint8_t)m_currentLevel; }
432
436 uint8_t Levels() const { return m_header.nLevels; }
437
440 bool IsFullyRead() const { return m_currentLevel == 0; }
441
446 uint8_t Quality() const { return m_header.quality; }
447
452 uint8_t Channels() const { return m_header.channels; }
453
459 uint8_t Mode() const { return m_header.mode; }
460
465 uint8_t BPP() const { return m_header.bpp; }
466
470 bool ROIisSupported() const { return (m_preHeader.version & PGFROI) == PGFROI; }
471
472#ifdef __PGFROISUPPORT__
476 PGFRect ComputeLevelROI() const;
477#endif
478
483 uint8_t UsedBitsPerChannel() const;
484
488 uint8_t Version() const { uint8_t ver = CodecMajorVersion(m_preHeader.version); return (ver <= 7) ? ver : (uint8_t)m_header.version.major; }
489
490 //class methods
491
496 static bool ImportIsSupported(uint8_t mode);
497
503 static uint32_t LevelSizeL(uint32_t size, int level) { ASSERT(level >= 0); uint32_t d = 1 << level; return (size + d - 1) >> level; }
504
510 static uint32_t LevelSizeH(uint32_t size, int level) { ASSERT(level >= 0); uint32_t d = 1 << (level - 1); return (size + d - 1) >> level; }
511
516 static uint8_t CodecMajorVersion(uint8_t version = PGFVersion);
517
522 static uint8_t MaxChannelDepth(uint8_t version = PGFVersion) { return (version & PGF32) ? 32 : 16; }
523
524 protected:
529 uint32_t* m_levelLength;
535 uint64_t m_userDataPos;
538 uint8_t m_quant;
543#ifdef __PGFROISUPPORT__
546#endif
547
548 private:
550 void* m_cbArg;
551 double m_percent;
553
554 void Init();
555 void ComputeLevels();
556 bool CompleteHeader();
557 void RgbToYuv(int pitch, uint8_t* rgbBuff, uint8_t bpp, int channelMap[], CallbackPtr cb, void* data);
558 void Downsample(int nChannel);
559 uint32_t UpdatePostHeaderSize();
560 void WriteLevel();
561
562#ifdef __PGFROISUPPORT__
563 PGFRect GetAlignedROI(int c = 0) const;
564 void SetROI(PGFRect rect);
565#endif
566
567 uint8_t Clamp4(DataT v) const {
568 if (v & 0xFFFFFFF0) return (v < 0) ? (uint8_t)0 : (uint8_t)15; else return (uint8_t)v;
569 }
570 uint16_t Clamp6(DataT v) const {
571 if (v & 0xFFFFFFC0) return (v < 0) ? (uint16_t)0 : (uint16_t)63; else return (uint16_t)v;
572 }
573 uint8_t Clamp8(DataT v) const {
574 // needs only one test in the normal case
575 if (v & 0xFFFFFF00) return (v < 0) ? (uint8_t)0 : (uint8_t)255; else return (uint8_t)v;
576 }
577 uint16_t Clamp16(DataT v) const {
578 if (v & 0xFFFF0000) return (v < 0) ? (uint16_t)0 : (uint16_t)65535; else return (uint16_t)v;
579 }
580 uint32_t Clamp31(DataT v) const {
581 return (v < 0) ? 0 : (uint32_t)v;
582 }
583 };
584}
PGF stream class.
PGF decoder.
Definition Decoder.h:41
PGF encoder.
Definition Encoder.h:41
void ComputeLevels()
Definition PGFimage.cpp:858
uint32_t WriteImage(CPGFStream *stream, CallbackPtr cb=nullptr, void *data=nullptr)
uint8_t Mode() const
Definition PGFimage.h:459
void SetHeader(const PGFHeader &header, uint8_t flags=0, const uint8_t *userData=0, uint32_t userDataLength=0)
Definition PGFimage.cpp:898
CWaveletTransform * m_wtChannel[MaxChannels]
wavelet transformed color channels
Definition PGFimage.h:525
const PGFHeader * GetHeader() const
Definition PGFimage.h:339
uint8_t Clamp8(DataT v) const
Definition PGFimage.h:573
void ImportBitmap(int pitch, uint8_t *buff, uint8_t bpp, int channelMap[]=nullptr, CallbackPtr cb=nullptr, void *data=nullptr)
Definition PGFimage.cpp:796
void Write(CPGFStream *stream, uint32_t *nWrittenBytes=nullptr, CallbackPtr cb=nullptr, void *data=nullptr)
bool IsOpen() const
Returns true if the PGF has been opened for reading.
Definition PGFimage.h:77
CPGFImage()
Standard constructor.
Definition PGFimage.cpp:65
void SetRefreshCallback(RefreshCB callback, void *arg)
Definition PGFimage.h:307
PGFRect m_roi
region of interest
Definition PGFimage.h:545
PGFPreHeader m_preHeader
PGF pre-header.
Definition PGFimage.h:532
uint32_t * m_levelLength
length of each level in bytes; first level starts immediately after this array
Definition PGFimage.h:529
uint16_t Clamp16(DataT v) const
Definition PGFimage.h:577
bool ROIisSupported() const
Definition PGFimage.h:470
uint32_t GetMaxValue() const
Definition PGFimage.h:345
void SetProgressMode(ProgressMode pm)
Definition PGFimage.h:300
void ImportYUV(int pitch, DataT *buff, uint8_t bpp, int channelMap[]=nullptr, CallbackPtr cb=nullptr, void *data=nullptr)
void Reconstruct(int level=0)
Definition PGFimage.cpp:352
const RGBQUAD * GetColorTable() const
Definition PGFimage.h:334
uint8_t Channels() const
Definition PGFimage.h:452
void Open(CPGFStream *stream)
Definition PGFimage.cpp:145
static uint8_t MaxChannelDepth(uint8_t version=PGFVersion)
Definition PGFimage.h:522
static uint8_t CodecMajorVersion(uint8_t version=PGFVersion)
Return major version.
Definition PGFimage.cpp:772
void ResetStreamPos(bool startOfData)
Definition PGFimage.cpp:686
uint8_t Level() const
Definition PGFimage.h:431
uint8_t ChannelDepth() const
Definition PGFimage.h:410
uint32_t GetEncodedLevelLength(int level) const
Definition PGFimage.h:371
uint32_t ChannelWidth(int c=0) const
Definition PGFimage.h:398
static bool ImportIsSupported(uint8_t mode)
PGFHeader m_header
PGF file header.
Definition PGFimage.h:533
uint8_t UsedBitsPerChannel() const
Definition PGFimage.cpp:760
uint32_t GetEncodedHeaderLength() const
Definition PGFimage.cpp:652
uint32_t ReadEncodedData(int level, uint8_t *target, uint32_t targetLen) const
Definition PGFimage.cpp:711
void SetMaxValue(uint32_t maxValue)
Definition PGFimage.cpp:742
void SetColorTable(uint32_t iFirstColor, uint32_t nColors, const RGBQUAD *prgbColors)
void ReadPreview()
Definition PGFimage.h:111
uint8_t BPP() const
Definition PGFimage.h:465
uint16_t Clamp6(DataT v) const
Definition PGFimage.h:570
void RgbToYuv(int pitch, uint8_t *rgbBuff, uint8_t bpp, int channelMap[], CallbackPtr cb, void *data)
bool IsFullyRead() const
Return true if all levels have been read.
Definition PGFimage.h:440
uint32_t m_height[MaxChannels]
height of each channel at current level
Definition PGFimage.h:531
uint32_t Clamp31(DataT v) const
Definition PGFimage.h:580
uint32_t m_userDataPolicy
user data (metadata) policy during open
Definition PGFimage.h:537
double m_percent
progress [0..1]
Definition PGFimage.h:551
RefreshCB m_cb
pointer to refresh callback procedure
Definition PGFimage.h:549
uint64_t m_userDataPos
stream position of user data
Definition PGFimage.h:535
uint32_t UpdatePostHeaderSize()
void GetBitmap(int pitch, uint8_t *buff, uint8_t bpp, int channelMap[]=nullptr, CallbackPtr cb=nullptr, void *data=nullptr) const
uint8_t Levels() const
Definition PGFimage.h:436
bool CompleteHeader()
Definition PGFimage.cpp:222
void SetChannel(DataT *channel, int c=0)
Definition PGFimage.h:276
uint32_t m_width[MaxChannels]
width of each channel at current level
Definition PGFimage.h:530
uint32_t ReadEncodedHeader(uint8_t *target, uint32_t targetLen) const
Definition PGFimage.cpp:664
void * m_cbArg
refresh callback argument
Definition PGFimage.h:550
bool m_streamReinitialized
stream has been reinitialized
Definition PGFimage.h:544
PGFPostHeader m_postHeader
PGF post-header.
Definition PGFimage.h:534
void GetYUV(int pitch, DataT *buff, uint8_t bpp, int channelMap[]=nullptr, CallbackPtr cb=nullptr, void *data=nullptr) const
PGFRect ComputeLevelROI() const
Definition PGFimage.cpp:587
uint8_t Version() const
Definition PGFimage.h:488
void Read(int level=0, CallbackPtr cb=nullptr, void *data=nullptr)
Definition PGFimage.cpp:406
uint32_t Width(int level=0) const
Definition PGFimage.h:417
bool m_downsample
chrominance channels are downsampled
Definition PGFimage.h:539
static uint32_t LevelSizeL(uint32_t size, int level)
Definition PGFimage.h:503
CEncoder * m_encoder
PGF encoder.
Definition PGFimage.h:528
bool m_favorSpeedOverSize
favor encoding speed over compression ratio
Definition PGFimage.h:540
CDecoder * m_decoder
PGF decoder.
Definition PGFimage.h:527
uint32_t Height(int level=0) const
Definition PGFimage.h:424
ProgressMode m_progressMode
progress mode used in Read and Write; Relative is default mode
Definition PGFimage.h:552
bool m_useOMPinEncoder
use Open MP in encoder
Definition PGFimage.h:541
static uint32_t LevelSizeH(uint32_t size, int level)
Definition PGFimage.h:510
uint32_t ChannelHeight(int c=0) const
Definition PGFimage.h:405
const uint8_t * GetUserData(uint32_t &cachedSize, uint32_t *pTotalSize=nullptr) const
Definition PGFimage.cpp:341
void SetROI(PGFRect rect)
Definition PGFimage.cpp:619
void ConfigureDecoder(bool useOMP=true, UP::Policy policy=UP::CacheAll, uint32_t prefixSize=0)
Definition PGFimage.h:260
uint8_t m_quant
quantization parameter
Definition PGFimage.h:538
void Downsample(int nChannel)
Definition PGFimage.cpp:814
bool m_useOMPinDecoder
use Open MP in decoder
Definition PGFimage.h:542
void ConfigureEncoder(bool useOMP=true, bool favorSpeedOverSize=false)
Definition PGFimage.h:250
uint32_t WriteHeader(CPGFStream *stream)
Definition PGFimage.cpp:983
PGFRect GetAlignedROI(int c=0) const
Definition PGFimage.cpp:602
int m_currentLevel
transform level of current image
Definition PGFimage.h:536
DataT * GetChannel(int c=0)
Definition PGFimage.h:321
uint8_t Quality() const
Definition PGFimage.h:446
DataT * m_channel[MaxChannels]
untransformed channels in YUV format
Definition PGFimage.h:526
uint64_t GetUserDataPos() const
Definition PGFimage.h:350
uint8_t Clamp4(DataT v) const
Definition PGFimage.h:567
Abstract stream base class.
Definition PGFstream.h:39
PGF wavelet transform.
constexpr Policy CachePrefix
Definition PGFtypes.h:112
uint32_t Policy
Definition PGFtypes.h:110
constexpr Policy CacheAll
Definition PGFtypes.h:112
Definition PGFimage.h:33
constexpr int PGFVersion
current standard version
Definition PGFtypes.h:76
constexpr int PGF32
32 bit values are used -> allows at maximum 30 input bits, otherwise 16 bit values are used -> allows...
Definition PGFtypes.h:69
constexpr size_t MaxUserDataSize
Definition PGFtypes.h:382
constexpr int MaxChannels
maximum number of (color) channels
Definition PGFtypes.h:64
void(*) RefreshCB(void *p)
Definition PGFtypes.h:372
int32_t DataT
Definition PGFtypes.h:367
ProgressMode
Definition PGFtypes.h:114
constexpr int PGFROI
supports Regions Of Interest
Definition PGFtypes.h:70
PGF header.
Definition PGFtypes.h:169
uint8_t usedBitsPerChannel
number of used bits per channel in 16- and 32-bit per channel modes
Definition PGFtypes.h:177
uint8_t bpp
bits per pixel
Definition PGFtypes.h:174
uint8_t channels
number of channels
Definition PGFtypes.h:175
uint8_t nLevels
number of FWT transforms
Definition PGFtypes.h:172
uint8_t mode
image mode according to Adobe's image modes
Definition PGFtypes.h:176
uint32_t width
image width in pixels
Definition PGFtypes.h:170
uint8_t quality
quantization parameter: 0=lossless, 4=standard, 6=poor quality
Definition PGFtypes.h:173
uint32_t height
image height in pixels
Definition PGFtypes.h:171
PGFVersionNumber version
codec version number: (since Version 7)
Definition PGFtypes.h:178
uint8_t version
PGF version.
Definition PGFtypes.h:128
Optional PGF post-header.
Definition PGFtypes.h:199
RGBQUAD clut[ColorTableLen]
color table for indexed color images (optional part of file header)
Definition PGFtypes.h:200
PGF pre-header.
Definition PGFtypes.h:136
Rectangle.
Definition PGFtypes.h:258
uint16_t major
major version number
Definition PGFtypes.h:151