• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

DjVuPalette.h

Go to the documentation of this file.
00001 //C-  -*- C++ -*-
00002 //C- -------------------------------------------------------------------
00003 //C- DjVuLibre-3.5
00004 //C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
00005 //C- Copyright (c) 2001  AT&T
00006 //C-
00007 //C- This software is subject to, and may be distributed under, the
00008 //C- GNU General Public License, Version 2. The license should have
00009 //C- accompanied the software or you may obtain a copy of the license
00010 //C- from the Free Software Foundation at http://www.fsf.org .
00011 //C-
00012 //C- This program is distributed in the hope that it will be useful,
00013 //C- but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //C- GNU General Public License for more details.
00016 //C- 
00017 //C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library
00018 //C- distributed by Lizardtech Software.  On July 19th 2002, Lizardtech 
00019 //C- Software authorized us to replace the original DjVu(r) Reference 
00020 //C- Library notice by the following text (see doc/lizard2002.djvu):
00021 //C-
00022 //C-  ------------------------------------------------------------------
00023 //C- | DjVu (r) Reference Library (v. 3.5)
00024 //C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
00025 //C- | The DjVu Reference Library is protected by U.S. Pat. No.
00026 //C- | 6,058,214 and patents pending.
00027 //C- |
00028 //C- | This software is subject to, and may be distributed under, the
00029 //C- | GNU General Public License, Version 2. The license should have
00030 //C- | accompanied the software or you may obtain a copy of the license
00031 //C- | from the Free Software Foundation at http://www.fsf.org .
00032 //C- |
00033 //C- | The computer code originally released by LizardTech under this
00034 //C- | license and unmodified by other parties is deemed "the LIZARDTECH
00035 //C- | ORIGINAL CODE."  Subject to any third party intellectual property
00036 //C- | claims, LizardTech grants recipient a worldwide, royalty-free, 
00037 //C- | non-exclusive license to make, use, sell, or otherwise dispose of 
00038 //C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 
00039 //C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 
00040 //C- | General Public License.   This grant only confers the right to 
00041 //C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 
00042 //C- | the extent such infringement is reasonably necessary to enable 
00043 //C- | recipient to make, have made, practice, sell, or otherwise dispose 
00044 //C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 
00045 //C- | any greater extent that may be necessary to utilize further 
00046 //C- | modifications or combinations.
00047 //C- |
00048 //C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
00049 //C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
00050 //C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
00051 //C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00052 //C- +------------------------------------------------------------------
00053 // 
00054 // $Id: DjVuPalette.h,v 1.9 2003/11/07 22:08:21 leonb Exp $
00055 // $Name: release_3_5_15 $
00056 
00057 #ifndef _DJVUPALETTE_H_
00058 #define _DJVUPALETTE_H_
00059 #ifdef HAVE_CONFIG_H
00060 #include "config.h"
00061 #endif
00062 #if NEED_GNUG_PRAGMAS
00063 # pragma interface
00064 #endif
00065 
00066 
00067 #include "GContainer.h"
00068 #include "GPixmap.h"
00069 #include <string.h>
00070 
00071 
00072 #ifdef HAVE_NAMESPACES
00073 namespace DJVU {
00074 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00075 }
00076 #endif
00077 #endif
00078 
00079 
00091 
00092 
00116 #ifdef _WIN32_WCE_EMULATION         // Work around odd behavior under WCE Emulation
00117 #define CALLINGCONVENTION __cdecl
00118 #else
00119 #define CALLINGCONVENTION  /* */
00120 #endif
00121 
00122 class DjVuPalette : public GPEnabled
00123 {
00124 protected:
00125   DjVuPalette(void);
00126 public:
00128   static GP<DjVuPalette> create(void) {return new DjVuPalette();}
00129 
00131   ~DjVuPalette();
00132   // COPY
00133   DjVuPalette(const DjVuPalette &ref);
00134   DjVuPalette& operator=(const DjVuPalette &ref);
00135   // PALETTE COMPUTATION
00137   void histogram_clear();
00140   void histogram_add(const GPixel &p, int weight);
00143   void histogram_add(const unsigned char *bgr, int weight);
00150   void histogram_norm_and_add(const int *bgr, int weight);
00156   int compute_palette(int maxcolors, int minboxsize=0);
00160   int compute_pixmap_palette(const GPixmap &pm, int ncolors, int minboxsize=0);
00161   // CONVERSION
00163   int size() const;
00165   int color_to_index(const GPixel &p);
00167   int color_to_index(const unsigned char *bgr);
00169   void index_to_color(int index, GPixel &p) const;
00172   void index_to_color(int index, unsigned char *bgr) const;
00175   void quantize(GPixmap &pm);
00177   int compute_palette_and_quantize(GPixmap &pm, int maxcolors, int minboxsize=0);
00178   // COLOR CORRECTION
00183   void color_correct(double corr);
00184   // COLOR INDEX DATA
00188   GTArray<short> colordata;
00192   void get_color(int nth, GPixel &out) const;
00193   // CODING
00196   void encode_rgb_entries(ByteStream &bs) const;
00199   void decode_rgb_entries(ByteStream &bs, const int palettesize);
00204   void encode(GP<ByteStream> bs) const;
00209   void decode(GP<ByteStream> bs);
00210 
00211 private:
00212   // Histogram
00213   int mask;
00214   GMap<int,int> *hist;
00215   // Quantization data
00216   struct PColor { unsigned char p[4]; };
00217   GTArray<PColor> palette;
00218   GMap<int,int> *pmap;
00219   // Helpers
00220   void allocate_hist();
00221   void allocate_pmap();
00222   static int CALLINGCONVENTION bcomp (const void*, const void*);
00223   static int CALLINGCONVENTION gcomp (const void*, const void*);
00224   static int CALLINGCONVENTION rcomp (const void*, const void*);
00225   static int CALLINGCONVENTION lcomp (const void*, const void*);
00226   int color_to_index_slow(const unsigned char *bgr);
00227 private: // dummy functions
00228   static void encode(ByteStream *);
00229   static void decode(ByteStream *);
00230 };
00231 
00232 
00234 
00235 // ------------ INLINES
00236 
00237 
00238 inline void 
00239 DjVuPalette::histogram_clear()
00240 {
00241   delete hist;
00242   hist = 0;
00243   mask = 0;
00244 }
00245 
00246 inline void 
00247 DjVuPalette::histogram_add(const unsigned char *bgr, int weight)
00248 {
00249   if (weight > 0)
00250     {
00251       if (!hist || hist->size()>=0x4000) 
00252         allocate_hist();
00253       int key = (bgr[0]<<16)|(bgr[1]<<8)|(bgr[2])|(mask);
00254       (*hist)[key] += weight;
00255     }
00256 }  
00257 
00258 inline void 
00259 DjVuPalette::histogram_add(const GPixel &p, int weight)
00260 {
00261   histogram_add(&p.b, weight);
00262 }
00263 
00264 inline void 
00265 DjVuPalette::histogram_norm_and_add(const int *bgr, int weight)
00266 {
00267   if (weight > 0)
00268     {
00269       int p0 = bgr[0]/weight; if (p0>255) p0=255;
00270       int p1 = bgr[1]/weight; if (p1>255) p1=255;
00271       int p2 = bgr[2]/weight; if (p2>255) p2=255;
00272       if (!hist || hist->size()>=0x4000) 
00273         allocate_hist();
00274       int key = (p0<<16)|(p1<<8)|(p2)|(mask);
00275       (*hist)[key] += weight;
00276     }
00277 }
00278 
00279 inline int
00280 DjVuPalette::size() const
00281 {
00282   return palette.size();
00283 }
00284 
00285 inline int 
00286 DjVuPalette::color_to_index(const unsigned char *bgr)
00287 {
00288   if (! pmap)
00289     allocate_pmap();
00290   int key = (bgr[0]<<16)|(bgr[1]<<8)|(bgr[2]);
00291   GPosition p = pmap->contains(key);
00292   if ( p)
00293     return (*pmap)[p];
00294   return color_to_index_slow(bgr);
00295 }
00296 
00297 inline int 
00298 DjVuPalette::color_to_index(const GPixel &p)
00299 {
00300   return color_to_index(&p.b);
00301 }
00302 
00303 inline void 
00304 DjVuPalette::index_to_color(int index, unsigned char *bgr) const
00305 {
00306   const PColor &color = palette[index];
00307   bgr[0] = color.p[0];
00308   bgr[1] = color.p[1];
00309   bgr[2] = color.p[2];
00310 }
00311 
00312 inline void 
00313 DjVuPalette::index_to_color(int index, GPixel &p) const
00314 {
00315   index_to_color(index, &p.b);
00316 }
00317 
00318 inline void
00319 DjVuPalette::get_color(int nth, GPixel &p) const
00320 {
00321   index_to_color(colordata[nth], p);
00322 }
00323 
00324 
00325 
00326 // ------------ THE END
00327 
00328 #ifdef HAVE_NAMESPACES
00329 }
00330 # ifndef NOT_USING_DJVU_NAMESPACE
00331 using namespace DJVU;
00332 # endif
00333 #endif
00334 #endif
00335       
00336       
00337              
00338 
00339     

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal