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

Side by Side Diff: src/codec/SkSwizzler.h

Issue 930283002: Add SkCodec, including PNG implementation. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Make SkPngCodec work on Mac! Created 5 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 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 #ifndef SkSwizzler_DEFINED
9 #define SkSwizzler_DEFINED
10
11 #include "SkTypes.h"
12 #include "SkColor.h"
13 #include "SkImageInfo.h"
14
15 class SkSwizzler : public SkNoncopyable {
16 public:
17 /**
18 * Enum describing the config of the source data.
19 */
20 enum SrcConfig {
21 kGray, // 1 byte per pixel
22 kIndex, // 1 byte per pixel
23 kRGB, // 3 bytes per pixel
24 kRGBX, // 4 byes per pixel (ignore 4th)
25 kRGBA, // 4 bytes per pixel
26 kRGB_565 // 2 bytes per pixel
27 };
28
29 static int BytesPerPixel(SrcConfig sc) {
30 switch (sc) {
31 case kGray:
32 case kIndex:
33 return 1;
34 case kRGB:
35 return 3;
36 case kRGBX:
37 case kRGBA:
38 return 4;
39 case kRGB_565:
40 return 2;
41 }
42 }
43
44 /**
45 * Create a new SkSwizzler.
46 * @param sc SrcConfig
47 * @param info dimensions() describe both the src and the dst.
48 * Other fields describe the dst.
49 * @param dst Destination to write pixels. Must match info and dstRowBytes
50 * @param dstRowBytes rowBytes for dst.
51 * @param skipZeroes Whether to skip writing zeroes. Useful if dst is
52 * zero-initialized. The implementation may or may not respect this.
53 * @return A new SkSwizzler or NULL on failure.
54 */
55 static SkSwizzler* CreateSwizzler(SrcConfig sc, const SkPMColor* ctable,
56 const SkImageInfo& info, void* dst,
57 size_t dstRowBytes, bool skipZeroes);
58 /**
59 * Swizzle the next line. Call height times, once for each row of source.
60 * @param src The next row of the source data.
61 * @return Whether the row had non-opaque alpha.
62 */
63 bool next(const uint8_t* SK_RESTRICT src);
64 private:
65 /**
66 * Method for converting raw data to Skia pixels.
67 * @param dstRow Row in which to write the resulting pixels.
68 * @param src Row of src data, in format specified by SrcConfig
69 * @param width Width in pixels
70 * @param bpp bytes per pixel of the source.
71 * @param y Line of source.
72 * @param ctable Colors (used for kIndex source).
73 */
74 typedef bool (*RowProc)(void* SK_RESTRICT dstRow,
75 const uint8_t* SK_RESTRICT src,
76 int width, int bpp, int y,
77 const SkPMColor ctable[]);
78
79 const RowProc fRowProc;
80 const SkPMColor* fColorTable; // Unowned pointer
81 const int fSrcPixelSize;
82 const SkImageInfo fDstInfo;
83 void* fDstRow;
84 const size_t fDstRowBytes;
85 int fCurrY;
86
87 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBpp,
88 const SkImageInfo& info, void* dst, size_t rowBytes);
89
90 };
91 #endif // SkSwizzler_DEFINED
92
OLDNEW
« gyp/codec.gyp ('K') | « src/codec/SkCodec_libpng.cpp ('k') | src/codec/SkSwizzler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698