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

Side by Side Diff: tools/skdiff_utils.cpp

Issue 1788643003: Remove uses of SkImageDecoder from skdiff (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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
« tools/skdiff_main.cpp ('K') | « tools/skdiff_utils.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
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 #include "skdiff.h" 7 #include "skdiff.h"
8 #include "skdiff_utils.h" 8 #include "skdiff_utils.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCodec.h"
10 #include "SkData.h" 11 #include "SkData.h"
11 #include "SkImageDecoder.h"
12 #include "SkImageEncoder.h" 12 #include "SkImageEncoder.h"
13 #include "SkStream.h" 13 #include "SkStream.h"
14 #include "SkTypes.h" 14 #include "SkTypes.h"
15 15
16 #include <memory> 16 #include <memory>
17 17
18 bool are_buffers_equal(SkData* skdata1, SkData* skdata2) { 18 bool are_buffers_equal(SkData* skdata1, SkData* skdata2) {
19 if ((nullptr == skdata1) || (nullptr == skdata2)) { 19 if ((nullptr == skdata1) || (nullptr == skdata2)) {
20 return false; 20 return false;
21 } 21 }
22 if (skdata1->size() != skdata2->size()) { 22 if (skdata1->size() != skdata2->size()) {
23 return false; 23 return false;
24 } 24 }
25 return (0 == memcmp(skdata1->data(), skdata2->data(), skdata1->size())); 25 return (0 == memcmp(skdata1->data(), skdata2->data(), skdata1->size()));
26 } 26 }
27 27
28 SkData* read_file(const char* file_path) { 28 SkData* read_file(const char* file_path) {
29 SkData* data = SkData::NewFromFileName(file_path); 29 SkData* data = SkData::NewFromFileName(file_path);
30 if (!data) { 30 if (!data) {
31 SkDebugf("WARNING: could not open file <%s> for reading\n", file_path); 31 SkDebugf("WARNING: could not open file <%s> for reading\n", file_path);
32 } 32 }
33 return data; 33 return data;
34 } 34 }
35 35
36 bool get_bitmap(SkData* fileBits, DiffResource& resource, SkImageDecoder::Mode m ode) { 36 bool get_bitmap(SkData* fileBits, DiffResource& resource, bool sizeOnly) {
37 SkMemoryStream stream(fileBits->data(), fileBits->size()); 37 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fileBits));
38 38 if (!codec) {
39 // In debug, the DLL will automatically be unloaded when this is deleted, 39 SkDebugf("ERROR: could not create codec for <%s>\n", resource.fFullPath. c_str());
40 // but that shouldn't be a problem in release mode.
41 std::unique_ptr<SkImageDecoder> codec(SkImageDecoder::Factory(&stream));
42 if (nullptr == codec) {
43 SkDebugf("ERROR: no codec found for <%s>\n", resource.fFullPath.c_str()) ;
44 resource.fStatus = DiffResource::kCouldNotDecode_Status; 40 resource.fStatus = DiffResource::kCouldNotDecode_Status;
45 return false; 41 return false;
46 } 42 }
47 43
48 stream.rewind(); 44 if (!resource.fBitmap.setInfo(codec->getInfo().makeColorType(kN32_SkColorTyp e))) {
49 if (!codec->decode(&stream, &resource.fBitmap, kN32_SkColorType, mode)) { 45 SkDebugf("ERROR: could not set bitmap info for <%s>\n", resource.fFullPa th.c_str());
46 resource.fStatus = DiffResource::kCouldNotDecode_Status;
47 return false;
48 }
49
50 if (sizeOnly) {
51 return true;
52 }
53
54 if (!resource.fBitmap.tryAllocPixels()) {
55 SkDebugf("ERROR: could not allocate pixels for <%s>\n", resource.fFullPa th.c_str());
56 resource.fStatus = DiffResource::kCouldNotDecode_Status;
57 return false;
58 }
59
60 if (SkCodec::kSuccess != codec->getPixels(resource.fBitmap.info(),
61 resource.fBitmap.getPixels(), resource.fBitmap.rowBytes())) {
50 SkDebugf("ERROR: codec failed for basePath <%s>\n", resource.fFullPath.c _str()); 62 SkDebugf("ERROR: codec failed for basePath <%s>\n", resource.fFullPath.c _str());
51 resource.fStatus = DiffResource::kCouldNotDecode_Status; 63 resource.fStatus = DiffResource::kCouldNotDecode_Status;
52 return false; 64 return false;
53 } 65 }
54 66
55 resource.fStatus = DiffResource::kDecoded_Status; 67 resource.fStatus = DiffResource::kDecoded_Status;
56 return true; 68 return true;
57 } 69 }
58 70
59 /** Thanks to PNG, we need to force all pixels 100% opaque. */ 71 /** Thanks to PNG, we need to force all pixels 100% opaque. */
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 drp->fDifference.fStatus = DiffResource::kDoesNotExist_Status; 170 drp->fDifference.fStatus = DiffResource::kDoesNotExist_Status;
159 } 171 }
160 if (write_bitmap(drp->fWhite.fFullPath, drp->fWhite.fBitmap)) { 172 if (write_bitmap(drp->fWhite.fFullPath, drp->fWhite.fBitmap)) {
161 drp->fWhite.fStatus = DiffResource::kExists_Status; 173 drp->fWhite.fStatus = DiffResource::kExists_Status;
162 } else { 174 } else {
163 drp->fWhite.fStatus = DiffResource::kDoesNotExist_Status; 175 drp->fWhite.fStatus = DiffResource::kDoesNotExist_Status;
164 } 176 }
165 } 177 }
166 } 178 }
167 } 179 }
OLDNEW
« tools/skdiff_main.cpp ('K') | « tools/skdiff_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698