00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef _GPIXMAP_H_
00058 #define _GPIXMAP_H_
00059 #ifdef HAVE_CONFIG_H
00060 #include "config.h"
00061 #endif
00062 #if NEED_GNUG_PRAGMAS
00063 # pragma interface
00064 #endif
00065
00084
00085
00086 #include "GSmartPointer.h"
00087
00088 #ifdef HAVE_NAMESPACES
00089 namespace DJVU {
00090 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00091 }
00092 #endif
00093 #endif
00094
00095
00096 class GBitmap;
00097 class GRect;
00098 class ByteStream;
00099
00100
00109 struct GPixel
00110 {
00112 unsigned char b;
00114 unsigned char g;
00116 unsigned char r;
00118 friend int operator==(const GPixel & p1, const GPixel & p2);
00120 friend int operator!=(const GPixel & p1, const GPixel & p2);
00122 friend unsigned int hash(const GPixel &p);
00125
00126 static const GPixel WHITE;
00128 static const GPixel BLACK;
00130 static const GPixel BLUE;
00132 static const GPixel GREEN;
00134 static const GPixel RED;
00136 };
00137
00138
00148 class GPixmap : public GPEnabled
00149 {
00150 protected:
00151 GPixmap(void);
00152 GPixmap(int nrows, int ncolumns, const GPixel *filler=0);
00153 GPixmap(const GBitmap &ref);
00154 GPixmap(const GBitmap &ref, const GRect &rect);
00155 GPixmap(const GPixmap &ref);
00156 GPixmap(const GPixmap &ref, const GRect &rect);
00157 GPixmap(ByteStream &ref);
00158
00159 public:
00161 virtual ~GPixmap();
00162
00163 void destroy(void);
00169 static GP<GPixmap> create(void) {return new GPixmap();}
00170
00174 static GP<GPixmap> create(
00175 const int nrows, const int ncolumns, const GPixel *filler=0)
00176 { return new GPixmap(nrows,ncolumns,filler); }
00177
00181 static GP<GPixmap> create(const GBitmap &ref)
00182 { return new GPixmap(ref); }
00183
00189 static GP<GPixmap> create(const GBitmap &ref, const GRect &rect)
00190 { return new GPixmap(ref,rect); }
00191
00194 static GP<GPixmap> create(const GPixmap &ref)
00195 { return new GPixmap(ref); }
00196
00200 static GP<GPixmap> create(const GPixmap &ref, const GRect &rect)
00201 { return new GPixmap(ref,rect); }
00202
00205 static GP<GPixmap> create(ByteStream &ref)
00206 { return new GPixmap(ref); }
00207
00209
00215 void init(int nrows, int ncolumns, const GPixel *filler=0);
00218 void init(const GPixmap &ref);
00221 void init(const GPixmap &ref, const GRect &rect);
00226 void init(const GBitmap &ref, const GPixel *ramp=0);
00232 void init(const GBitmap &ref, const GRect &rect, const GPixel *ramp=0);
00235 void init(ByteStream &ref);
00238 GPixmap& operator=(const GBitmap &ref);
00242 GPixmap& operator=(const GPixmap &ref);
00244
00248 unsigned int rows() const;
00250 unsigned int columns() const;
00253 const GPixel * operator[] (int row) const;
00256 GPixel * operator[] (int row);
00261 unsigned int rowsize() const;
00263
00273 void downsample(const GPixmap *src, int factor, const GRect *rect=0);
00281 void upsample(const GPixmap *src, int factor, const GRect *rect=0);
00288 void downsample43(const GPixmap *src, const GRect *rect=0);
00295 void upsample23(const GPixmap *src, const GRect *rect=0);
00297
00308 void attenuate(const GBitmap *bm, int x, int y);
00314 void blit(const GBitmap *bm, int x, int y, const GPixel *color);
00321 void blit(const GBitmap *bm, int x, int y, const GPixmap *color);
00326 void blend(const GBitmap *bm, int x, int y, const GPixmap *color);
00334 void stencil(const GBitmap *bm,
00335 const GPixmap *pm, int pms,
00336 const GRect *pmr, double corr=1.0);
00338
00352 void ordered_666_dither(int xmin=0, int ymin=0);
00364 void ordered_32k_dither(int xmin=0, int ymin=0);
00369 void color_correct(double corr);
00372 static void color_correct(double corr, GPixel *pixels, int npixels);
00373
00375
00379 inline unsigned int get_memory_usage() const;
00383 void save_ppm(ByteStream &bs, int raw=1) const;
00385
00398 GPixel *take_data(size_t &offset);
00405 inline void borrow_data(GPixel &data, int w, int h);
00407 void donate_data(GPixel *data, int w, int h);
00408
00413 GP<GPixmap> rotate(int count=0);
00414
00416
00417
00418
00419
00420 int get_grays(void) const { return 256; };
00421 void set_grays(int) {};\
00422
00423 protected:
00424
00425 unsigned short nrows;
00426 unsigned short ncolumns;
00427 unsigned short nrowsize;
00428 GPixel *pixels;
00429 GPixel *pixels_data;
00430 friend class DjVu_PixImage;
00431 };
00432
00434
00435
00436
00437
00438 inline int
00439 operator==(const GPixel & p1, const GPixel & p2)
00440 {
00441 return p1.r==p2.r && p1.g==p2.g && p1.b==p2.b;
00442 }
00443
00444 inline int
00445 operator!=(const GPixel & p1, const GPixel & p2)
00446 {
00447 return p1.r!=p2.r || p1.g!=p2.g || p1.b!=p2.b;
00448 }
00449
00450 inline unsigned int
00451 hash(const GPixel &p)
00452 {
00453 unsigned int x = (p.b<<16)|(p.g<<8)|(p.r);
00454 return x ^ (p.b<<4) ^ (p.r<<12);
00455 }
00456
00457 inline unsigned int
00458 GPixmap::rows() const
00459 {
00460 return nrows;
00461 }
00462
00463 inline unsigned int
00464 GPixmap::columns() const
00465 {
00466 return ncolumns;
00467 }
00468
00469 inline unsigned int
00470 GPixmap::rowsize() const
00471 {
00472 return nrowsize;
00473 }
00474
00475 inline GPixel *
00476 GPixmap::operator[](int row)
00477 {
00478 if (row<0 || row>=nrows || !pixels) return 0;
00479 return &pixels[row * nrowsize];
00480 }
00481
00482 inline const GPixel *
00483 GPixmap::operator[](int row) const
00484 {
00485 if (row<0 || row>=nrows) return 0;
00486 return &pixels[row * nrowsize];
00487 }
00488
00489 inline GPixmap &
00490 GPixmap::operator=(const GBitmap &ref)
00491 {
00492 init(ref);
00493 return *this;
00494 }
00495
00496 inline GPixmap &
00497 GPixmap::operator=(const GPixmap &ref)
00498 {
00499 init(ref);
00500 return *this;
00501 }
00502
00503 inline void
00504 GPixmap::borrow_data(GPixel &data, int w, int h)
00505 {
00506 donate_data(&data,w,h);
00507 pixels_data=0;
00508 }
00509
00511
00513
00514
00515 inline unsigned int
00516 GPixmap::get_memory_usage() const
00517 {
00518 return sizeof(GPixmap)+(nrows * ncolumns * sizeof(GPixel));
00519 }
00520
00521
00522
00523 #ifdef HAVE_NAMESPACES
00524 }
00525 # ifndef NOT_USING_DJVU_NAMESPACE
00526 using namespace DJVU;
00527 # endif
00528 #endif
00529 #endif
00530
00531