aboutsummaryrefslogtreecommitdiff
path: root/non-free/esmod.hh
blob: c1ce40b54ec5ed95a2d955f6f476b003af0d2d5c (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//  esmod.hh -- exposed API of the 'esmod' library
//  Copyright (C) 2019 SEIKO EPSON Corporation
//
//  This file is part of the 'esmod' library.
//
//  The 'esmod' library is non-free software.
//  It is distributed under the terms of the EPSON END USER SOFTWARE LICENSE.
//
//  You should have received a verbatim copy of the EPSON END USER
//  SOFTWARE LICENSE along with the software.


#ifndef esmod_hh_included
#define esmod_hh_included

#ifndef __cplusplus
#error "This is a C++ header file; use a C++ compiler to compile it."
#endif

#include <cstddef>              /* for size_t */

namespace esmod
{

#define ESMOD_OPTION_FLATBED            (0)
#define ESMOD_OPTION_TPU                (1)
#define ESMOD_OPTION_ADF                (2)

#define ESMOD_FILM_NEGATIVE             (0)
#define ESMOD_FILM_POSITIVE             (1)

#define ESMOD_PIXEL_RGB                 (0)
#define ESMOD_PIXEL_GRAY                (1)
#define ESMOD_PIXEL_MONO                (2)

#define ESMOD_IMAGE_PHOTO               (0)
#define ESMOD_IMAGE_DOCUMENT            (1)
#define ESMOD_IMAGE_LINE_ART            (2)

#define ESMOD_DEFAULT_GAMMA             (1.0)
#define ESMOD_DEFAULT_HILITE          (245)
#define ESMOD_DEFAULT_SHADOW            (8)
#define ESMOD_DEFAULT_THRESHOLD       (160)

#define ESMOD_FOCUS_UMASK               (1)
#define ESMOD_FOCUS_GAUSS               (2)
#define ESMOD_FOCUS_UMASK_Y             (3)

#define ESMOD_SCALE_NEAREST_NEIGHBOUR   (1)
#define ESMOD_SCALE_BILINEAR            (2)
#define ESMOD_SCALE_BICUBIC             (3)


typedef unsigned char byte_type;
typedef size_t        size_type;
typedef bool          bool_type;
typedef int           type_type;
typedef long          long_type;
typedef unsigned long parm_type;
typedef double        real_type;


class filter
{
public:
  virtual ~filter () {};

  //! Returns a block of n bytes of post-filter data.
  virtual filter& getblock (      byte_type *block, size_type n) = 0;
  //! Feeds the filter a block of n bytes of data.
  virtual filter& putblock (const byte_type *block, size_type n) = 0;
  //! Combines putblock() and getblock() in a single call.
  virtual filter& exec     (const byte_type *i_block, size_type i_n,
                                  byte_type *o_block, size_type o_n)
  {
           putblock (i_block, i_n);
    return getblock (o_block, o_n);
  }

  //! Returns number of additional input lines needed for out_lines of output.
  virtual size_type get_line_quote (size_type out_lines)
  { return out_lines; };

protected:
  void *_hidden_data;
  filter () {};

private:                        // undefined to prevent copying
  filter (const filter&);
  filter& operator= (const filter&);
};

class focus : public filter
{
public:
  focus (long_type width, long_type height, long_type rowbytes,
         size_type bits_per_pixel);
  focus (long_type i_width, long_type i_height, long_type i_rowbytes,
         long_type o_width, long_type o_height, long_type o_rowbytes,
         size_type bits_per_pixel,
         parm_type strength, parm_type radius, parm_type clipping,
         type_type focus_type);
  virtual ~focus ();

  void set_parms (size_type resolution, bool_type film_type, bool_type is_dumb,
                  parm_type *strength, parm_type *radius, parm_type *clipping);

  virtual filter& getblock (      byte_type *block, size_type n);
  virtual filter& putblock (const byte_type *block, size_type n);
  virtual filter& exec     (const byte_type *i_block, size_type i_n,
                                  byte_type *o_block, size_type o_n);

  virtual size_type get_line_quote (size_type out_lines);
};

class moire : public filter
{
public:
  moire (long_type i_width, long_type i_height, long_type i_rowbytes,
         long_type o_width, long_type o_height, long_type o_rowbytes,
         size_type bits_per_pixel,
         size_type resolution, bool_type is_dumb);
  virtual ~moire ();

  virtual filter& getblock (      byte_type *block, size_type n);
  virtual filter& putblock (const byte_type *block, size_type n);
  virtual filter& exec     (const byte_type *i_block, size_type i_n,
                                  byte_type *o_block, size_type o_n);

  static  size_type get_res_quote  (size_type out_res, bool_type is_dumb);
  virtual size_type get_line_quote (size_type out_lines);
};

class scale : public filter
{
public:
  scale (long_type i_width, long_type i_height, long_type i_rowbytes,
         long_type o_width, long_type o_height, long_type o_rowbytes,
         size_type bits_per_pixel,
         type_type scale_type);
  virtual ~scale ();

  virtual filter& getblock (      byte_type *block, size_type n);
  virtual filter& putblock (const byte_type *block, size_type n);
  virtual filter& exec     (const byte_type *i_block, size_type i_n,
                                  byte_type *o_block, size_type o_n);

  virtual size_type get_line_quote (size_type out_lines);
};

// WARNING: These quite likely modify global state in libesmod.
void auto_expose (type_type option_type, type_type film_type,
                  byte_type *image,
                  long_type width, long_type height, long_type rowbytes,
                  long_type top, long_type left,
                  long_type bottom, long_type right,
                  long_type *gamma, long_type *hilite,
                  long_type *shadow, long_type *graybalance,
                  real_type film_gamma[3],
                  real_type film_yp[3],
                  real_type grayl[3],
                  bool_type is_photo, bool_type is_dumb);
void build_LUT (type_type option_type, type_type film_type,
                type_type pixel_type, type_type image_type,
                long_type gamma, long_type hilite,
                long_type shadow, long_type graybalance,
                const real_type film_gamma[3],
                const real_type film_yp[3],
                const real_type grayl[3],
                byte_type master[256],
                byte_type rgb[3 * 256],
                byte_type lut[3 * 256],
                bool is_dumb);

} // namespace esmod

#endif  /* !defined (esmod_hh_included) */