| 1 |
/* |
| 2 |
* bmpcoder.h - encoding/decoding bitmaps (DjVu 2 specification, 8.5.9-10) |
| 3 |
*/ |
| 4 |
|
| 5 |
#ifndef MDJVU_BMPCODER_H |
| 6 |
#define MDJVU_BMPCODER_H |
| 7 |
|
| 8 |
#include "jb2const.h" |
| 9 |
#include "zp.h" |
| 10 |
|
| 11 |
class JB2BitmapCoder |
| 12 |
{ |
| 13 |
public: |
| 14 |
void reset_numcontexts(); // this was introduced in DjVu 3 |
| 15 |
protected: |
| 16 |
ZPBitContext bitmap_direct[1024]; |
| 17 |
ZPBitContext bitmap_refine[2048]; |
| 18 |
ZPNumContext |
| 19 |
symbol_width, |
| 20 |
symbol_height, |
| 21 |
symbol_width_difference, |
| 22 |
symbol_height_difference; |
| 23 |
JB2BitmapCoder(ZPMemoryWatcher *w = NULL); |
| 24 |
|
| 25 |
virtual ~JB2BitmapCoder(); |
| 26 |
|
| 27 |
void code_row_directly(int32 n, unsigned char *up2, |
| 28 |
unsigned char *up1, |
| 29 |
unsigned char *target, |
| 30 |
unsigned char *erosion); |
| 31 |
void code_row_by_refinement(int32 n, |
| 32 |
unsigned char *up1, |
| 33 |
unsigned char *target, |
| 34 |
unsigned char *p_up, |
| 35 |
unsigned char *p_sm, |
| 36 |
unsigned char *p_dn, |
| 37 |
unsigned char *erosion); |
| 38 |
void code_image_directly(mdjvu_bitmap_t, mdjvu_bitmap_t erosion_mask); |
| 39 |
void code_image_by_refinement(mdjvu_bitmap_t, mdjvu_bitmap_t prototype, mdjvu_bitmap_t erosion_mask); |
| 40 |
|
| 41 |
virtual int code_pixel(ZPBitContext &, unsigned char *pixel, int erosion) = 0; |
| 42 |
virtual void load_row(mdjvu_bitmap_t, int32 y, unsigned char *row) = 0; |
| 43 |
virtual void save_row(mdjvu_bitmap_t, int32 y, unsigned char *row, int erosion) = 0; |
| 44 |
}; |
| 45 |
|
| 46 |
class JB2BitmapDecoder : public JB2BitmapCoder |
| 47 |
{ |
| 48 |
public: |
| 49 |
mdjvu_bitmap_t decode(mdjvu_image_t, |
| 50 |
mdjvu_bitmap_t prototype = NULL); |
| 51 |
JB2BitmapDecoder(ZPDecoder &, ZPMemoryWatcher *w = NULL); |
| 52 |
private: |
| 53 |
ZPDecoder &zp; |
| 54 |
// JB3BitmapDecoder jb3; /* XXX */ |
| 55 |
virtual int code_pixel(ZPBitContext &, unsigned char *pixel, int erosion); |
| 56 |
virtual void load_row(mdjvu_bitmap_t, int32 y, unsigned char *row); |
| 57 |
virtual void save_row(mdjvu_bitmap_t, int32 y, unsigned char *row, int erosion); |
| 58 |
}; |
| 59 |
|
| 60 |
class JB2BitmapEncoder : public JB2BitmapCoder |
| 61 |
{ |
| 62 |
public: |
| 63 |
void encode(mdjvu_bitmap_t, mdjvu_bitmap_t prototype = NULL, mdjvu_bitmap_t erosion_mask = NULL); |
| 64 |
JB2BitmapEncoder(ZPEncoder &, ZPMemoryWatcher *w = NULL); |
| 65 |
private: |
| 66 |
ZPEncoder &zp; |
| 67 |
// JB3BitmapEncoder jb3; /* XXX */ |
| 68 |
virtual int code_pixel(ZPBitContext &, unsigned char *pixel, int erosion); |
| 69 |
virtual void load_row(mdjvu_bitmap_t, int32 y, unsigned char *row); |
| 70 |
virtual void save_row(mdjvu_bitmap_t, int32 y, unsigned char *row, int erosion); |
| 71 |
}; |
| 72 |
|
| 73 |
#endif |