summaryrefslogtreecommitdiffstats
path: root/kfaxview/libkfaximage/faxexpand.h
blob: 72819e23216b89c7e6d388d584a23dd7f73b6b86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* Include file for fax routines
   Copyright (C) 1990, 1995  Frank D. Cringle.
   Copyright (C) 2005  Helge Deller <[email protected]>

This file is part of viewfax - g3/g4 fax processing software.
     
viewfax is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
     
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
     
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */

#ifndef _faxexpand_h_
#define _faxexpand_h_

#include <sys/types.h>
#include <unistd.h>

#include <tqglobal.h>
#include <tqimage.h>

#define t32bits TQ_UINT32
#define t16bits TQ_UINT16

typedef t16bits pixnum;

class pagenode;

/* drawfunc() points to a function which processes a line of the
   expanded image described as a list of run lengths.
   run is the base of an array of lengths, starting with a
   (possibly empty) white run for line number linenum.
   pn points to the page descriptor */
typedef void (*drawfunc)(pixnum *run, int linenum, class pagenode *pn);

struct strip {			/* tiff strip descriptor */
    off_t offset;		/* offset in file */
    off_t size;			/* size of this strip */
};


/* defines for the pagenode member: type */
#define FAX_TIFF   1
#define FAX_RAW    2

class pagenode {		/* compressed page descriptor */
    public:
    pagenode();
    ~pagenode() { };
    int	nstrips;		/* number of strips */
    int rowsperstrip;		/* number of rows per strip */
    int stripnum;		/* current strip while expanding */
    struct strip *strips;	/* array of strips containing fax data in file */
    t16bits *data;		/* in-memory copy of strip */
    size_t length;		/* length of data */
    TQSize size;			/* width & height of page in pixels */
    int inverse;		/* black <=> white */
    int lsbfirst;		/* bit order is lsb first */
    int type;	                /* Bernd: tiff vs no tiff*/
    int orient;			/* orientation - upsidedown, landscape, mirrored */
    int vres;			/* vertical resolution: 1 = fine  */
    TQPoint dpi;			/* DPI horz/vert */
    void (*expander)(class pagenode *, drawfunc);
    TQImage image;
    unsigned int bytes_per_line;
};

extern class pagenode *firstpage, *lastpage, *thispage;
extern class pagenode defaultpage;

/* page orientation flags */
#define TURN_NONE 0
#define TURN_U	1
#define TURN_L	2
#define TURN_M	4

/* fsm state codes */
#define S_Null		0
#define S_Pass		1
#define S_Horiz		2
#define S_V0		3
#define S_VR		4
#define S_VL		5
#define S_Ext		6
#define S_TermW		7
#define S_TermB		8
#define S_MakeUpW	9
#define S_MakeUpB	10
#define S_MakeUp	11
#define S_EOL		12

/* state table entry */
struct tabent {
    unsigned char State;
    unsigned char Width;	/* width of code in bits */
    pixnum Param;		/* run length */
};

extern struct tabent MainTable[]; 	/* 2-D state table */
extern struct tabent WhiteTable[];	/* White run lengths */
extern struct tabent BlackTable[];	/* Black run lengths */

void MHexpand(class pagenode *pn, drawfunc df);
void g31expand(class pagenode *pn, drawfunc df);
void g32expand(class pagenode *pn, drawfunc df);
void g4expand(class pagenode *pn, drawfunc df);

unsigned char *getstrip(class pagenode *pn, int strip);
class pagenode *notefile(const char *name);
int notetiff(const char *name);

/* initialise code tables */
extern void fax_init_tables(void);

/* count lines in image */
extern int G3count(class pagenode *pn, int twoD);

#endif