OLD | NEW |
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 "SkData.h" | 10 #include "SkData.h" |
11 #include "SkImageDecoder.h" | 11 #include "SkImageDecoder.h" |
12 #include "SkImageEncoder.h" | 12 #include "SkImageEncoder.h" |
13 #include "SkStream.h" | 13 #include "SkStream.h" |
14 #include "SkTemplates.h" | |
15 #include "SkTypes.h" | 14 #include "SkTypes.h" |
16 | 15 |
| 16 #include <memory> |
| 17 |
17 bool are_buffers_equal(SkData* skdata1, SkData* skdata2) { | 18 bool are_buffers_equal(SkData* skdata1, SkData* skdata2) { |
18 if ((NULL == skdata1) || (NULL == skdata2)) { | 19 if ((NULL == skdata1) || (NULL == skdata2)) { |
19 return false; | 20 return false; |
20 } | 21 } |
21 if (skdata1->size() != skdata2->size()) { | 22 if (skdata1->size() != skdata2->size()) { |
22 return false; | 23 return false; |
23 } | 24 } |
24 return (0 == memcmp(skdata1->data(), skdata2->data(), skdata1->size())); | 25 return (0 == memcmp(skdata1->data(), skdata2->data(), skdata1->size())); |
25 } | 26 } |
26 | 27 |
27 SkData* read_file(const char* file_path) { | 28 SkData* read_file(const char* file_path) { |
28 SkData* data = SkData::NewFromFileName(file_path); | 29 SkData* data = SkData::NewFromFileName(file_path); |
29 if (!data) { | 30 if (!data) { |
30 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); |
31 } | 32 } |
32 return data; | 33 return data; |
33 } | 34 } |
34 | 35 |
35 bool get_bitmap(SkData* fileBits, DiffResource& resource, SkImageDecoder::Mode m
ode) { | 36 bool get_bitmap(SkData* fileBits, DiffResource& resource, SkImageDecoder::Mode m
ode) { |
36 SkMemoryStream stream(fileBits->data(), fileBits->size()); | 37 SkMemoryStream stream(fileBits->data(), fileBits->size()); |
37 | 38 |
38 SkImageDecoder* codec = SkImageDecoder::Factory(&stream); | 39 // In debug, the DLL will automatically be unloaded when this is deleted, |
| 40 // but that shouldn't be a problem in release mode. |
| 41 std::unique_ptr<SkImageDecoder> codec(SkImageDecoder::Factory(&stream)); |
39 if (NULL == codec) { | 42 if (NULL == codec) { |
40 SkDebugf("ERROR: no codec found for <%s>\n", resource.fFullPath.c_str())
; | 43 SkDebugf("ERROR: no codec found for <%s>\n", resource.fFullPath.c_str())
; |
41 resource.fStatus = DiffResource::kCouldNotDecode_Status; | 44 resource.fStatus = DiffResource::kCouldNotDecode_Status; |
42 return false; | 45 return false; |
43 } | 46 } |
44 | 47 |
45 // In debug, the DLL will automatically be unloaded when this is deleted, | |
46 // but that shouldn't be a problem in release mode. | |
47 SkAutoTDelete<SkImageDecoder> ad(codec); | |
48 | |
49 stream.rewind(); | 48 stream.rewind(); |
50 if (!codec->decode(&stream, &resource.fBitmap, kN32_SkColorType, mode)) { | 49 if (!codec->decode(&stream, &resource.fBitmap, kN32_SkColorType, mode)) { |
51 SkDebugf("ERROR: codec failed for basePath <%s>\n", resource.fFullPath.c
_str()); | 50 SkDebugf("ERROR: codec failed for basePath <%s>\n", resource.fFullPath.c
_str()); |
52 resource.fStatus = DiffResource::kCouldNotDecode_Status; | 51 resource.fStatus = DiffResource::kCouldNotDecode_Status; |
53 return false; | 52 return false; |
54 } | 53 } |
55 | 54 |
56 resource.fStatus = DiffResource::kDecoded_Status; | 55 resource.fStatus = DiffResource::kDecoded_Status; |
57 return true; | 56 return true; |
58 } | 57 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 drp->fDifference.fStatus = DiffResource::kDoesNotExist_Status; | 158 drp->fDifference.fStatus = DiffResource::kDoesNotExist_Status; |
160 } | 159 } |
161 if (write_bitmap(drp->fWhite.fFullPath, drp->fWhite.fBitmap)) { | 160 if (write_bitmap(drp->fWhite.fFullPath, drp->fWhite.fBitmap)) { |
162 drp->fWhite.fStatus = DiffResource::kExists_Status; | 161 drp->fWhite.fStatus = DiffResource::kExists_Status; |
163 } else { | 162 } else { |
164 drp->fWhite.fStatus = DiffResource::kDoesNotExist_Status; | 163 drp->fWhite.fStatus = DiffResource::kDoesNotExist_Status; |
165 } | 164 } |
166 } | 165 } |
167 } | 166 } |
168 } | 167 } |
OLD | NEW |