Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: src/pdf/SkPngPredictors.cpp

Issue 1686313005: SkPDF: Implement Paeth predictor for images. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-02-19 (Friday) 15:12:05 EST Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/pdf/SkPngPredictors.h ('K') | « src/pdf/SkPngPredictors.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkPngPredictors.h"
9 #include "SkTypes.h"
10
11 namespace {
12 enum EncodeOrDecode {
mtklein 2016/02/19 21:53:07 Please remove the dead kDecode path and all relate
13 kEncode,
14 kDecode,
15 };
16 }
17
18 // If encoding, prev == out is okay.
19 // If decoding, scanline == out is okay.
20 // prev can be null.
21 template<int COMPONENT_COUNT, EncodeOrDecode ENCODE_OR_DECODE>
mtklein 2016/02/19 21:53:07 ALL_UPPPER_CASE_IS_FOR_MACROS_DUDE This is genera
22 static void paeth(int width, const uint8_t* prev, const uint8_t* scanline, uint8 _t* out) {
23 static_assert(COMPONENT_COUNT > 0, "");
24 // a = left, b = above, c = upper left
25 if (prev) {
26 uint8_t a[COMPONENT_COUNT]{}, c[COMPONENT_COUNT]{};
mtklein 2016/02/19 21:53:07 I think this would be easier to follow byte-by-byt
27 while (width-- > 0) {
28 for (int cmp = 0; cmp < COMPONENT_COUNT; ++cmp) {
29 uint8_t b = *prev++;
30 uint8_t x = *scanline++;
31 int pa = SkTAbs<int>(b - c[cmp]);
32 int pb = SkTAbs<int>(a[cmp] - c[cmp]);
33 int pc = SkTAbs<int>((b - c[cmp]) + (a[cmp] - c[cmp]));
34 int smallest = SkTMin(pc, SkTMin(pa, pb));
mtklein 2016/02/19 21:53:07 For serial code, this is faster and simpler like t
35 uint8_t pred = smallest == pa ? a[cmp] : (smallest == pb ? b : c [cmp]);
36 static_assert(ENCODE_OR_DECODE == kEncode || ENCODE_OR_DECODE == kDecode, "");
37 if (ENCODE_OR_DECODE == kEncode) {
38 *out++ = x - pred;
39 } else {
40 *out++ = x + pred;
41 }
42 a[cmp] = x;
43 c[cmp] = b;
44 }
45 }
46 } else {
mtklein 2016/02/19 21:53:07 Let's split this else case off as static void s
47 uint8_t a[COMPONENT_COUNT]{};
48 while (width-- > 0) {
49 for (int cmp = 0; cmp < COMPONENT_COUNT; ++cmp) {
50 uint8_t x = *scanline++;
51 *out++ = x - a[cmp];
mtklein 2016/02/19 21:53:07 This is why you should not land dead code.
52 a[cmp] = x;
53 }
54 }
55 }
56 }
57
58 void SkPaethEncode3(int width, const uint8_t* prev, const uint8_t* scanline, uin t8_t* out) {
59 return paeth<3, kEncode>(width, prev, scanline, out);
60 }
61
62 void SkPaethEncode1(int width, const uint8_t* prev, const uint8_t* scanline, uin t8_t* out) {
63 return paeth<1, kEncode>(width, prev, scanline, out);
64 }
OLDNEW
« src/pdf/SkPngPredictors.h ('K') | « src/pdf/SkPngPredictors.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698