Fix (pdfwrite) : Improving heuristics in the compression chooser.
"Igor V. Melichev" <[email protected]>
| Newsgroups | gmane.comp.printing.ghostscript.patches |
|---|---|
| Message-ID | <[email protected]> |
[Log message beg] Fix (pdfwrite) : Improving heuristics in the compression chooser. DETAILS : Gradients' area was wrongly computed. Fixing it and adjust thresholds to comply with the new computation. Bug 687169 "(pdfwrite) : An imperfect compression choice with dina3_watermark.pdf". Processing comparefiles, with this patch pdfwrite chooses a compression closer to the original document. I noticed 3 tests differing from source : Fixed_Original.pdf loremIpsum.pdf S2_Digitalproof-Forum_x3k.pdf In all 3 tests the images are like a photo, so DCT is the right choice rather than the original Flate or LZW. EXPECTED DIFFERENCES : adesso2.pdf adesso5.pdf Altona-Testsuite_p2_S_x3.pdf Altona.Page_3.2002-09-27.pdf BEST8-99-Path.fh7.pdf besttest.pdf dina3_watermark.pdf DisplayedGood.pdf DisplayedWrong.pdf Faktura.pdf Fixed_Original.pdf foo.pdf H00216q.pdf kazmir.pdf loremIpsum.pdf MagicEye.pdf Original.pdf S2_Digitalproof-Forum_x3k.pdf si_tg_brochure.pdf test.pdf [Log message end] _______________________________________________ gs-code-review mailing list [email protected] http://www.ghostscript.com/mailman/listinfo/gs-code-review
patch.txt
(text/plain, 4.3 KB)
Changes:
*** f:\casper\HEAD\gs\src\gdevpdfj.c Wed Sep 10 12:01:46 2003
--- files\gs\src\gdevpdfj.c Wed Nov 26 21:10:33 2003
***************
*** 535,538 ****
--- 535,542 ----
l0 = cos_stream_length(s[0]);
l1 = cos_stream_length(s[1]);
+
+ if (force && l0 <= l1)
+ k0 = 1; /* Use Flate if it is not longer. */
+ else {
k0 = s_compr_chooser__get_choice(
(stream_compr_chooser_state *)piw->binary[2].strm->state, force);
***************
*** 545,548 ****
--- 549,553 ----
else
return;
+ }
k1 = 1 - k0;
s_close_filters(&piw->binary[k0].strm, piw->binary[k0].target);
*** f:\casper\HEAD\gs\src\gdevpsds.c Mon Jun 17 02:07:55 2002
--- files\gs\src\gdevpsds.c Thu Nov 27 14:12:52 2003
***************
*** 802,812 ****
}
- /* An auxiliary proc for the choice. */
- private inline bool
- much_bigger__PLR(int n1, int n2)
- {
- return n1 >= 10000 && n2 < n1 / 3 && n2 > 100; /* arbitrary */
- }
-
/* Estimate a row for photo/lineart recognition. */
private void
--- 802,805 ----
***************
*** 823,828 ****
Dealing with vertical ones would be too expensive.
*/
! const int delta = 256 / 16; /* about 1/16 of the range */
! const int max_lineart_boundary_width = 3/* pixels */;
int i, j0 = 0, j1 = 0;
int w0 = p[0], w1 = p[0], v;
--- 816,822 ----
Dealing with vertical ones would be too expensive.
*/
! const int delta = 256 / 16; /* about 1/16 of the color range */
! const int max_lineart_boundary_width = 3; /* pixels */
! const int max_gradient_constant = 10; /* pixels */
int i, j0 = 0, j1 = 0;
int w0 = p[0], w1 = p[0], v;
***************
*** 834,839 ****
v = p[i];
if (!lower) {
! if (w1 < v)
! w1 = v, upper = true;
else if (upper && w1 - delta > v) {
/* end of upper plateau at w1-delta...w1 */
--- 828,838 ----
v = p[i];
if (!lower) {
! if (w1 < v) {
! if (!upper)
! j1 = i - 1;
! w1 = v;
! upper = true;
! } else if (w1 == v && j1 < i - max_gradient_constant)
! j1 = i - max_gradient_constant; /* inner constant plateaw */
else if (upper && w1 - delta > v) {
/* end of upper plateau at w1-delta...w1 */
***************
*** 850,858 ****
j1 = i;
upper = false;
}
}
if (!upper) {
! if (w0 > v)
! w0 = v, lower = true;
else if (lower && w0 + delta < v) {
/* end of lower plateau at w0...w0+delta */
--- 849,864 ----
j1 = i;
upper = false;
+ w0 = w1;
+ continue;
}
}
if (!upper) {
! if (w0 > v) {
! if (!lower)
! j1 = i - 1;
! w0 = v;
! lower = true;
! } else if (w0 == v && j1 < i - max_gradient_constant)
! j1 = i - max_gradient_constant; /* inner constant plateaw */
else if (lower && w0 + delta < v) {
/* end of lower plateau at w0...w0+delta */
***************
*** 869,872 ****
--- 875,879 ----
j1 = i;
lower = false;
+ w1 = w0;
}
}
***************
*** 885,892 ****
ss->gradients += gradients;
plateaus = min(ss->lower_plateaus, ss->upper_plateaus); /* (fore/back)ground */
! if (much_bigger__PLR(plateaus, ss->gradients))
! ss->choice = 2; /* choice is made : lineart */
! else if (much_bigger__PLR(ss->gradients, plateaus))
ss->choice = 1; /* choice is made : photo */
}
}
--- 892,899 ----
ss->gradients += gradients;
plateaus = min(ss->lower_plateaus, ss->upper_plateaus); /* (fore/back)ground */
! if (ss->gradients >= 10000 && ss->gradients > plateaus / 6)
ss->choice = 1; /* choice is made : photo */
+ else if (plateaus >= 100000 && plateaus / 5000 >= ss->gradients)
+ ss->choice = 2; /* choice is made : lineart */
}
}
***************
*** 978,988 ****
ulong plateaus = min(ss->lower_plateaus, ss->upper_plateaus);
if (force) {
! if (ss->gradients > plateaus / 3/* arbitrary */)
! return 2;
! else if (plateaus > ss->gradients)
! return 1;
}
! return ss->choice;
}
--- 985,997 ----
ulong plateaus = min(ss->lower_plateaus, ss->upper_plateaus);
+ if (ss->choice)
+ return ss->choice;
if (force) {
! if (ss->gradients > plateaus / 12) /* messenger16.pdf, page 3. */
! return 1; /* photo */
! else if (plateaus / 5000 >= ss->gradients)
! return 2; /* lineart */
}
! return 0;
}