Blame libdjvu/GPixmap.h

Packit df99a1
//C-  -*- C++ -*-
Packit df99a1
//C- -------------------------------------------------------------------
Packit df99a1
//C- DjVuLibre-3.5
Packit df99a1
//C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
Packit df99a1
//C- Copyright (c) 2001  AT&T
Packit df99a1
//C-
Packit df99a1
//C- This software is subject to, and may be distributed under, the
Packit df99a1
//C- GNU General Public License, either Version 2 of the license,
Packit df99a1
//C- or (at your option) any later version. The license should have
Packit df99a1
//C- accompanied the software or you may obtain a copy of the license
Packit df99a1
//C- from the Free Software Foundation at http://www.fsf.org .
Packit df99a1
//C-
Packit df99a1
//C- This program is distributed in the hope that it will be useful,
Packit df99a1
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit df99a1
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit df99a1
//C- GNU General Public License for more details.
Packit df99a1
//C- 
Packit df99a1
//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
Packit df99a1
//C- Lizardtech Software.  Lizardtech Software has authorized us to
Packit df99a1
//C- replace the original DjVu(r) Reference Library notice by the following
Packit df99a1
//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
Packit df99a1
//C-
Packit df99a1
//C-  ------------------------------------------------------------------
Packit df99a1
//C- | DjVu (r) Reference Library (v. 3.5)
Packit df99a1
//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
Packit df99a1
//C- | The DjVu Reference Library is protected by U.S. Pat. No.
Packit df99a1
//C- | 6,058,214 and patents pending.
Packit df99a1
//C- |
Packit df99a1
//C- | This software is subject to, and may be distributed under, the
Packit df99a1
//C- | GNU General Public License, either Version 2 of the license,
Packit df99a1
//C- | or (at your option) any later version. The license should have
Packit df99a1
//C- | accompanied the software or you may obtain a copy of the license
Packit df99a1
//C- | from the Free Software Foundation at http://www.fsf.org .
Packit df99a1
//C- |
Packit df99a1
//C- | The computer code originally released by LizardTech under this
Packit df99a1
//C- | license and unmodified by other parties is deemed "the LIZARDTECH
Packit df99a1
//C- | ORIGINAL CODE."  Subject to any third party intellectual property
Packit df99a1
//C- | claims, LizardTech grants recipient a worldwide, royalty-free, 
Packit df99a1
//C- | non-exclusive license to make, use, sell, or otherwise dispose of 
Packit df99a1
//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 
Packit df99a1
//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 
Packit df99a1
//C- | General Public License.   This grant only confers the right to 
Packit df99a1
//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 
Packit df99a1
//C- | the extent such infringement is reasonably necessary to enable 
Packit df99a1
//C- | recipient to make, have made, practice, sell, or otherwise dispose 
Packit df99a1
//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 
Packit df99a1
//C- | any greater extent that may be necessary to utilize further 
Packit df99a1
//C- | modifications or combinations.
Packit df99a1
//C- |
Packit df99a1
//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
Packit df99a1
//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
Packit df99a1
//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
Packit df99a1
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
Packit df99a1
//C- +------------------------------------------------------------------
Packit df99a1
Packit df99a1
#ifndef _GPIXMAP_H_
Packit df99a1
#define _GPIXMAP_H_
Packit df99a1
#ifdef HAVE_CONFIG_H
Packit df99a1
#include "config.h"
Packit df99a1
#endif
Packit df99a1
#if NEED_GNUG_PRAGMAS
Packit df99a1
# pragma interface
Packit df99a1
#endif
Packit df99a1
Packit df99a1
/** @name GPixmap.h
Packit df99a1
Packit df99a1
    Files #"GPixmap.h"# and #"GPixmap.cpp"# implement class \Ref{GPixmap}.
Packit df99a1
    Instances of this class represent color images.  Each RGB pixel is
Packit df99a1
    represented by structure \Ref{GPixel}. The ``bottom left'' coordinate system
Packit df99a1
    is used consistently in the DjVu library.  Line zero of a GPixmap is the
Packit df99a1
    bottom line in the color image.  Pixels are organized from left to right
Packit df99a1
    within each line.
Packit df99a1
    
Packit df99a1
    {\bf ToDo} --- More sophisticated color correction schemes. 
Packit df99a1
    
Packit df99a1
    @memo
Packit df99a1
    Generic support for color images.
Packit df99a1
    @author
Packit df99a1
    L\'eon Bottou <leonb@research.att.com>
Packit df99a1
*/
Packit df99a1
//@{
Packit df99a1
Packit df99a1
Packit df99a1
#include "GSmartPointer.h"
Packit df99a1
Packit df99a1
#ifdef HAVE_NAMESPACES
Packit df99a1
namespace DJVU {
Packit df99a1
# ifdef NOT_DEFINED // Just to fool emacs c++ mode
Packit df99a1
}
Packit df99a1
#endif
Packit df99a1
#endif
Packit df99a1
Packit df99a1
Packit df99a1
class GBitmap;
Packit df99a1
class GRect;
Packit df99a1
class ByteStream;
Packit df99a1
Packit df99a1
Packit df99a1
/** Color pixel as a RGB triple.  
Packit df99a1
    The colors are represented using three bytes named #r#, #g# and #b#.  The
Packit df99a1
    value of these bytes represent additive amounts of light.  Color white is
Packit df99a1
    represented by setting all three bytes to #255#.  Color black is
Packit df99a1
    represented by setting all three bytes to #0#.  This convention should not
Packit df99a1
    be confused with the convention adopted for class \Ref{GBitmap} where the
Packit df99a1
    pixel values represent an ink level.  */
Packit df99a1
Packit df99a1
struct DJVUAPI GPixel
Packit df99a1
{
Packit df99a1
  /** Blue component. */
Packit df99a1
  unsigned char b;
Packit df99a1
  /** Green component. */
Packit df99a1
  unsigned char g;
Packit df99a1
  /** Red component. */
Packit df99a1
  unsigned char r;
Packit df99a1
  /** Returns true iff colors are identical. */
Packit df99a1
  friend int operator==(const GPixel & p1, const GPixel & p2);
Packit df99a1
  /** Returns true iff colors are different. */
Packit df99a1
  friend int operator!=(const GPixel & p1, const GPixel & p2);
Packit df99a1
  /** Returns a hash code for the color. */
Packit df99a1
  friend unsigned int hash(const GPixel &p);
Packit df99a1
  /** @name Predefined colors. */
Packit df99a1
  //@{ 
Packit df99a1
  /// GPixel::WHITE is initialized to #rgb:255/255/255#.
Packit df99a1
  static const GPixel WHITE; 
Packit df99a1
  /// GPixel::BLACK is initialized to #rgb:0/0/0#.
Packit df99a1
  static const GPixel BLACK; 
Packit df99a1
  /// GPixel::BLUE is initialized to #rgb:0/0/255#.
Packit df99a1
  static const GPixel BLUE;  
Packit df99a1
  /// GPixel::GREEN is initialized to #rgb:0/255/0#.
Packit df99a1
  static const GPixel GREEN; 
Packit df99a1
  /// GPixel::RED is initialized to #rgb:255/0/0#.
Packit df99a1
  static const GPixel RED;
Packit df99a1
  //@}
Packit df99a1
};
Packit df99a1
Packit df99a1
Packit df99a1
/** RGB Color images.  
Packit df99a1
    Instances of class #GPixmap# represent color images as a two dimensional
Packit df99a1
    array of pixels \Ref{GPixel}.  The bracket operator returns a pointer to
Packit df99a1
    the pixels composing one line of the image.  This pointer can be used as
Packit df99a1
    an array to read or write the pixels of this particular line.  Following
Packit df99a1
    the general convention of the DjVu Reference Library, line zero is always
Packit df99a1
    the bottom line of the image.
Packit df99a1
 */
Packit df99a1
Packit df99a1
class DJVUAPI GPixmap : public GPEnabled
Packit df99a1
{
Packit df99a1
protected:
Packit df99a1
  GPixmap(void);
Packit df99a1
  GPixmap(int nrows, int ncolumns, const GPixel *filler=0);
Packit df99a1
  GPixmap(const GBitmap &ref;;
Packit df99a1
  GPixmap(const GBitmap &ref, const GRect &rect);
Packit df99a1
  GPixmap(const GPixmap &ref;;
Packit df99a1
  GPixmap(const GPixmap &ref, const GRect &rect);
Packit df99a1
  GPixmap(ByteStream &ref;;
Packit df99a1
Packit df99a1
public:
Packit df99a1
  /// Virtual destructor.
Packit df99a1
  virtual ~GPixmap();
Packit df99a1
Packit df99a1
  void destroy(void);
Packit df99a1
  /** @name Construction. */
Packit df99a1
  //@{
Packit df99a1
  /** Creates an empty GBitmap object.  The returned GPixmap has zero rows
Packit df99a1
      and zero columns.  Use function \Ref{init} to change the size of the
Packit df99a1
      image. */
Packit df99a1
  static GP<GPixmap> create(void) {return new GPixmap();}
Packit df99a1
Packit df99a1
  /** Creates a GPixmap with #nrows# rows and #ncolumns# columns.  When the
Packit df99a1
      optional argument #filler# is specified, all pixels are initialized 
Packit df99a1
      with the corresponding color. */
Packit df99a1
  static GP<GPixmap> create(
Packit df99a1
    const int nrows, const int ncolumns, const GPixel *filler=0)
Packit df99a1
  { return new GPixmap(nrows,ncolumns,filler); }
Packit df99a1
Packit df99a1
  /** Creates a GPixmap by copying the gray level image #ref#.
Packit df99a1
      The constructed GPixmap has the same size as #ref#.  The pixels
Packit df99a1
      are initialized with shades of grays copied from #ref#. */
Packit df99a1
  static GP<GPixmap> create(const GBitmap &ref)
Packit df99a1
  { return new GPixmap(ref); }
Packit df99a1
Packit df99a1
  /** Creates a GPixmap by copying the rectangle #rect# of the gray level
Packit df99a1
      image #ref#.  The constructed GPixmap has the same size as rectangle
Packit df99a1
      #rect#.  The pixels are initialized with shades of grays converted from
Packit df99a1
      the ink levels represented in #ref#.  This conversion depends on the
Packit df99a1
      number of gray levels in #ref#. */
Packit df99a1
  static GP<GPixmap> create(const GBitmap &ref, const GRect &rect)
Packit df99a1
  { return new GPixmap(ref,rect); }
Packit df99a1
Packit df99a1
  /** Copy constructors. Creates a GPixmap by replicating the size and the
Packit df99a1
      contents of GPixmap #ref#. */
Packit df99a1
  static GP<GPixmap> create(const GPixmap &ref)
Packit df99a1
  { return new GPixmap(ref); }
Packit df99a1
Packit df99a1
  /** Creates a GPixmap by copying the rectangle #rect# of the color image #ref#.
Packit df99a1
      The constructed GPixmap has the same size as rectangle #rect#.
Packit df99a1
      The pixels are initialized with colors copied from #ref#. */
Packit df99a1
  static GP<GPixmap> create(const GPixmap &ref, const GRect &rect)
Packit df99a1
  { return new GPixmap(ref,rect); }
Packit df99a1
Packit df99a1
  /** Creates a GPixmap by reading PPM data from ByteStream #ref#.
Packit df99a1
      See \Ref{PNM and RLE file formats} for more information. */
Packit df99a1
  static GP<GPixmap> create(ByteStream &ref)
Packit df99a1
  { return new GPixmap(ref); }
Packit df99a1
Packit df99a1
  //@}
Packit df99a1
Packit df99a1
  /** @name Initialization. */
Packit df99a1
  //@{
Packit df99a1
  /** Resets the GPixmap to #nrows# rows and #ncolumns# columns.  When the
Packit df99a1
      optional argument #filler# is specified, all pixels are initialized with
Packit df99a1
      the corresponding color.  The previous content of the GPixmap is discarded. */
Packit df99a1
  void init(int nrows, int ncolumns,  const GPixel *filler=0);
Packit df99a1
  /** Resets the GPixmap by copying the size and the contents of the color
Packit df99a1
      image #ref#.  The previous content of the GPixmap is discarded. */
Packit df99a1
  void init(const GPixmap &ref;;
Packit df99a1
  /** Resets the GPixmap by copying the rectangle #rect# of the color image #ref#.
Packit df99a1
      The previous content of the GPixmap is discarded. */
Packit df99a1
  void init(const GPixmap &ref, const GRect &rect);
Packit df99a1
  /** Resets the GPixmap by copying the size and the contents of the gray 
Packit df99a1
      level image #ref#.  The optional argument #ramp# is an array of 256 
Packit df99a1
      pixel values used for mapping the gray levels to color values. 
Packit df99a1
      Setting #ramp# to zero selects a linear ramp of shades of gray. */
Packit df99a1
  void init(const GBitmap &ref, const GPixel *ramp=0);
Packit df99a1
  /** Resets the GPixmap by copying the rectangle #rect# of the gray level
Packit df99a1
      image #ref#.  The optional argument #ramp# is an array of 256 pixel
Packit df99a1
      values used for mapping the gray levels to color values.  Setting #ramp#
Packit df99a1
      to zero selects a linear ramp computed according to the maximal number
Packit df99a1
      of gray levels in #ref#. */
Packit df99a1
  void init(const GBitmap &ref, const GRect &rect, const GPixel *ramp=0);
Packit df99a1
  /** Resets the GPixmap by reading PPM data from ByteStream #ref#.  See
Packit df99a1
      \Ref{PNM and RLE file formats} for more information. */
Packit df99a1
  void init(ByteStream &ref;;
Packit df99a1
  /** Resets the GPixmap by copying the gray level image #ref#.  The pixels
Packit df99a1
      are initialized with shades of grays copied from #ref#. */
Packit df99a1
  GPixmap& operator=(const GBitmap &ref;;
Packit df99a1
  /** Copy operator. Resets the GPixmap by copying the size and the contents
Packit df99a1
      of the color image #ref#.  The previous content of the GPixmap is
Packit df99a1
      discarded. */
Packit df99a1
  GPixmap& operator=(const GPixmap &ref;;
Packit df99a1
  //@}
Packit df99a1
Packit df99a1
  /** @name Accessing pixels. */
Packit df99a1
  //@{
Packit df99a1
  /** Returns the number of rows (the image height). */
Packit df99a1
  unsigned int rows() const;
Packit df99a1
  /** Returns the number of columns (the image width). */
Packit df99a1
  unsigned int columns() const;
Packit df99a1
  /** Returns a constant pointer to the first GPixel in row #row#.  This
Packit df99a1
      pointer can be used as an array to read the row elements. */
Packit df99a1
  const GPixel * operator[] (int row) const;
Packit df99a1
  /** Returns a pointer to the first GPixel in row #row#.  This pointer can be
Packit df99a1
      used as an array to read or write the row elements. */
Packit df99a1
  GPixel * operator[] (int row);
Packit df99a1
  /** Returns the length (in pixels) of a row in memory.  This number is equal
Packit df99a1
      to the difference between pointers to pixels located in the same column
Packit df99a1
      in consecutive rows.  This difference may be larger than the number of
Packit df99a1
      columns in the image. */
Packit df99a1
  unsigned int rowsize() const;
Packit df99a1
  //@}
Packit df99a1
Packit df99a1
  /** @name Resampling images. */
Packit df99a1
  //@{
Packit df99a1
  /** Resets this GPixmap with a subsampled segment of color image #src#.
Packit df99a1
      This function conceptually rescales image #src# by a factor #1:factor#,
Packit df99a1
      and copies rectangle #rect# of the subsampled image into the current GPixmap.
Packit df99a1
      The full subsampled image is copied if #rect# is a null pointer.
Packit df99a1
      Both operations are however performed together for efficiency reasons.
Packit df99a1
      Subsampling works by averaging the colors of the source pixels located
Packit df99a1
      in small squares of size #factor# times #factor#. */
Packit df99a1
  void downsample(const GPixmap *src, int factor, const GRect *rect=0);
Packit df99a1
  /** Resets this GPixmap with a oversampled segment of color image #src#.
Packit df99a1
      This function conceptually rescales image #src# by a factor #factor:1#,
Packit df99a1
      and copies rectangle #rect# of the oversampled image into the current
Packit df99a1
      GPixmap.  The full oversampled image is copied if #rect# is a null
Packit df99a1
      pointer.  Both operations are however performed together for efficiency
Packit df99a1
      reasons.  Oversampling works by replicating the color of the source
Packit df99a1
      pixels into squares of size #factor# times #factor#. */
Packit df99a1
  void upsample(const GPixmap *src, int factor, const GRect *rect=0);
Packit df99a1
  /** Resets this GPixmap with a rescaled segment of #src# (zoom 75%).  This
Packit df99a1
      function conceptually rescales image #src# by a factor #3:4#, and copies
Packit df99a1
      rectangle #rect# of the rescaled image into the current GPixmap.  The
Packit df99a1
      full rescaled image is copied if #rect# is a null pointer.  Both
Packit df99a1
      operations are however performed together for efficiency reasons.  This
Packit df99a1
      function has been superseded by class \Ref{GPixmapScaler}. */
Packit df99a1
  void downsample43(const GPixmap *src, const GRect *rect=0); 
Packit df99a1
  /** Resets this GPixmap with a rescaled segment of #src# (zoom 150%).  This
Packit df99a1
      function conceptually rescales image #src# by a factor #3:2# and copies
Packit df99a1
      rectangle #rect# of the rescaled image into the current GPixmap.  The
Packit df99a1
      full rescaled image is copied if #rect# is a null pointer.  Both
Packit df99a1
      operations are however performed together for efficiency reasons.  This
Packit df99a1
      function has been superseded by class \Ref{GPixmapScaler}. */
Packit df99a1
  void upsample23(const GPixmap *src, const GRect *rect=0);
Packit df99a1
  //@}
Packit df99a1
Packit df99a1
  /** @name Blitting and applying stencils.  
Packit df99a1
      These function is essential for rendering DjVu images.  The elementary
Packit df99a1
      functions are \Ref{attenuate} and \Ref{blit}.  The combined functions
Packit df99a1
      \Ref{blend} and \Ref{stencil} should be viewed as optimizations.  */
Packit df99a1
  //@{
Packit df99a1
  /** Attenuates the color image in preparation for a blit.  
Packit df99a1
      Bitmap #bm# is positionned at location #x#,#y# over this color image.
Packit df99a1
      The matching color image pixels are then multiplied by #1.0-Alpha# where
Packit df99a1
      #Alpha# denotes the gray value, in range #[0,1]#, represented by the
Packit df99a1
      corresponding pixel of bitmap #bm#. */
Packit df99a1
  void attenuate(const GBitmap *bm, int x, int y);
Packit df99a1
  /** Blits solid color #color# through transparency mask #bm#.  
Packit df99a1
      Bitmap #bm# is positionned at location #x#,#y# over this color image.
Packit df99a1
      The matching color image pixels are then modified by adding color
Packit df99a1
      #color# multiplied by #Alpha#, where #Alpha# denotes the gray value, in
Packit df99a1
      range #[0,1]#, represented by the corresponding pixel of bitmap #bm#. */
Packit df99a1
  void blit(const GBitmap *bm, int x, int y, const GPixel *color);
Packit df99a1
  /** Blits pixmap #color# through transparency mask #bm#.
Packit df99a1
      Bitmap #bm# is positionned at location #x#,#y# over this color image.
Packit df99a1
      The matching color image pixels are then modified by adding the
Packit df99a1
      corresponding pixel color in pixmap #color#, multiplied by #Alpha#,
Packit df99a1
      where #Alpha# denotes the gray value, in range #[0,1]#, represented by
Packit df99a1
      the corresponding pixel of bitmap #bm#. */
Packit df99a1
  void blit(const GBitmap *bm, int x, int y, const GPixmap *color);
Packit df99a1
  /** Performs alpha blending. This function is similar to first calling
Packit df99a1
      \Ref{attenuate} with alpha map #bm# and then calling \Ref{blit} with
Packit df99a1
      alpha map #bm# and color map #color#. Both operations are performed
Packit df99a1
      together for efficiency reasons. */
Packit df99a1
  void blend(const GBitmap *bm, int x, int y, const GPixmap *color);
Packit df99a1
  /** Resample color pixmap and performs color corrected alpha blending.  This
Packit df99a1
      function conceptually computes an intermediate color image by first
Packit df99a1
      upsampling the GPixmap #pm# by a factor #pms:1# (see \Ref{upsample}),
Packit df99a1
      extracting the sub-image designated by rectangle #pmr# and applying
Packit df99a1
      color correction #corr# (see \Ref{color_correct}).  This intermediate
Packit df99a1
      color image is then blended into this pixel map according to the alpha
Packit df99a1
      map #bm# (see \Ref{blend}). */
Packit df99a1
  void stencil(const GBitmap *bm, 
Packit df99a1
               const GPixmap *pm, int pms, 
Packit df99a1
               const GRect *pmr, double corr, GPixel white);
Packit df99a1
  void stencil(const GBitmap *bm, 
Packit df99a1
               const GPixmap *pm, int pms, 
Packit df99a1
               const GRect *pmr, double corr=1.0);
Packit df99a1
  //@}
Packit df99a1
  
Packit df99a1
  /** @name Manipulating colors. */
Packit df99a1
  //@{
Packit df99a1
  /** Dithers the image to 216 colors.  This function applies an ordered
Packit df99a1
      dithering algorithm to reduce the image to 216 predefined colors.  These
Packit df99a1
      predefined colors are located on a color cube of 6x6x6 colors: the color
Packit df99a1
      RGB coordinates can only take the following values: #0#, #51#, #102#,
Packit df99a1
      #163#, #214# or #255#.  This is useful for displaying images on a device
Packit df99a1
      supporting a maximum of 256 colors. Arguments #xmin# and #ymin# control
Packit df99a1
      the position of the dithering grids.  This is useful for dithering tiled
Packit df99a1
      images. Arguments #xmin# and #ymin# must be the position of the bottom
Packit df99a1
      left corner of the tile contained in this GPixmap. Properly setting
Packit df99a1
      these arguments eliminates dithering artifacts on the tile
Packit df99a1
      boundaries. */
Packit df99a1
  void ordered_666_dither(int xmin=0, int ymin=0);
Packit df99a1
  /** Dithers the image to 32768 colors.  This function applies an ordered
Packit df99a1
      dithering algorithm to reduce the image to 32768 predefined colors.
Packit df99a1
      These predefined colors are located on a color cube of 32x32x32 colors:
Packit df99a1
      the color RGB coordinates can only take values in which the three least
Packit df99a1
      significant bits are set to #1#.  This is useful for displaying images
Packit df99a1
      with less than 24 bits per pixel.  Arguments #xmin# and #ymin# control
Packit df99a1
      the position of the dithering grids.  This is useful for dithering tiled
Packit df99a1
      images. Arguments #xmin# and #ymin# must be the position of the bottom
Packit df99a1
      left corner of the tile contained in this GPixmap. Properly setting
Packit df99a1
      these arguments eliminates dithering artifacts on the tile
Packit df99a1
      boundaries. */
Packit df99a1
  void ordered_32k_dither(int xmin=0, int ymin=0);
Packit df99a1
  /** Applies a luminance gamma correction factor of #corr#.  
Packit df99a1
      Values greater than #1.0# make the image brighter.  
Packit df99a1
      Values smaller than #1.0# make the image darker.  
Packit df99a1
      The documentation of program \Ref{ppmcoco} explains how to
Packit df99a1
      properly use this function. */
Packit df99a1
  void color_correct(double corr);
Packit df99a1
  void color_correct(double corr, GPixel white);
Packit df99a1
  /** Applies a luminance gamma correction to an array of pixels. 
Packit df99a1
      This function is {\em static} and does not modify this pixmap. */
Packit df99a1
  static void color_correct(double corr, GPixel *pix, int npix);
Packit df99a1
  static void color_correct(double corr, GPixel white, GPixel *pix, int npix);
Packit df99a1
Packit df99a1
  //@}
Packit df99a1
  
Packit df99a1
  /** @name Miscellaneous. */
Packit df99a1
  //@{
Packit df99a1
  /** Returns the number of bytes allocated for this image. */
Packit df99a1
  inline unsigned int get_memory_usage() const;
Packit df99a1
  /** Saves the image into ByteStream #bs# using the PPM format.
Packit df99a1
      Argument #raw# selects the ``Raw PPM'' (1) or the ``Ascii PPM'' (0) format.
Packit df99a1
      See \Ref{PNM and RLE file formats} for more information. */
Packit df99a1
  void save_ppm(ByteStream &bs, int raw=1) const;
Packit df99a1
  //@}
Packit df99a1
Packit df99a1
  /** @name Stealing or borrowing the memory buffer (advanced). */
Packit df99a1
  //@{
Packit df99a1
  /** Steals the memory buffer of a GPixmap.  This function returns the
Packit df99a1
      address of the memory buffer allocated by this GPixmap object.  The
Packit df99a1
      offset of the first pixel in the bottom line is written into variable
Packit df99a1
      #offset#.  Other lines can be accessed using pointer arithmetic (see
Packit df99a1
      \Ref{rowsize}).  The GPixmap object no longer ``owns'' the buffer: you
Packit df99a1
      must explicitly de-allocate the buffer using #operator delete []#.  This
Packit df99a1
      de-allocation should take place after the destruction or the
Packit df99a1
      re-initialization of the GPixmap object.  This function will return a
Packit df99a1
      null pointer if the GPixmap object does not ``own'' the buffer in the
Packit df99a1
      first place.  */
Packit df99a1
  GPixel *take_data(size_t &offset);
Packit df99a1
  /** Initializes this GPixmap by borrowing a memory segment.  The GPixmap
Packit df99a1
      then directly addresses the memory buffer #data# provided by the user.
Packit df99a1
      This buffer must be large enough to hold #w*h# GPixels.  The GPixmap
Packit df99a1
      object does not ``own'' the buffer: you must explicitly de-allocate the
Packit df99a1
      buffer using #operator delete []#.  This de-allocation should take place
Packit df99a1
      after the destruction or the re-initialization of the GPixmap object.  */
Packit df99a1
  inline void borrow_data(GPixel &data, int w, int h); 
Packit df99a1
  /// Identical to the above, but GPixmap will do the delete []. 
Packit df99a1
  void donate_data(GPixel *data, int w, int h); 
Packit df99a1
  
Packit df99a1
  /** Rotates pixmap by 90, 180 or 270 degrees anticlockwise
Packit df99a1
      and returns a new pixmap, input pixmap is not changed. 
Packit df99a1
      count can be 1, 2, or 3 for 90, 180, 270 degree rotation.
Packit df99a1
      It returns the same pixmap if not rotated. */
Packit df99a1
  GP<GPixmap> rotate(int count=0);
Packit df99a1
Packit df99a1
  //@}
Packit df99a1
  
Packit df99a1
  // Please ignore these two functions. Their only purpose is to allow
Packit df99a1
  // DjVu viewer compile w/o errors. eaf. 
Packit df99a1
  // Is this still useful ?. lyb.
Packit df99a1
  int get_grays(void) const { return 256; };
Packit df99a1
  void set_grays(int) {};\
Packit df99a1
  
Packit df99a1
protected:
Packit df99a1
  // data
Packit df99a1
  unsigned short nrows;
Packit df99a1
  unsigned short ncolumns;
Packit df99a1
  unsigned short nrowsize;
Packit df99a1
  GPixel *pixels;
Packit df99a1
  GPixel *pixels_data;
Packit df99a1
  friend class DjVu_PixImage;
Packit df99a1
};
Packit df99a1
Packit df99a1
//@}
Packit df99a1
Packit df99a1
// INLINE --------------------------
Packit df99a1
Packit df99a1
Packit df99a1
inline int 
Packit df99a1
operator==(const GPixel & p1, const GPixel & p2)
Packit df99a1
{
Packit df99a1
  return p1.r==p2.r && p1.g==p2.g && p1.b==p2.b;
Packit df99a1
}
Packit df99a1
Packit df99a1
inline int 
Packit df99a1
operator!=(const GPixel & p1, const GPixel & p2)
Packit df99a1
{
Packit df99a1
  return p1.r!=p2.r || p1.g!=p2.g || p1.b!=p2.b;
Packit df99a1
}
Packit df99a1
Packit df99a1
inline unsigned int 
Packit df99a1
hash(const GPixel &p)
Packit df99a1
{
Packit df99a1
  unsigned int x = (p.b<<16)|(p.g<<8)|(p.r);
Packit df99a1
  return x ^ (p.b<<4) ^ (p.r<<12);
Packit df99a1
}
Packit df99a1
Packit df99a1
inline unsigned int
Packit df99a1
GPixmap::rows() const
Packit df99a1
{
Packit df99a1
  return nrows;
Packit df99a1
}
Packit df99a1
Packit df99a1
inline unsigned int
Packit df99a1
GPixmap::columns() const
Packit df99a1
{
Packit df99a1
  return ncolumns;
Packit df99a1
}
Packit df99a1
Packit df99a1
inline unsigned int
Packit df99a1
GPixmap::rowsize() const
Packit df99a1
{
Packit df99a1
  return nrowsize;
Packit df99a1
}
Packit df99a1
Packit df99a1
inline GPixel *
Packit df99a1
GPixmap::operator[](int row)
Packit df99a1
{
Packit df99a1
  if (row<0 || row>=nrows || !pixels) return 0;
Packit df99a1
  return &pixels[row * nrowsize];
Packit df99a1
}
Packit df99a1
Packit df99a1
inline const GPixel *
Packit df99a1
GPixmap::operator[](int row) const
Packit df99a1
{
Packit df99a1
  if (row<0 || row>=nrows) return 0;
Packit df99a1
  return &pixels[row * nrowsize];
Packit df99a1
}
Packit df99a1
Packit df99a1
inline GPixmap & 
Packit df99a1
GPixmap::operator=(const GBitmap &ref)
Packit df99a1
{
Packit df99a1
  init(ref);
Packit df99a1
  return *this;
Packit df99a1
}
Packit df99a1
Packit df99a1
inline GPixmap & 
Packit df99a1
GPixmap::operator=(const GPixmap &ref)
Packit df99a1
{
Packit df99a1
  init(ref);
Packit df99a1
  return *this;
Packit df99a1
}
Packit df99a1
Packit df99a1
inline void
Packit df99a1
GPixmap::borrow_data(GPixel &data, int w, int h)
Packit df99a1
{
Packit df99a1
  donate_data(&data,w,h);
Packit df99a1
  pixels_data=0;
Packit df99a1
}
Packit df99a1
Packit df99a1
//////////////////////////////////////////////////
Packit df99a1
// Memory usage
Packit df99a1
//////////////////////////////////////////////////
Packit df99a1
Packit df99a1
Packit df99a1
inline unsigned int 
Packit df99a1
GPixmap::get_memory_usage() const
Packit df99a1
{
Packit df99a1
  return  sizeof(GPixmap)+(nrows * ncolumns * sizeof(GPixel));
Packit df99a1
}
Packit df99a1
Packit df99a1
// ---------------------------------
Packit df99a1
Packit df99a1
#ifdef HAVE_NAMESPACES
Packit df99a1
}
Packit df99a1
# ifndef NOT_USING_DJVU_NAMESPACE
Packit df99a1
using namespace DJVU;
Packit df99a1
# endif
Packit df99a1
#endif
Packit df99a1
#endif
Packit df99a1
Packit df99a1