| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkData.h" | 8 #include "SkData.h" |
| 9 #include "SkJpegInfo.h" | 9 #include "SkJpegInfo.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 class JpegSegment { | 12 class JpegSegment { |
| 13 public: | 13 public: |
| 14 JpegSegment(const SkData* skdata) | 14 JpegSegment(const SkData* skdata) |
| 15 : fData(static_cast<const char*>(skdata->data())) | 15 : fData(static_cast<const char*>(skdata->data())) |
| 16 , fSize(skdata->size()) | 16 , fSize(skdata->size()) |
| 17 , fOffset(0) | 17 , fOffset(0) |
| 18 , fLength(0) {} | 18 , fLength(0) {} |
| 19 bool read() { | 19 bool read() { |
| 20 if (!this->readBigendianUint16(&fMarker)) { | 20 if (!this->readBigendianUint16(&fMarker)) { |
| 21 return false; | 21 return false; |
| 22 } | 22 } |
| 23 if (JpegSegment::StandAloneMarker(fMarker)) { | 23 if (JpegSegment::StandAloneMarker(fMarker)) { |
| 24 fLength = 0; | 24 fLength = 0; |
| 25 fBuffer = NULL; | 25 fBuffer = nullptr; |
| 26 return true; | 26 return true; |
| 27 } | 27 } |
| 28 if (!this->readBigendianUint16(&fLength) || fLength < 2) { | 28 if (!this->readBigendianUint16(&fLength) || fLength < 2) { |
| 29 return false; | 29 return false; |
| 30 } | 30 } |
| 31 fLength -= 2; // Length includes itself for some reason. | 31 fLength -= 2; // Length includes itself for some reason. |
| 32 if (fOffset + fLength > fSize) { | 32 if (fOffset + fLength > fSize) { |
| 33 return false; // Segment too long. | 33 return false; // Segment too long. |
| 34 } | 34 } |
| 35 fBuffer = &fData[fOffset]; | 35 fBuffer = &fData[fOffset]; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 if (numberOfComponents == 3) { | 112 if (numberOfComponents == 3) { |
| 113 info->fType = SkJFIFInfo::kYCbCr; | 113 info->fType = SkJFIFInfo::kYCbCr; |
| 114 } else { | 114 } else { |
| 115 info->fType = SkJFIFInfo::kGrayscale; | 115 info->fType = SkJFIFInfo::kGrayscale; |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 return true; | 118 return true; |
| 119 } | 119 } |
| 120 | 120 |
| 121 | 121 |
| OLD | NEW |