w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

jbig2enc.cc
Go to the documentation of this file.
1 // Copyright 2006 Google Inc. All Rights Reserved.
2 // Author: agl@imperialviolet.org (Adam Langley)
3 //
4 // Copyright (C) 2006 Google Inc.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 
18 #include <map>
19 #include <vector>
20 #include <algorithm>
21 
22 #include <allheaders.h>
23 #include <pix.h>
24 
25 #include <math.h>
26 #include <stdint.h>
27 
28 #define u64 uint64_t
29 #define u32 uint32_t
30 #define u16 uint16_t
31 #define u8 uint8_t
32 
33 #include "jbig2arith.h"
34 #include "jbig2sym.h"
35 #include "jbig2structs.h"
36 #include "jbig2segments.h"
37 
38 #include <winsock.h>
39 
40 #include <sys/time.h>
41 
42 // -----------------------------------------------------------------------------
43 // Removes spots which are less than size x size pixels
44 //
45 // Note, this has a side-effect of removing a few pixels
46 // that from components you want to keep.
47 //
48 // If that's a problem, you do a binary reconstruction
49 // (from seedfill.c):
50 // -----------------------------------------------------------------------------
51 static PIX *
52 remove_flyspecks(PIX *const source, const int size) {
53  Sel *sel_5h = selCreateBrick(1, size, 0, 2, SEL_HIT);
54  Sel *sel_5v = selCreateBrick(size, 1, 2, 0, SEL_HIT);
55 
56  Pix *pixt = pixOpen(NULL, source, sel_5h);
57  Pix *pixd = pixOpen(NULL, source, sel_5v);
58  pixOr(pixd, pixd, pixt);
59  pixDestroy(&pixt);
60  selDestroy(&sel_5h);
61  selDestroy(&sel_5v);
62 
63  return pixd;
64 }
65 
66 // -----------------------------------------------------------------------------
67 // Returns the number of bits needed to encode v symbols
68 // -----------------------------------------------------------------------------
69 static unsigned
70 log2up(int v) {
71  unsigned r = 0;
72  const bool is_pow_of_2 = (v & (v - 1)) == 0;
73 
74  while (v >>= 1) r++;
75  if (is_pow_of_2) return r;
76 
77  return r + 1;
78 }
79 
80 // -----------------------------------------------------------------------------
81 // This is the context for a multi-page JBIG2 document.
82 // -----------------------------------------------------------------------------
83 struct jbig2ctx {
84  struct JbClasser *classer; // the leptonica classifier
85  int xres, yres; // ppi for the X and Y direction
86  bool full_headers; // true if we are producing a full JBIG2 file
87  bool pdf_page_numbering; // true if all text pages are page "1" (pdf mode)
88  int segnum; // current segment number
89  int symtab_segment; // the segment number of the symbol table
90  // a map from page number a list of components for that page
91  std::map<int, std::vector<int> > pagecomps;
92  // for each page, the list of symbols which are only used on that page
93  std::map<int, std::vector<unsigned> > single_use_symbols;
94  // the number of symbols in the global symbol table
96  std::vector<int> page_width, page_height;
97  // Used to store the mapping from symbol number to the index in the global
98  // symbol dictionary.
99  std::map<int, int> symmap;
101  PIXA *avg_templates; // grayed templates
103  // only used when using refinement
104  // the bounding boxes of the symbols of each page.
105  std::vector<BOXA *> boxes;
106  // the number of the first symbol of each page
107  std::vector<int> baseindexes;
108  std::vector<PIXA *> comps;
109 };
110 
111 // see comments in .h file
112 struct jbig2ctx *
113 jbig2_init(float thresh, float weight, int xres, int yres, bool full_headers,
114  int refine_level) {
115  struct jbig2ctx *ctx = new jbig2ctx;
116  ctx->xres = xres;
117  ctx->yres = yres;
118  ctx->full_headers = full_headers;
120  ctx->segnum = 0;
121  ctx->symtab_segment = -1;
122  ctx->refinement = refine_level >= 0;
123  ctx->refine_level = refine_level;
124  ctx->avg_templates = NULL;
125 
126  ctx->classer = jbCorrelationInit(JB_CONN_COMPS, 9999, 9999, thresh, weight);
127 
128  return ctx;
129 }
130 
131 // see comments in .h file
132 void
133 jbig2_destroy(struct jbig2ctx *ctx) {
134  for (std::vector<BOXA *>::iterator i = ctx->boxes.begin();
135  i != ctx->boxes.end(); ++i) {
136  boxaDestroy(&(*i));
137  }
138  for (std::vector<PIXA *>::iterator i = ctx->comps.begin();
139  i != ctx->comps.end(); ++i) {
140  pixaDestroy(&(*i));
141  }
142  if (ctx->avg_templates) pixaDestroy(&ctx->avg_templates);
143  jbClasserDestroy(&ctx->classer);
144  delete ctx;
145 }
146 
147 // see comments in .h file
148 void
149 jbig2_add_page(struct jbig2ctx *ctx, struct Pix *input) {
150  PIX *bw;
151 
152  if (false /*ctx->xres >= 300*/) {
153  bw = remove_flyspecks(input, (int) (0.0084*ctx->xres));
154  } else {
155  bw = pixClone(input);
156  }
157 
158  if (ctx->refinement) {
159  ctx->baseindexes.push_back(ctx->classer->baseindex);
160  }
161 
162  jbAddPage(ctx->classer, bw);
163  ctx->page_width.push_back(bw->w);
164  ctx->page_height.push_back(bw->h);
165 
166  if (ctx->refinement) {
167  BOXA *boxes = boxaCopy(ctx->classer->boxas, L_CLONE);
168  ctx->boxes.push_back(boxes);
169  PIXA *comps = pixaCopy(ctx->classer->pixas, L_CLONE);
170  ctx->comps.push_back(comps);
171  }
172 
173  pixDestroy(&bw);
174 }
175 
176 #define F(x) memcpy(ret + offset, &x, sizeof(x)) ; offset += sizeof(x)
177 #define G(x, y) memcpy(ret + offset, x, y); offset += y;
178 #define SEGMENT(x) x.write(ret + offset); offset += x.size();
179 
180 // see comments in .h file
181 uint8_t *
182 jbig2_pages_complete(struct jbig2ctx *ctx, int *const length) {
183  // We find the symbols which only appear on a single page and encode them in
184  // a symbol dictionary just for that page. This is because we want to keep
185  // the size of the global dictionary down as some PDF readers appear to
186  // decode it for every page (!)
187 
188  // (as a short cut, we just pick the symbols which are only used once since,
189  // in testing, all the symbols which appear on only one page appear only once
190  // on that page)
191 
192  // maps symbol number to the number of times it has been used
193  // pixat->n is the number of symbols
194  // naclass->n is the number of connected components
195 
196  std::vector<unsigned> symbol_used(ctx->classer->pixat->n);
197  for (int i = 0; i < ctx->classer->naclass->n; ++i) {
198  int n;
199  numaGetIValue(ctx->classer->naclass, i, &n);
200  symbol_used[n]++;
201  }
202 
203  // the multiuse symbols are the ones which go into the global dictionary
204  std::vector<unsigned> multiuse_symbols;
205  for (int i = 0; i < ctx->classer->pixat->n; ++i) {
206  if (symbol_used[i] == 0) abort();
207  if (symbol_used[i] > 1) multiuse_symbols.push_back(i);
208  }
209  ctx->num_global_symbols = multiuse_symbols.size();
210 
211  // build the pagecomps map: a map from page number to the list of connected
212  // components for that page. The classer gives us an array from connected
213  // component number to page number - we just have to reverse it
214  for (int i = 0; i < ctx->classer->napage->n; ++i) {
215  int page_num;
216  numaGetIValue(ctx->classer->napage, i, &page_num);
217  ctx->pagecomps[page_num].push_back(i);
218  int symbol;
220  if (symbol_used[symbol] == 1) {
221  ctx->single_use_symbols[page_num].push_back(symbol);
222  }
223  }
224 
225 #ifdef DUMP_SYMBOL_GRAPH
226  for (int p = 0; p < ctx->classer->npages; ++p) {
227  for (std::vector<int>::const_iterator i = ctx->pagecomps[p].begin();
228  i != ctx->pagecomps[p].end(); ++i) {
229  const int sym = (int) ctx->classer->naclass->array[*i];
230  fprintf(stderr, "S: %d %d\n", p, sym);
231  }
232  }
233 #endif
234 
235 #ifdef SYMBOL_COMPRESSION_DEBUGGING
236  std::map<int, int> usecount;
237  for (int i = 0; i < ctx->classer->naclass->n; ++i) {
238  usecount[(int)ctx->classer->naclass->array[i]]++;
239  }
240 
241  for (int p = 0; p < ctx->classer->npages; ++p) {
242  const int numcomps = ctx->pagecomps[p].size();
243  int unique_in_doc = 0;
244  std::map<int, int> symcount;
245  for (std::vector<int>::const_iterator i = ctx->pagecomps[p].begin();
246  i != ctx->pagecomps[p].end(); ++i) {
247  const int sym = (int) ctx->classer->naclass->array[*i];
248  symcount[sym]++;
249  if (usecount[sym] == 1) unique_in_doc++;
250  }
251  int unique_this_page = 0;
252  for (std::map<int, int>::const_iterator i = symcount.begin();
253  i != symcount.end(); ++i) {
254  if (i->second == 1) unique_this_page++;
255  }
256 
257  fprintf(stderr, "Page %d %d/%d/%d\n", p, numcomps, unique_this_page, unique_in_doc);
258  }
259 #endif
260 
261 #ifdef DUMP_ALL_SYMBOLS
262  char filenamebuf[128];
263  for (int i = 0; i < ctx->classer->pixat->n; ++i) {
264  sprintf(filenamebuf, "sym-%d.png", i);
265  pixWrite(filenamebuf, ctx->classer->pixat->pix[i], IFF_PNG);
266  }
267 #endif
268  fprintf(stderr, "JBIG2 compression complete. pages:%d symbols:%d log2:%d\n",
269  ctx->classer->npages, ctx->classer->pixat->n,
270  log2up(ctx->classer->pixat->n));
271 
272  jbGetLLCorners(ctx->classer);
273 
274  struct jbig2enc_ctx ectx;
275  jbig2enc_init(&ectx);
276 
277  struct jbig2_file_header header;
278  if (ctx->full_headers) {
279  memset(&header, 0, sizeof(header));
280  header.n_pages = htonl(ctx->classer->npages);
281  header.organisation_type = 1;
282  memcpy(&header.id, JBIG2_FILE_MAGIC, 8);
283  }
284 
285  Segment seg;
286  struct jbig2_symbol_dict symtab;
287  memset(&symtab, 0, sizeof(symtab));
288 
290  (&ectx, ctx->avg_templates ? ctx->avg_templates : ctx->classer->pixat,
291  &multiuse_symbols, &ctx->symmap, ctx->avg_templates == NULL);
292  const int symdatasize = jbig2enc_datasize(&ectx);
293 
294  symtab.a1x = 3;
295  symtab.a1y = -1;
296  symtab.a2x = -3;
297  symtab.a2y = -1;
298  symtab.a3x = 2;
299  symtab.a3y = -2;
300  symtab.a4x = -2;
301  symtab.a4y = -2;
302  symtab.exsyms = symtab.newsyms = htonl(multiuse_symbols.size());
303 
304  ctx->symtab_segment = ctx->segnum;
305  seg.number = ctx->segnum;
306  ctx->segnum++;
307  seg.type = segment_symbol_table;
308  seg.len = sizeof(symtab) + symdatasize;
309  seg.page = 0;
310  seg.retain_bits = 1;
311 
312  u8 *const ret = (u8 *) malloc((ctx->full_headers ? sizeof(header) : 0) +
313  seg.size() + sizeof(symtab) + symdatasize);
314  int offset = 0;
315  if (ctx->full_headers) {
316  F(header);
317  }
318  SEGMENT(seg);
319  F(symtab);
320  jbig2enc_tobuffer(&ectx, ret + offset);
321  jbig2enc_dealloc(&ectx);
322  offset += symdatasize;
323 
324  *length = offset;
325 
326  return ret;
327 }
328 
329 // see comments in .h file
330 uint8_t *
331 jbig2_produce_page(struct jbig2ctx *ctx, int page_no,
332  int xres, int yres, int *const length) {
333  const bool last_page = page_no == ctx->classer->npages;
334  const bool include_trailer = last_page && ctx->full_headers;
335 
336  struct jbig2enc_ctx ectx;
337  jbig2enc_init(&ectx);
338 
339  Segment seg, symseg;
340  Segment endseg, trailerseg;
341  struct jbig2_page_info pageinfo;
342  memset(&pageinfo, 0, sizeof(pageinfo));
343  struct jbig2_text_region textreg;
344  memset(&textreg, 0, sizeof(textreg));
345  struct jbig2_text_region_syminsts textreg_syminsts;
346  memset(&textreg_syminsts, 0, sizeof(textreg_syminsts));
347  struct jbig2_text_region_atflags textreg_atflags;
348  memset(&textreg_atflags, 0, sizeof(textreg_atflags));
349  Segment segr;
350 
351  // page information segment
352  seg.number = ctx->segnum;
353  ctx->segnum++;
355  seg.page = ctx->pdf_page_numbering ? 1 : 1 + page_no;
356  seg.len = sizeof(struct jbig2_page_info);
357  pageinfo.width = htonl(ctx->page_width[page_no]);
358  pageinfo.height = htonl(ctx->page_height[page_no]);
359  pageinfo.xres = htonl(xres == -1 ? ctx->xres : xres);
360  pageinfo.yres = htonl(yres == -1 ? ctx->yres : yres);
361  pageinfo.is_lossless = ctx->refinement;
362 
363  std::map<int, int> second_symbol_map;
364  // If we have single-use symbols on this page we make a new symbol table
365  // containing just them.
366  const bool extrasymtab = ctx->single_use_symbols[page_no].size() > 0;
367  struct jbig2enc_ctx extrasymtab_ctx;
368 
369  struct jbig2_symbol_dict symtab;
370  memset(&symtab, 0, sizeof(symtab));
371 
372  if (extrasymtab) {
373  jbig2enc_init(&extrasymtab_ctx);
374  symseg.number = ctx->segnum++;
375  symseg.type = segment_symbol_table;
376  symseg.page = ctx->pdf_page_numbering ? 1 : 1 + page_no;
377 
379  (&extrasymtab_ctx,
380  ctx->avg_templates ? ctx->avg_templates : ctx->classer->pixat,
381  &ctx->single_use_symbols[page_no], &second_symbol_map,
382  ctx->avg_templates == NULL);
383  symtab.a1x = 3;
384  symtab.a1y = -1;
385  symtab.a2x = -3;
386  symtab.a2y = -1;
387  symtab.a3x = 2;
388  symtab.a3y = -2;
389  symtab.a4x = -2;
390  symtab.a4y = -2;
391  symtab.exsyms = symtab.newsyms =
392  htonl(ctx->single_use_symbols[page_no].size());
393 
394  symseg.len = jbig2enc_datasize(&extrasymtab_ctx) + sizeof(symtab);
395  }
396 
397  const int numsyms = ctx->num_global_symbols +
398  ctx->single_use_symbols[page_no].size();
399  BOXA *const boxes = ctx->refinement ? ctx->boxes[page_no] : NULL;
400  int baseindex = ctx->refinement ? ctx->baseindexes[page_no] : 0;
401  jbig2enc_textregion(&ectx, ctx->symmap, second_symbol_map,
402  ctx->pagecomps[page_no],
403  ctx->classer->ptall, ctx->classer->pixat,
404  ctx->classer->naclass, 1,
405  log2up(numsyms),
406  ctx->refinement ? ctx->comps[page_no] : NULL,
407  boxes, baseindex, ctx->refine_level);
408  const int textdatasize = jbig2enc_datasize(&ectx);
409  textreg.width = htonl(ctx->page_width[page_no]);
410  textreg.height = htonl(ctx->page_height[page_no]);
411  textreg.logsbstrips = 0;
412  textreg.sbrefine = ctx->refinement;
413  // refcorner = 0 -> bot left
414  textreg_syminsts.sbnuminstances = htonl(ctx->pagecomps[page_no].size());
415 
416  textreg_atflags.a1x = -1;
417  textreg_atflags.a1y = -1;
418  textreg_atflags.a2x = -1;
419  textreg_atflags.a2y = -1;
420 
421  segr.number = ctx->segnum;
422  ctx->segnum++;
424  segr.referred_to.push_back(ctx->symtab_segment);
425  if (extrasymtab) segr.referred_to.push_back(symseg.number);
426  if (ctx->refinement) {
427  segr.len = sizeof(textreg) + sizeof(textreg_syminsts) +
428  sizeof(textreg_atflags) + textdatasize;
429  } else {
430  segr.len = sizeof(textreg) + sizeof(textreg_syminsts) + textdatasize;
431  }
432 
433  segr.retain_bits = 2;
434  segr.page = ctx->pdf_page_numbering ? 1 : 1 + page_no;
435 
436  const int extrasymtab_size = extrasymtab ?
437  jbig2enc_datasize(&extrasymtab_ctx) : 0;
438 
439  if (ctx->full_headers) {
440  endseg.number = ctx->segnum;
441  ctx->segnum++;
442  endseg.type = segment_end_of_page;
443  endseg.page = ctx->pdf_page_numbering ? 1 : 1 + page_no;
444  }
445 
446  if (include_trailer) {
447  trailerseg.number = ctx->segnum;
448  ctx->segnum++;
449  trailerseg.type = segment_end_of_file;
450  trailerseg.page = 0;
451  }
452 
453  const int totalsize = seg.size() + sizeof(pageinfo) +
454  (extrasymtab ? (extrasymtab_size + symseg.size() +
455  sizeof(symtab)) : 0) +
456  segr.size() +
457  sizeof(textreg) + sizeof(textreg_syminsts) +
458  (ctx->refinement ? sizeof(textreg_atflags) : 0) +
459  textdatasize +
460  (ctx->full_headers ? endseg.size() : 0) +
461  (include_trailer ? trailerseg.size() : 0);
462  u8 *ret = (u8 *) malloc(totalsize);
463  int offset = 0;
464 
465  SEGMENT(seg);
466  F(pageinfo);
467  if (extrasymtab) {
468  SEGMENT(symseg);
469  F(symtab);
470  jbig2enc_tobuffer(&extrasymtab_ctx, ret + offset);
471  offset += extrasymtab_size;
472  }
473  SEGMENT(segr);
474  F(textreg);
475  if (ctx->refinement) {
476  F(textreg_atflags);
477  }
478  F(textreg_syminsts);
479  jbig2enc_tobuffer(&ectx, ret + offset); offset += textdatasize;
480  if (ctx->full_headers) {
481  SEGMENT(endseg);
482  }
483  if (include_trailer) {
484  SEGMENT(trailerseg);
485  }
486 
487  if (totalsize != offset) abort();
488 
489  jbig2enc_dealloc(&ectx);
490  if (extrasymtab) jbig2enc_dealloc(&extrasymtab_ctx);
491 
492  *length = offset;
493  return ret;
494 }
495 
496 #undef F
497 #undef G
498 
499 // see comments in .h file
500 u8 *
501 jbig2_encode_generic(struct Pix *const bw, const bool full_headers, const int xres,
502  const int yres, const bool duplicate_line_removal,
503  int *const length) {
504  int segnum = 0;
505 
506  if (!bw) return NULL;
507  pixSetPadBits(bw, 0);
508 
509  struct jbig2_file_header header;
510  if (full_headers) {
511  memset(&header, 0, sizeof(header));
512  header.n_pages = htonl(1);
513  header.organisation_type = 1;
514  memcpy(&header.id, JBIG2_FILE_MAGIC, 8);
515  }
516 
517  // setup compression
518  struct jbig2enc_ctx ctx;
519  jbig2enc_init(&ctx);
520 
521  Segment seg, seg2, endseg;
522  jbig2_page_info pageinfo;
523  memset(&pageinfo, 0, sizeof(pageinfo));
524  jbig2_generic_region genreg;
525  memset(&genreg, 0, sizeof(genreg));
526 
527  seg.number = segnum;
528  segnum++;
530  seg.page = 1;
531  seg.len = sizeof(struct jbig2_page_info);
532  pageinfo.width = htonl(bw->w);
533  pageinfo.height = htonl(bw->h);
534  pageinfo.xres = htonl(xres ? xres : bw->xres);
535  pageinfo.yres = htonl(yres ? yres : bw->yres);
536  pageinfo.is_lossless = 1;
537 
538  jbig2enc_bitimage(&ctx, (u8 *) bw->data, bw->w, bw->h, duplicate_line_removal);
539  jbig2enc_final(&ctx);
540  const int datasize = jbig2enc_datasize(&ctx);
541 
542  seg2.number = segnum;
543  segnum++;
545  seg2.page = 1;
546  seg2.len = sizeof(genreg) + datasize;
547 
548  genreg.width = htonl(bw->w);
549  genreg.height = htonl(bw->h);
550  if (duplicate_line_removal) {
551  genreg.tpgdon = true;
552  }
553  genreg.a1x = 3;
554  genreg.a1y = -1;
555  genreg.a2x = -3;
556  genreg.a2y = -1;
557  genreg.a3x = 2;
558  genreg.a3y = -2;
559  genreg.a4x = -2;
560  genreg.a4y = -2;
561 
562  const int totalsize = seg.size() + sizeof(pageinfo) + seg2.size() +
563  sizeof(genreg) + datasize +
564  (full_headers ? (sizeof(header) + 2*endseg.size()) : 0);
565  u8 *const ret = (u8 *) malloc(totalsize);
566  int offset = 0;
567 
568 #define F(x) memcpy(ret + offset, &x, sizeof(x)) ; offset += sizeof(x)
569  if (full_headers) {
570  F(header);
571  }
572  SEGMENT(seg);
573  F(pageinfo);
574  SEGMENT(seg2);
575  F(genreg);
576  jbig2enc_tobuffer(&ctx, ret + offset);
577  offset += datasize;
578 
579  if (full_headers) {
580  endseg.type = segment_end_of_page;
581  SEGMENT(endseg);
582  endseg.type = segment_end_of_file;
583  SEGMENT(endseg);
584  }
585 
586  if (totalsize != offset) abort();
587 
588  jbig2enc_dealloc(&ctx);
589 
590  *length = offset;
591 
592  return ret;
593 }
594 
BOXA * boxaCopy(BOXA *boxa, l_int32 copyflag)
Definition: box.c:478
void boxaDestroy(BOXA **pboxa)
Definition: box.c:522
#define n
Definition: t4ht.c:1290
int v
Definition: dviconv.c:10
#define memcpy(d, s, n)
Definition: gsftopk.c:64
@ IFF_PNG
Definition: imageio.h:31
JBCLASSER * jbCorrelationInit(l_int32 components, l_int32 maxwidth, l_int32 maxheight, l_float32 thresh, l_float32 weightfactor)
Definition: jbclass.c:299
void jbClasserDestroy(JBCLASSER **pclasser)
Definition: jbclass.c:1504
l_int32 jbAddPage(JBCLASSER *classer, PIX *pixs)
Definition: jbclass.c:395
l_int32 jbGetLLCorners(JBCLASSER *classer)
Definition: jbclass.c:1962
@ JB_CONN_COMPS
Definition: jbclass.h:114
void jbig2enc_bitimage(struct jbig2enc_ctx *__restrict__ ctx, const uint8_t *__restrict__ idata, int mx, int my, bool duplicate_line_removal)
Definition: jbig2arith.cc:468
void jbig2enc_dealloc(struct jbig2enc_ctx *ctx)
Definition: jbig2arith.cc:164
unsigned jbig2enc_datasize(const struct jbig2enc_ctx *ctx)
Definition: jbig2arith.cc:443
void jbig2enc_final(struct jbig2enc_ctx *__restrict__ ctx)
Definition: jbig2arith.cc:315
void jbig2enc_tobuffer(const struct jbig2enc_ctx *__restrict__ ctx, uint8_t *__restrict__ buffer)
Definition: jbig2arith.cc:449
void jbig2enc_init(struct jbig2enc_ctx *ctx)
Definition: jbig2arith.cc:121
static unsigned log2up(int v)
Definition: jbig2enc.cc:70
uint8_t * jbig2_produce_page(struct jbig2ctx *ctx, int page_no, int xres, int yres, int *const length)
Definition: jbig2enc.cc:331
#define F(x)
Definition: jbig2enc.cc:176
uint8_t * jbig2_encode_generic(struct Pix *const bw, const bool full_headers, const int xres, const int yres, const bool duplicate_line_removal, int *const length)
Definition: jbig2enc.cc:501
struct jbig2ctx * jbig2_init(float thresh, float weight, int xres, int yres, bool full_headers, int refine_level)
Definition: jbig2enc.cc:113
#define SEGMENT(x)
Definition: jbig2enc.cc:178
static PIX * remove_flyspecks(PIX *const source, const int size)
Definition: jbig2enc.cc:52
void jbig2_add_page(struct jbig2ctx *ctx, struct Pix *input)
Definition: jbig2enc.cc:149
void jbig2_destroy(struct jbig2ctx *ctx)
Definition: jbig2enc.cc:133
uint8_t * jbig2_pages_complete(struct jbig2ctx *ctx, int *const length)
Definition: jbig2enc.cc:182
#define u8
Definition: jbig2enc.cc:31
@ segment_page_information
Definition: jbig2structs.h:26
@ segment_imm_generic_region
Definition: jbig2structs.h:25
@ segment_end_of_file
Definition: jbig2structs.h:29
@ segment_imm_text_region
Definition: jbig2structs.h:27
@ segment_end_of_page
Definition: jbig2structs.h:28
@ segment_symbol_table
Definition: jbig2structs.h:24
#define JBIG2_FILE_MAGIC
Definition: jbig2structs.h:35
void jbig2enc_textregion(struct jbig2enc_ctx *__restrict__ ctx, std::map< int, int > &symmap, std::map< int, int > &symmap2, const std::vector< int > &comps, PTA *const in_ll, PIXA *const symbols, NUMA *assignments, int stripwidth, int symbits, PIXA *const source, BOXA *boxes, int baseindex, int refine_level)
Definition: jbig2sym.cc:203
void jbig2enc_symboltable(struct jbig2enc_ctx *__restrict__ ctx, PIXA *__restrict__ const symbols, std::vector< unsigned > *__restrict__ symbol_list, std::map< int, int > *symmap, const bool unborder_symbols)
Definition: jbig2sym.cc:76
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
unsigned char uint8_t
Definition: stdint.h:78
static int ret
Definition: convert.c:72
static int thresh
Definition: qsort.c:23
#define fprintf
Definition: mendex.h:64
#define length(c)
Definition: ctangleboot.c:65
#define malloc
Definition: alloca.c:91
#define symbol(x)
Definition: web2c-parser.c:71
void abort()
#define sprintf
Definition: snprintf.c:44
l_int32 numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
Definition: numarray.c:484
void pixaDestroy(PIXA **ppixa)
Definition: pixa.c:275
void pixDestroy(PIX **ppix)
Definition: pix1.c:225
PIX * pixOpen(PIX *pixd, PIX *pixs, SEL *sel)
Definition: morph.c:342
PIXA * pixaCopy(PIXA *pixa, l_int32 copyflag)
Definition: pixa.c:319
void selDestroy(SEL **psel)
Definition: sel1.c:184
PIX * pixOr(PIX *pixd, PIX *pixs1, PIX *pixs2)
Definition: pix2.c:1224
l_int32 pixWrite(const char *filename, PIX *pix, l_int32 format)
Definition: writefile.c:113
l_int32 pixSetPadBits(PIX *pix, l_int32 val)
Definition: pix2.c:558
SEL * selCreateBrick(l_int32 h, l_int32 w, l_int32 cy, l_int32 cx, l_int32 type)
Definition: sel1.c:263
PIX * pixClone(PIX *pixs)
Definition: pix1.c:197
@ SEL_HIT
Definition: morph.h:40
static int xres
Definition: pbmto4425.c:21
static int yres
Definition: pbmto4425.c:22
@ L_CLONE
Definition: pix.h:363
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
static int size
Definition: ppmlabel.c:24
int r
Definition: ppmqvga.c:68
static int offset
Definition: ppmtogif.c:642
bstring c int memset(void *s, int c, int length)
#define seg
Definition: pix.h:303
struct Pixa * pixat
Definition: jbclass.h:59
l_int32 npages
Definition: jbclass.h:41
struct Pta * ptall
Definition: jbclass.h:73
struct Numa * napage
Definition: jbclass.h:69
struct Boxa * boxas
Definition: jbclass.h:53
struct Numa * naclass
Definition: jbclass.h:68
struct Pixa * pixas
Definition: jbclass.h:54
l_int32 baseindex
Definition: jbclass.h:42
l_float32 * array
Definition: array.h:42
l_int32 n
Definition: array.h:40
Definition: pix.h:51
l_uint32 * data
Definition: pix.h:64
l_uint32 w
Definition: pix.h:52
l_uint32 yres
Definition: pix.h:59
l_uint32 h
Definition: pix.h:53
l_uint32 xres
Definition: pix.h:57
Definition: pix.h:268
struct Pix ** pix
Definition: pix.h:272
l_int32 n
Definition: pix.h:269
unsigned number
Definition: jbig2segments.h:43
unsigned size() const
Definition: jbig2segments.h:80
int retain_bits
Definition: jbig2segments.h:46
unsigned len
Definition: jbig2segments.h:49
unsigned page
Definition: jbig2segments.h:48
std::vector< unsigned > referred_to
Definition: jbig2segments.h:47
Definition: morph.h:112
Definition: execute.c:108
signed char a4y
Definition: jbig2structs.h:127
signed char a1x
Definition: jbig2structs.h:127
signed char a2y
Definition: jbig2structs.h:127
signed char a1y
Definition: jbig2structs.h:127
signed char a3x
Definition: jbig2structs.h:127
signed char a2x
Definition: jbig2structs.h:127
signed char a3y
Definition: jbig2structs.h:127
signed char a4x
Definition: jbig2structs.h:127
std::vector< int > page_height
Definition: jbig2enc.cc:96
std::vector< int > baseindexes
Definition: jbig2enc.cc:107
std::vector< int > page_width
Definition: jbig2enc.cc:96
int xres
Definition: jbig2enc.cc:85
bool pdf_page_numbering
Definition: jbig2enc.cc:87
int refine_level
Definition: jbig2enc.cc:102
std::map< int, int > symmap
Definition: jbig2enc.cc:99
std::vector< BOXA * > boxes
Definition: jbig2enc.cc:105
std::vector< PIXA * > comps
Definition: jbig2enc.cc:108
bool refinement
Definition: jbig2enc.cc:100
std::map< int, std::vector< int > > pagecomps
Definition: jbig2enc.cc:91
struct JbClasser * classer
Definition: jbig2enc.cc:84
int symtab_segment
Definition: jbig2enc.cc:89
int num_global_symbols
Definition: jbig2enc.cc:95
PIXA * avg_templates
Definition: jbig2enc.cc:101
std::map< int, std::vector< unsigned > > single_use_symbols
Definition: jbig2enc.cc:93
int segnum
Definition: jbig2enc.cc:88
bool full_headers
Definition: jbig2enc.cc:86
int yres
Definition: jbig2enc.cc:85
Definition: gd.c:2418
Definition: sh.h:1345
return() int(((double) *(font_tbl[cur_fnt].wtbl+(int)(*(font_tbl[cur_fnt].char_wi+(int)(ch - font_tbl[cur_fnt].char_f)% 256)))/(double)(1L<< 20)) *(double) font_tbl[cur_fnt].scale)
unsigned long htonl(unsigned long inv)
#define sym(x)
Definition: y.tab.c:133