Help-Site Computer Manuals
Software
Hardware
Programming
Networking
  Algorithms & Data Structures   Programming Languages   Revision Control
  Protocols
  Cameras   Computers   Displays   Keyboards & Mice   Motherboards   Networking   Printers & Scanners   Storage
  Windows   Linux & Unix   Mac

/var/sites/help-site.com/auto/tmp/CPAN/9677/PDF-API2-0.68/lib/PDF/API2/Resource/XObject/Image/PNG.pm

/var/sites/help-site.com/auto/tmp/CPAN/9677/PDF-API2-0.68/lib/PDF/API2/Resource/XObject/Image/PNG.pm


$res = PDF::API2::Resource::XObject::Image::PNG->new $pdf, $file [, $name]
Returns a png-image object.

$res = PDF::API2::Resource::XObject::Image::PNG->new_api $api, $file [, $name]
Returns a png-image object. This method is different from 'new' that it needs an PDF::API2-object rather than a Text::PDF::File-object.


AUTHOR

alfred reibenschuh


HISTORY


    $Log: PNG.pm,v $

    Revision 2.0  2005/11/16 02:18:23  areibens

    revision workaround for SF cvs import not to screw up CPAN

    Revision 1.2  2005/11/16 01:27:50  areibens

    genesis2

    Revision 1.1  2005/11/16 01:19:27  areibens

    genesis

    Revision 1.10  2005/06/17 19:44:04  fredo

    fixed CPAN modulefile versioning (again)

    Revision 1.9  2005/06/17 18:53:35  fredo

    fixed CPAN modulefile versioning (dislikes cvs)

    Revision 1.8  2005/03/14 22:01:31  fredo

    upd 2005

    Revision 1.7  2004/12/16 00:30:55  fredo

    added no warn for recursion

    Revision 1.6  2004/06/15 09:14:54  fredo

    removed cr+lf

    Revision 1.5  2004/06/07 19:44:44  fredo

    cleaned out cr+lf for lf

    Revision 1.4  2004/02/12 14:48:01  fredo

    removed duplicate definition of $fh

    Revision 1.3  2003/12/08 13:06:11  Administrator

    corrected to proper licencing statement

    Revision 1.2  2003/11/30 17:37:16  Administrator

    merged into default

    Revision 1.1.1.1.2.2  2003/11/30 16:57:10  Administrator

    merged into default

    Revision 1.1.1.1.2.1  2003/11/30 16:00:42  Administrator

    added CVS id/log



=cut

RFC 2083 PNG: Portable Network Graphics January 1997




4.1.3. IDAT Image data

    The IDAT chunk contains the actual image data.  To create this

    data:

     * Begin with image scanlines represented as described in

       Image layout (Section 2.3); the layout and total size of

       this raw data are determined by the fields of IHDR.

     * Filter the image data according to the filtering method

       specified by the IHDR chunk.  (Note that with filter

       method 0, the only one currently defined, this implies

       prepending a filter type byte to each scanline.)

     * Compress the filtered data using the compression method

       specified by the IHDR chunk.

    The IDAT chunk contains the output datastream of the compression

    algorithm.

    To read the image data, reverse this process.

    There can be multiple IDAT chunks; if so, they must appear

    consecutively with no other intervening chunks.  The compressed

    datastream is then the concatenation of the contents of all the

    IDAT chunks.  The encoder can divide the compressed datastream

    into IDAT chunks however it wishes.  (Multiple IDAT chunks are

    allowed so that encoders can work in a fixed amount of memory;

    typically the chunk size will correspond to the encoder's buffer

    size.) It is important to emphasize that IDAT chunk boundaries

    have no semantic significance and can occur at any point in the

    compressed datastream.  A PNG file in which each IDAT chunk

    contains only one data byte is legal, though remarkably wasteful

    of space.  (For that matter, zero-length IDAT chunks are legal,

    though even more wasteful.)



4.2.9. tRNS Transparency

    The tRNS chunk specifies that the image uses simple

    transparency: either alpha values associated with palette

    entries (for indexed-color images) or a single transparent

    color (for grayscale and truecolor images).  Although simple

    transparency is not as elegant as the full alpha channel, it

    requires less storage space and is sufficient for many common

    cases.

    For color type 3 (indexed color), the tRNS chunk contains a

    series of one-byte alpha values, corresponding to entries in

    the PLTE chunk:

        Alpha for palette index 0:  1 byte

        Alpha for palette index 1:  1 byte

        ... etc ...

    Each entry indicates that pixels of the corresponding palette

    index must be treated as having the specified alpha value.

    Alpha values have the same interpretation as in an 8-bit full

    alpha channel: 0 is fully transparent, 255 is fully opaque,

    regardless of image bit depth. The tRNS chunk must not contain

    more alpha values than there are palette entries, but tRNS can

    contain fewer values than there are palette entries.  In this

    case, the alpha value for all remaining palette entries is

    assumed to be 255.  In the common case in which only palette

    index 0 need be made transparent, only a one-byte tRNS chunk is

    needed.

    For color type 0 (grayscale), the tRNS chunk contains a single

    gray level value, stored in the format:

        Gray:  2 bytes, range 0 .. (2^bitdepth)-1

    (For consistency, 2 bytes are used regardless of the image bit

    depth.) Pixels of the specified gray level are to be treated as

    transparent (equivalent to alpha value 0); all other pixels are

    to be treated as fully opaque (alpha value (2^bitdepth)-1).

    For color type 2 (truecolor), the tRNS chunk contains a single

    RGB color value, stored in the format:

        Red:   2 bytes, range 0 .. (2^bitdepth)-1

        Green: 2 bytes, range 0 .. (2^bitdepth)-1

        Blue:  2 bytes, range 0 .. (2^bitdepth)-1

    (For consistency, 2 bytes per sample are used regardless of the

    image bit depth.) Pixels of the specified color value are to be

    treated as transparent (equivalent to alpha value 0); all other

    pixels are to be treated as fully opaque (alpha value

    2^bitdepth)-1).

    tRNS is prohibited for color types 4 and 6, since a full alpha

    channel is already present in those cases.

    Note: when dealing with 16-bit grayscale or truecolor data, it

    is important to compare both bytes of the sample values to

    determine whether a pixel is transparent.  Although decoders

    may drop the low-order byte of the samples for display, this

    must not occur until after the data has been tested for

    transparency.  For example, if the grayscale level 0x0001 is

    specified to be transparent, it would be incorrect to compare

    only the high-order byte and decide that 0x0002 is also

    transparent.

    When present, the tRNS chunk must precede the first IDAT chunk,

    and must follow the PLTE chunk, if any.



6. Filter Algorithms

    This chapter describes the filter algorithms that can be applied

    before compression.  The purpose of these filters is to prepare the

    image data for optimum compression.



6.1. Filter types

    PNG filter method 0 defines five basic filter types:

        Type    Name

        0       None

        1       Sub

        2       Up

        3       Average

        4       Paeth

    (Note that filter method 0 in IHDR specifies exactly this set of

    five filter types.  If the set of filter types is ever extended, a

    different filter method number will be assigned to the extended

    set, so that decoders need not decompress the data to discover

    that it contains unsupported filter types.)

    The encoder can choose which of these filter algorithms to apply

    on a scanline-by-scanline basis.  In the image data sent to the

    compression step, each scanline is preceded by a filter type byte

    that specifies the filter algorithm used for that scanline.

    Filtering algorithms are applied to bytes, not to pixels,

    regardless of the bit depth or color type of the image.  The

    filtering algorithms work on the byte sequence formed by a

    scanline that has been represented as described in Image layout

    (Section 2.3).  If the image includes an alpha channel, the alpha

    data is filtered in the same way as the image data.

    When the image is interlaced, each pass of the interlace pattern

    is treated as an independent image for filtering purposes.  The

    filters work on the byte sequences formed by the pixels actually

    transmitted during a pass, and the "previous scanline" is the one

    previously transmitted in the same pass, not the one adjacent in

    the complete image.  Note that the subimage transmitted in any one

    pass is always rectangular, but is of smaller width and/or height

    than the complete image.  Filtering is not applied when this

    subimage is empty.

    For all filters, the bytes "to the left of" the first pixel in a

    scanline must be treated as being zero.  For filters that refer to

    the prior scanline, the entire prior scanline must be treated as

    being zeroes for the first scanline of an image (or of a pass of

    an interlaced image).

    To reverse the effect of a filter, the decoder must use the

    decoded values of the prior pixel on the same line, the pixel

    immediately above the current pixel on the prior line, and the

    pixel just to the left of the pixel above.  This implies that at

    least one scanline's worth of image data will have to be stored by

    the decoder at all times.  Even though some filter types do not

    refer to the prior scanline, the decoder will always need to store

    each scanline as it is decoded, since the next scanline might use

    a filter that refers to it.

    PNG imposes no restriction on which filter types can be applied to

    an image.  However, the filters are not equally effective on all

    types of data.  See Recommendations for Encoders: Filter selection

    (Section 9.6).

    See also Rationale: Filtering (Section 12.9).

6.2. Filter type 0: None


    With the None filter, the scanline is transmitted unmodified; it

    is only necessary to insert a filter type byte before the data.



6.3. Filter type 1: Sub

    The Sub filter transmits the difference between each byte and the

    value of the corresponding byte of the prior pixel.

    To compute the Sub filter, apply the following formula to each

    byte of the scanline:

        Sub(x) = Raw(x) - Raw(x-bpp)

    where x ranges from zero to the number of bytes representing the

    scanline minus one, Raw(x) refers to the raw data byte at that

    byte position in the scanline, and bpp is defined as the number of

    bytes per complete pixel, rounding up to one. For example, for

    color type 2 with a bit depth of 16, bpp is equal to 6 (three

    samples, two bytes per sample); for color type 0 with a bit depth

    of 2, bpp is equal to 1 (rounding up); for color type 4 with a bit

    depth of 16, bpp is equal to 4 (two-byte grayscale sample, plus

    two-byte alpha sample).

    Note this computation is done for each byte, regardless of bit

    depth.  In a 16-bit image, each MSB is predicted from the

    preceding MSB and each LSB from the preceding LSB, because of the

    way that bpp is defined.

    Unsigned arithmetic modulo 256 is used, so that both the inputs

    and outputs fit into bytes.  The sequence of Sub values is

    transmitted as the filtered scanline.

    For all x < 0, assume Raw(x) = 0.

    To reverse the effect of the Sub filter after decompression,

    output the following value:

        Sub(x) + Raw(x-bpp)

    (computed mod 256), where Raw refers to the bytes already decoded.



6.4. Filter type 2: Up

    The Up filter is just like the Sub filter except that the pixel

    immediately above the current pixel, rather than just to its left,

    is used as the predictor.

    To compute the Up filter, apply the following formula to each byte

    of the scanline:

        Up(x) = Raw(x) - Prior(x)

    where x ranges from zero to the number of bytes representing the

    scanline minus one, Raw(x) refers to the raw data byte at that

    byte position in the scanline, and Prior(x) refers to the

    unfiltered bytes of the prior scanline.

    Note this is done for each byte, regardless of bit depth.

    Unsigned arithmetic modulo 256 is used, so that both the inputs

    and outputs fit into bytes.  The sequence of Up values is

    transmitted as the filtered scanline.

    On the first scanline of an image (or of a pass of an interlaced

    image), assume Prior(x) = 0 for all x.

    To reverse the effect of the Up filter after decompression, output

    the following value:

        Up(x) + Prior(x)

    (computed mod 256), where Prior refers to the decoded bytes of the

    prior scanline.



6.5. Filter type 3: Average

    The Average filter uses the average of the two neighboring pixels

    (left and above) to predict the value of a pixel.

    To compute the Average filter, apply the following formula to each

    byte of the scanline:

        Average(x) = Raw(x) - floor((Raw(x-bpp)+Prior(x))/2)

    where x ranges from zero to the number of bytes representing the

    scanline minus one, Raw(x) refers to the raw data byte at that

    byte position in the scanline, Prior(x) refers to the unfiltered

    bytes of the prior scanline, and bpp is defined as for the Sub

    filter.

    Note this is done for each byte, regardless of bit depth.  The

    sequence of Average values is transmitted as the filtered

    scanline.

    The subtraction of the predicted value from the raw byte must be

    done modulo 256, so that both the inputs and outputs fit into

    bytes.  However, the sum Raw(x-bpp)+Prior(x) must be formed

    without overflow (using at least nine-bit arithmetic).  floor()

    indicates that the result of the division is rounded to the next

    lower integer if fractional; in other words, it is an integer

    division or right shift operation.

    For all x < 0, assume Raw(x) = 0.  On the first scanline of an

    image (or of a pass of an interlaced image), assume Prior(x) = 0

    for all x.

    To reverse the effect of the Average filter after decompression,

    output the following value:

        Average(x) + floor((Raw(x-bpp)+Prior(x))/2)

    where the result is computed mod 256, but the prediction is

    calculated in the same way as for encoding.  Raw refers to the

    bytes already decoded, and Prior refers to the decoded bytes of

    the prior scanline.



6.6. Filter type 4: Paeth

    The Paeth filter computes a simple linear function of the three

    neighboring pixels (left, above, upper left), then chooses as

    predictor the neighboring pixel closest to the computed value.

    This technique is due to Alan W. Paeth [PAETH].

    To compute the Paeth filter, apply the following formula to each

    byte of the scanline:

        Paeth(x) = Raw(x) - PaethPredictor(Raw(x-bpp), Prior(x), Prior(x-bpp))

    where x ranges from zero to the number of bytes representing the

    scanline minus one, Raw(x) refers to the raw data byte at that

    byte position in the scanline, Prior(x) refers to the unfiltered

    bytes of the prior scanline, and bpp is defined as for the Sub

    filter.

    Note this is done for each byte, regardless of bit depth.

    Unsigned arithmetic modulo 256 is used, so that both the inputs

    and outputs fit into bytes.  The sequence of Paeth values is

    transmitted as the filtered scanline.

    The PaethPredictor function is defined by the following

    pseudocode:

        function PaethPredictor (a, b, c)

        begin

            ; a = left, b = above, c = upper left

            p := a + b - c        ; initial estimate

            pa := abs(p - a)      ; distances to a, b, c

            pb := abs(p - b)

            pc := abs(p - c)

            ; return nearest of a,b,c,

            ; breaking ties in order a,b,c.

            if pa <= pb AND pa <= pc then return a

            else if pb <= pc then return b

            else return c

        end

    The calculations within the PaethPredictor function must be

    performed exactly, without overflow.  Arithmetic modulo 256 is to

    be used only for the final step of subtracting the function result

    from the target byte value.

    Note that the order in which ties are broken is critical and must

    not be altered.  The tie break order is: pixel to the left, pixel

    above, pixel to the upper left.  (This order differs from that

    given in Paeth's article.)

    For all x < 0, assume Raw(x) = 0 and Prior(x) = 0.  On the first

    scanline of an image (or of a pass of an interlaced image), assume

    Prior(x) = 0 for all x.

    To reverse the effect of the Paeth filter after decompression,

    output the following value:

        Paeth(x) + PaethPredictor(Raw(x-bpp), Prior(x), Prior(x-bpp))

    (computed mod 256), where Raw and Prior refer to bytes already

    decoded.  Exactly the same PaethPredictor function is used by both

    encoder and decoder.
Programminig
Wy
Wy
yW
Wy
Programming
Wy
Wy
Wy
Wy