libpgf  6.12.24
PGF - Progressive Graphics File
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PGFimage.cpp File Reference
#include "PGFimage.h"
#include "Decoder.h"
#include "Encoder.h"
#include <cmath>
#include <cstring>

Go to the source code of this file.

Macros

#define YUVoffset4   8
 
#define YUVoffset6   32
 
#define YUVoffset8   128
 
#define YUVoffset16   32768
 

Functions

*After you ve written a PGF
you can call this method
followed by GetBitmap GetYUV
*to get a quick 
reconstruction (coded-> decoded image).*It might throw an IOException.*@param level The image level of the resulting image in the internal image buffer.*/void CPGFImage
 
 if (ROIisSupported())
 
 while (currentLevel > level)
 
return m_decoder GetEncodedHeaderLength ()
 
 ASSERT (targetLen > 0)
 
 ASSERT (m_decoder)
 
m_decoder SetStreamPosToStart ()
 
 ASSERT (len >=0 &&len<=targetLen)
 
 ASSERT (target)
 
m_decoder SetStreamPosToData ()
 
 for (int i=m_header.nLevels-1;i > level;i--)
 
m_decoder Skip (offset)
 
 if (bpc > 8)
 
 ASSERT (header.quality<=MaxQuality)
 
 memcpy (m_preHeader.magic, Magic, 3)
 
 CompleteHeader ()
 
 ComputeLevels ()
 
 if (m_header.quality > DownsampleThreshold &&(m_header.mode==ImageModeRGBColor||m_header.mode==ImageModeRGBA||m_header.mode==ImageModeRGB48||m_header.mode==ImageModeCMYKColor||m_header.mode==ImageModeCMYK64||m_header.mode==ImageModeLabColor||m_header.mode==ImageModeLab48))
 
 if (m_header.mode==ImageModeIndexedColor)
 
 if (userDataLength &&userData)
 
 for (int i=0;i< m_header.channels;i++)
 
*Create wavelet transform
channels and encoder Write
header at current stream
position *Call this method
before your first call of 
Write (int level) or WriteImage()
 
*Create wavelet transform
channels and encoder Write
header at current stream
position *Call this method
before your first call of but
after 
SetHeader ().*This method is called inside of Write(stream
 
*Encode and write the one and
only image at current stream
position *Call this method
after 
WriteHeader ().In case you want to write uncached metadata
 
*Encode and write a entire PGF image (header and image) at current stream position.*A PGF image is structered in levels
 
*Encode and write a entire PGF
numbered between and 
Levels ()-1.*Each level can be seen as a single image
 
*Encode and write a entire PGF
numbered between and
containing the same content
*as all other but in a
different 
size (width, height).*The image size at level i is double the size(width
 
*Retrieves blue(RGB) color
values from a range of entries
in the palette of the DIB
section.*It might throw an
IOException.*@param
iFirstColor The color table
index of the first entry to
retrieve.*@param nColors The
number of color table entries
to retrieve.*@param prgbColors
A pointer to the array of
RGBQUAD structures to retrieve
the color table entries.*/void
CPGFImage 
for (UINT32 i=iFirstColor, j=0;j< nColors;i++, j++)
 
*Get YUV image data in
interleaved then the image
buffer must point to the last
row of a bottom up 
image (first byte on last row).*if pitch is positive
 
*Get YUV image data in
interleaved then the image
buffer must point to the last
row of a bottom up then the
image buffer must point to the
first row of a top down 
image (first byte).*The sequence of output channels in the output image buffer does not need to be the same as provided by PGF.In case of different sequences you have to *provide a channelMap of size of expected channels(depending on image mode).For example
 

Variables

*Return user data and size of
user data
Precondition
 
return m_postHeader userData
 
*After you ve written a PGF image
 
 else
 
*Reads the encoded PGF headers
and copies it to a target
buffer UINT32 targetLen const 
THROW_
 
UINT32 len = __min(targetLen, GetEncodedHeaderLength())
 
*Reads the data of an encoded
PGF level and copies it to a
target buffer *without
decoding UINT8 * 
target
 
UINT64 offset = 0
 
*Set maximum intensity value
for image modes with more than
eight bits per channel *Call
this method after 
SetHeader
 
*Set PGF header and user data BYTE flags
 
m_preHeader version = PGFVersion | flags
 
m_preHeader hSize = HeaderSize
 
memcpym_header
 
 m_quant = m_header.quality
 
*Encode and write the one and
only image at current stream
position *Call this method
after *then do that after *It
might throw an IOException
*param stream A PGF stream
*param cb A pointer to a
callback procedure The
procedure is called after
writing a single level If cb
returns 
true
 
*Encode and write a entire PGF
numbered between and
containing the same content
*as all other 
levels
 
*Retrieves red
 
*Retrieves green
 
*Get YUV image data in interleaved format
 
*Get YUV image data in
interleaved then the image
buffer must point to the last
row of a bottom up then the
image buffer must point to the
first row of a top down PGF
provides a channel sequence
BGR in RGB color mode *If your
provided image buffer expects
a channel sequence 
VUY
 
*Get YUV image data in
interleaved then the image
buffer must point to the last
row of a bottom up then the
image buffer must point to the
first row of a top down PGF
provides a channel sequence
BGR in RGB color mode *If your
provided image buffer expects
a channel sequence then the
channelMap looks 
like
 
*Import a YUV image from a
specified image buffer *The
absolute value of pitch is the
number of bytes of an image
row *If pitch is 
negative
 

Macro Definition Documentation

#define YUVoffset16   32768

Definition at line 38 of file PGFimage.cpp.

#define YUVoffset4   8

Definition at line 35 of file PGFimage.cpp.

#define YUVoffset6   32

Definition at line 36 of file PGFimage.cpp.

#define YUVoffset8   128

Definition at line 37 of file PGFimage.cpp.

Function Documentation

ASSERT ( targetLen  ,
 
)
ASSERT ( m_decoder  )
ASSERT ( len >=0 &&len<=  targetLen)
ASSERT ( target  )
ASSERT ( header.quality<=  MaxQuality)
CompleteHeader ( )
ComputeLevels ( )
for ( int  i = m_header.nLevels - 1; i,
level;i--   
)

Definition at line 665 of file PGFimage.cpp.

{
offset += m_levelLength[m_header.nLevels - 1 - i];
}
for ( )

Definition at line 891 of file PGFimage.cpp.

{
// set current width and height
m_width[i] = m_header.width;
m_height[i] = m_header.height;
// allocate channels
ASSERT(!m_channel[i]);
m_channel[i] = new(std::nothrow) DataT[m_header.width*m_header.height];
if (!m_channel[i]) {
if (i) i--;
while(i) {
delete[] m_channel[i]; m_channel[i] = 0;
i--;
}
ReturnWithError(InsufficientMemory);
}
}
* Retrieves blue (RGB) color values from a range of entries in the palette of the DIB section. * It might throw an IOException. * @param iFirstColor The color table index of the first entry to retrieve. * @param nColors The number of color table entries to retrieve. * @param prgbColors A pointer to the array of RGBQUAD structures to retrieve the color table entries. */ void CPGFImage for ( UINT32  i = iFirstColor)

Definition at line 1272 of file PGFimage.cpp.

{
prgbColors[j] = m_postHeader.clut[i];
}
return m_decoder GetEncodedHeaderLength ( )
if ( ROIisSupported()  )

Definition at line 342 of file PGFimage.cpp.

{
// enable ROI reading
SetROI(PGFRect(0, 0, m_header.width, m_header.height));
}
if ( bpc  ,
 
)

Definition at line 705 of file PGFimage.cpp.

{
return m_header.usedBitsPerChannel;
} else {
if ( m_header.  quality,
DownsampleThreshold &&  m_header.mode==ImageModeRGBColor||m_header.mode==ImageModeRGBA||m_header.mode==ImageModeRGB48||m_header.mode==ImageModeCMYKColor||m_header.mode==ImageModeCMYK64||m_header.mode==ImageModeLabColor||m_header.mode==ImageModeLab48 
)

Definition at line 862 of file PGFimage.cpp.

{
m_downsample = true;
m_quant = m_header.quality - 1;
} else {
if ( m_header.  mode = ImageModeIndexedColor)

Definition at line 877 of file PGFimage.cpp.

{
// update header size
m_preHeader.hSize += ColorTableSize;
}
if ( userDataLength &&  userData)

Definition at line 881 of file PGFimage.cpp.

{
m_postHeader.userData = new(std::nothrow) UINT8[userDataLength];
if (!m_postHeader.userData) ReturnWithError(InsufficientMemory);
m_postHeader.userDataLen = userDataLength;
memcpy(m_postHeader.userData, userData, userDataLength);
// update header size
m_preHeader.hSize += userDataLength;
}
* Encode and write a entire PGF image ( header and  image)
* Get YUV image data in interleaved then the image buffer must point to the last row of a bottom up image ( first byte on last  row)
* Get YUV image data in interleaved then the image buffer must point to the last row of a bottom up then the image buffer must point to the first row of a top down image ( first  byte)
* Encode and write a entire PGF numbered between and Levels ( )
memcpy ( m_preHeader.  magic,
Magic  ,
 
)
* After you ve written a PGF you can call this method followed by GetBitmap GetYUV* to get a quick reconstruction ( coded-> decoded  image)

Definition at line 327 of file PGFimage.cpp.

{
if (m_header.nLevels == 0) {
// image didn't use wavelet transform
if (level == 0) {
for (int i=0; i < m_header.channels; i++) {
ASSERT(m_wtChannel[i]);
m_channel[i] = m_wtChannel[i]->GetSubband(0, LL)->GetBuffer();
}
}
} else {
* Create wavelet transform channels and encoder Write header at current stream position* Call this method before your first call of but after SetHeader ( )
m_decoder SetStreamPosToData ( )
m_decoder SetStreamPosToStart ( )
* Encode and write a entire PGF numbered between and containing the same content* as all other but in a different size ( width  ,
height   
)
m_decoder Skip ( offset  )
while ( currentLevel  ,
level   
)

Definition at line 347 of file PGFimage.cpp.

{
for (int i=0; i < m_header.channels; i++) {
ASSERT(m_wtChannel[i]);
// dequantize subbands
if (currentLevel == m_header.nLevels) {
// last level also has LL band
m_wtChannel[i]->GetSubband(currentLevel, LL)->Dequantize(m_quant);
}
m_wtChannel[i]->GetSubband(currentLevel, HL)->Dequantize(m_quant);
m_wtChannel[i]->GetSubband(currentLevel, LH)->Dequantize(m_quant);
m_wtChannel[i]->GetSubband(currentLevel, HH)->Dequantize(m_quant);
// inverse transform from m_wtChannel to m_channel
OSError err = m_wtChannel[i]->InverseTransform(currentLevel, &m_width[i], &m_height[i], &m_channel[i]);
if (err != NoError) ReturnWithError(err);
ASSERT(m_channel[i]);
}
currentLevel--;
}
* Create wavelet transform channels and encoder Write header at current stream position* Call this method before your first call of Write ( int  level)
*Encode and write the one and only image at current stream position *Call this method after *then do that after WriteHeader ( )

Variable Documentation

else
Initial value:
{
int currentLevel = m_header.nLevels

Definition at line 339 of file PGFimage.cpp.

* Set PGF header and user data BYTE flags

Definition at line 838 of file PGFimage.cpp.

* Get YUV image data in interleaved format

Definition at line 2444 of file PGFimage.cpp.

*Sets the green

Definition at line 1264 of file PGFimage.cpp.

m_preHeader hSize = HeaderSize

Definition at line 850 of file PGFimage.cpp.

*Import a YUV image from a specified image buffer *The absolute value of pitch is the number of bytes of an image row *If pitch is then buff points to the last row of a bottom up then buff points to the first row of a top down image

Definition at line 326 of file PGFimage.cpp.

return len = __min(targetLen, GetEncodedHeaderLength())

Definition at line 628 of file PGFimage.cpp.

* Encode and write a entire PGF numbered between and containing the same content* as all other levels

Definition at line 1131 of file PGFimage.cpp.

*Import a YUV image from a specified image buffer *The absolute value of pitch is the number of bytes of an image row *If pitch is then buff points to the last row of a bottom up then buff points to the first row of a top down PGF expects in RGB color mode a channel sequence BGR *If your provided image buffer contains a channel sequence then the channelMap looks like
Initial value:
{ 2, 1, 0 }.
* It might throw an IOException.
* @param pitch The number of bytes of a row of the image buffer.
* @param buff An image buffer.
* @param bpp The number of bits per pixel used in image buffer.
* @param channelMap A integer array containing the mapping of PGF channel ordering to expected channel ordering.
* @param cb A pointer to a callback procedure. The procedure is called after each copied buffer row. If cb returns true

Definition at line 2448 of file PGFimage.cpp.

memcpy& m_header

Definition at line 853 of file PGFimage.cpp.

m_quant = m_header.quality

Definition at line 873 of file PGFimage.cpp.

* Import a YUV image from a specified image buffer* The absolute value of pitch is the number of bytes of an image row* If pitch is negative

Definition at line 2555 of file PGFimage.cpp.

UINT64 offset = 0

Definition at line 663 of file PGFimage.cpp.

*Encode and write a entire PGF numbered between and containing the same content *as all other but in a different height of the image at level i *The image at level contains the original size * Precondition

Definition at line 321 of file PGFimage.cpp.

*Sets the red

Definition at line 1264 of file PGFimage.cpp.

* Set maximum intensity value for image modes with more than eight bits per channel* Call this method after SetHeader

Definition at line 682 of file PGFimage.cpp.

* Reads the data of an encoded PGF level and copies it to a target buffer* without decoding UINT8* target

Definition at line 653 of file PGFimage.cpp.

* Set PGF header and user data BYTE UINT8 UINT32 userDataLength THROW_
Initial value:

Definition at line 619 of file PGFimage.cpp.

* Encode and write the one and only image at current stream position* Call this method after * then do that after * It might throw an IOException* param stream A PGF stream* param cb A pointer to a callback procedure The procedure is called after writing a single level If cb returns true

Definition at line 1066 of file PGFimage.cpp.

*Set PGF header and user data BYTE UINT8 * userData

Definition at line 322 of file PGFimage.cpp.

m_preHeader version = PGFVersion | flags

Definition at line 849 of file PGFimage.cpp.

*Import a YUV image from a specified image buffer *The absolute value of pitch is the number of bytes of an image row *If pitch is then buff points to the last row of a bottom up then buff points to the first row of a top down PGF expects in RGB color mode a channel sequence BGR *If your provided image buffer contains a channel sequence VUY

Definition at line 2448 of file PGFimage.cpp.