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

Side by Side Diff: src/image/SkImage.cpp

Issue 15314004: Move SkImage::encode to SkImage_Codec.cpp. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « gyp/tools.gyp ('k') | src/image/SkImage_Codec.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkImage_Base.h" 8 #include "SkImage_Base.h"
9 #include "SkImagePriv.h" 9 #include "SkImagePriv.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "../images/SkImageEncoder.h"
13 12
14 SK_DEFINE_INST_COUNT(SkImage) 13 SK_DEFINE_INST_COUNT(SkImage)
15 14
16 static SkImage_Base* asIB(SkImage* image) { 15 static SkImage_Base* asIB(SkImage* image) {
17 return static_cast<SkImage_Base*>(image); 16 return static_cast<SkImage_Base*>(image);
18 } 17 }
19 18
20 static const SkImage_Base* asIB(const SkImage* image) {
21 return static_cast<const SkImage_Base*>(image);
22 }
23
24 uint32_t SkImage::NextUniqueID() { 19 uint32_t SkImage::NextUniqueID() {
25 static int32_t gUniqueID; 20 static int32_t gUniqueID;
26 21
27 // never return 0; 22 // never return 0;
28 uint32_t id; 23 uint32_t id;
29 do { 24 do {
30 id = sk_atomic_inc(&gUniqueID) + 1; 25 id = sk_atomic_inc(&gUniqueID) + 1;
31 } while (0 == id); 26 } while (0 == id);
32 return id; 27 return id;
33 } 28 }
34 29
35 void SkImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y, 30 void SkImage::draw(SkCanvas* canvas, SkScalar x, SkScalar y,
36 const SkPaint* paint) { 31 const SkPaint* paint) {
37 asIB(this)->onDraw(canvas, x, y, paint); 32 asIB(this)->onDraw(canvas, x, y, paint);
38 } 33 }
39 34
40 GrTexture* SkImage::getTexture() { 35 GrTexture* SkImage::getTexture() {
41 return asIB(this)->onGetTexture(); 36 return asIB(this)->onGetTexture();
42 } 37 }
43 38
44 static const struct {
45 SkImageEncoder::Type fIE;
46 SkImage::EncodeType fET;
47 } gTable[] = {
48 { SkImageEncoder::kBMP_Type, SkImage::kBMP_EncodeType },
49 { SkImageEncoder::kGIF_Type, SkImage::kGIF_EncodeType },
50 { SkImageEncoder::kICO_Type, SkImage::kICO_EncodeType },
51 { SkImageEncoder::kJPEG_Type, SkImage::kJPEG_EncodeType },
52 { SkImageEncoder::kPNG_Type, SkImage::kPNG_EncodeType },
53 { SkImageEncoder::kWBMP_Type, SkImage::kWBMP_EncodeType },
54 { SkImageEncoder::kWEBP_Type, SkImage::kWEBP_EncodeType },
55 };
56 39
57 SkData* SkImage::encode(EncodeType et, int quality) const {
58 for (size_t i = 0; i < SK_ARRAY_COUNT(gTable); ++i) {
59 if (gTable[i].fET == et) {
60 SkBitmap bm;
61 if (asIB(this)->getROPixels(&bm)) {
62 return SkImageEncoder::EncodeData(bm, gTable[i].fIE, quality);
63 }
64 break;
65 }
66 }
67 return NULL;
68 }
OLDNEW
« no previous file with comments | « gyp/tools.gyp ('k') | src/image/SkImage_Codec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698