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" | 14 #include "SkTemplates.h" |
15 #include "SkTypes.h" | 15 #include "SkTypes.h" |
16 | 16 |
17 bool are_buffers_equal(SkData* skdata1, SkData* skdata2) { | 17 bool are_buffers_equal(SkData* skdata1, SkData* skdata2) { |
18 if ((NULL == skdata1) || (NULL == skdata2)) { | 18 if ((NULL == skdata1) || (NULL == skdata2)) { |
19 return false; | 19 return false; |
20 } | 20 } |
21 if (skdata1->size() != skdata2->size()) { | 21 if (skdata1->size() != skdata2->size()) { |
22 return false; | 22 return false; |
23 } | 23 } |
24 return (0 == memcmp(skdata1->data(), skdata2->data(), skdata1->size())); | 24 return (0 == memcmp(skdata1->data(), skdata2->data(), skdata1->size())); |
25 } | 25 } |
26 | 26 |
27 SkData* read_file(const char* file_path) { | 27 SkData* read_file(const char* file_path) { |
28 SkFILEStream fileStream(file_path); | 28 SkData* data = SkData::NewFromFileName(file_path); |
29 if (!fileStream.isValid()) { | 29 if (!data) { |
30 SkDebugf("WARNING: could not open file <%s> for reading\n", file_path); | 30 SkDebugf("WARNING: could not open file <%s> for reading\n", file_path); |
31 return NULL; | |
32 } | 31 } |
33 size_t bytesInFile = fileStream.getLength(); | 32 return data; |
34 size_t bytesLeftToRead = bytesInFile; | |
35 | |
36 void* bufferStart = sk_malloc_throw(bytesInFile); | |
37 char* bufferPointer = (char*)bufferStart; | |
38 while (bytesLeftToRead > 0) { | |
39 size_t bytesReadThisTime = fileStream.read(bufferPointer, bytesLeftToRea
d); | |
40 if (0 == bytesReadThisTime) { | |
41 SkDebugf("WARNING: error reading from <%s>\n", file_path); | |
42 sk_free(bufferStart); | |
43 return NULL; | |
44 } | |
45 bytesLeftToRead -= bytesReadThisTime; | |
46 bufferPointer += bytesReadThisTime; | |
47 } | |
48 return SkData::NewFromMalloc(bufferStart, bytesInFile); | |
49 } | 33 } |
50 | 34 |
51 bool get_bitmap(SkData* fileBits, DiffResource& resource, SkImageDecoder::Mode m
ode) { | 35 bool get_bitmap(SkData* fileBits, DiffResource& resource, SkImageDecoder::Mode m
ode) { |
52 SkMemoryStream stream(fileBits->data(), fileBits->size()); | 36 SkMemoryStream stream(fileBits->data(), fileBits->size()); |
53 | 37 |
54 SkImageDecoder* codec = SkImageDecoder::Factory(&stream); | 38 SkImageDecoder* codec = SkImageDecoder::Factory(&stream); |
55 if (NULL == codec) { | 39 if (NULL == codec) { |
56 SkDebugf("ERROR: no codec found for <%s>\n", resource.fFullPath.c_str())
; | 40 SkDebugf("ERROR: no codec found for <%s>\n", resource.fFullPath.c_str())
; |
57 resource.fStatus = DiffResource::kCouldNotDecode_Status; | 41 resource.fStatus = DiffResource::kCouldNotDecode_Status; |
58 return false; | 42 return false; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 drp->fDifference.fStatus = DiffResource::kDoesNotExist_Status; | 159 drp->fDifference.fStatus = DiffResource::kDoesNotExist_Status; |
176 } | 160 } |
177 if (write_bitmap(drp->fWhite.fFullPath, drp->fWhite.fBitmap)) { | 161 if (write_bitmap(drp->fWhite.fFullPath, drp->fWhite.fBitmap)) { |
178 drp->fWhite.fStatus = DiffResource::kExists_Status; | 162 drp->fWhite.fStatus = DiffResource::kExists_Status; |
179 } else { | 163 } else { |
180 drp->fWhite.fStatus = DiffResource::kDoesNotExist_Status; | 164 drp->fWhite.fStatus = DiffResource::kDoesNotExist_Status; |
181 } | 165 } |
182 } | 166 } |
183 } | 167 } |
184 } | 168 } |
OLD | NEW |