| 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 "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 ((NULL == skdata1) || (NULL == 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, SkImageDecoder::Mode m
ode) { |
| 37 SkMemoryStream stream(fileBits->data(), fileBits->size()); | 37 SkMemoryStream stream(fileBits->data(), fileBits->size()); |
| 38 | 38 |
| 39 // In debug, the DLL will automatically be unloaded when this is deleted, | 39 // In debug, the DLL will automatically be unloaded when this is deleted, |
| 40 // but that shouldn't be a problem in release mode. | 40 // but that shouldn't be a problem in release mode. |
| 41 std::unique_ptr<SkImageDecoder> codec(SkImageDecoder::Factory(&stream)); | 41 std::unique_ptr<SkImageDecoder> codec(SkImageDecoder::Factory(&stream)); |
| 42 if (NULL == codec) { | 42 if (nullptr == codec) { |
| 43 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())
; |
| 44 resource.fStatus = DiffResource::kCouldNotDecode_Status; | 44 resource.fStatus = DiffResource::kCouldNotDecode_Status; |
| 45 return false; | 45 return false; |
| 46 } | 46 } |
| 47 | 47 |
| 48 stream.rewind(); | 48 stream.rewind(); |
| 49 if (!codec->decode(&stream, &resource.fBitmap, kN32_SkColorType, mode)) { | 49 if (!codec->decode(&stream, &resource.fBitmap, kN32_SkColorType, mode)) { |
| 50 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()); |
| 51 resource.fStatus = DiffResource::kCouldNotDecode_Status; | 51 resource.fStatus = DiffResource::kCouldNotDecode_Status; |
| 52 return false; | 52 return false; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 drp->fDifference.fStatus = DiffResource::kDoesNotExist_Status; | 158 drp->fDifference.fStatus = DiffResource::kDoesNotExist_Status; |
| 159 } | 159 } |
| 160 if (write_bitmap(drp->fWhite.fFullPath, drp->fWhite.fBitmap)) { | 160 if (write_bitmap(drp->fWhite.fFullPath, drp->fWhite.fBitmap)) { |
| 161 drp->fWhite.fStatus = DiffResource::kExists_Status; | 161 drp->fWhite.fStatus = DiffResource::kExists_Status; |
| 162 } else { | 162 } else { |
| 163 drp->fWhite.fStatus = DiffResource::kDoesNotExist_Status; | 163 drp->fWhite.fStatus = DiffResource::kDoesNotExist_Status; |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 } | 167 } |
| OLD | NEW |