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

Side by Side Diff: src/codec/SkCodec_libico.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 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
« no previous file with comments | « src/codec/SkCodec_libgif.cpp ('k') | src/codec/SkCodec_libpng.cpp » ('j') | 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 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 "SkBmpCodec.h" 8 #include "SkBmpCodec.h"
9 #include "SkCodec_libico.h" 9 #include "SkCodec_libico.h"
10 #include "SkCodec_libpng.h" 10 #include "SkCodec_libpng.h"
(...skipping 27 matching lines...) Expand all
38 38
39 // Header size constants 39 // Header size constants
40 static const uint32_t kIcoDirectoryBytes = 6; 40 static const uint32_t kIcoDirectoryBytes = 6;
41 static const uint32_t kIcoDirEntryBytes = 16; 41 static const uint32_t kIcoDirEntryBytes = 16;
42 42
43 // Read the directory header 43 // Read the directory header
44 SkAutoTDeleteArray<uint8_t> dirBuffer(new uint8_t[kIcoDirectoryBytes]); 44 SkAutoTDeleteArray<uint8_t> dirBuffer(new uint8_t[kIcoDirectoryBytes]);
45 if (inputStream.get()->read(dirBuffer.get(), kIcoDirectoryBytes) != 45 if (inputStream.get()->read(dirBuffer.get(), kIcoDirectoryBytes) !=
46 kIcoDirectoryBytes) { 46 kIcoDirectoryBytes) {
47 SkCodecPrintf("Error: unable to read ico directory header.\n"); 47 SkCodecPrintf("Error: unable to read ico directory header.\n");
48 return NULL; 48 return nullptr;
49 } 49 }
50 50
51 // Process the directory header 51 // Process the directory header
52 const uint16_t numImages = get_short(dirBuffer.get(), 4); 52 const uint16_t numImages = get_short(dirBuffer.get(), 4);
53 if (0 == numImages) { 53 if (0 == numImages) {
54 SkCodecPrintf("Error: No images embedded in ico.\n"); 54 SkCodecPrintf("Error: No images embedded in ico.\n");
55 return NULL; 55 return nullptr;
56 } 56 }
57 57
58 // Ensure that we can read all of indicated directory entries 58 // Ensure that we can read all of indicated directory entries
59 SkAutoTDeleteArray<uint8_t> entryBuffer(new uint8_t[numImages * kIcoDirEntry Bytes]); 59 SkAutoTDeleteArray<uint8_t> entryBuffer(new uint8_t[numImages * kIcoDirEntry Bytes]);
60 if (inputStream.get()->read(entryBuffer.get(), numImages*kIcoDirEntryBytes) != 60 if (inputStream.get()->read(entryBuffer.get(), numImages*kIcoDirEntryBytes) !=
61 numImages*kIcoDirEntryBytes) { 61 numImages*kIcoDirEntryBytes) {
62 SkCodecPrintf("Error: unable to read ico directory entries.\n"); 62 SkCodecPrintf("Error: unable to read ico directory entries.\n");
63 return NULL; 63 return nullptr;
64 } 64 }
65 65
66 // This structure is used to represent the vital information about entries 66 // This structure is used to represent the vital information about entries
67 // in the directory header. We will obtain this information for each 67 // in the directory header. We will obtain this information for each
68 // directory entry. 68 // directory entry.
69 struct Entry { 69 struct Entry {
70 uint32_t offset; 70 uint32_t offset;
71 uint32_t size; 71 uint32_t size;
72 }; 72 };
73 SkAutoTDeleteArray<Entry> directoryEntries(new Entry[numImages]); 73 SkAutoTDeleteArray<Entry> directoryEntries(new Entry[numImages]);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // stop trying to make codecs 124 // stop trying to make codecs
125 if (inputStream.get()->skip(offset - bytesRead) != offset - bytesRead) { 125 if (inputStream.get()->skip(offset - bytesRead) != offset - bytesRead) {
126 SkCodecPrintf("Warning: could not skip to ico offset.\n"); 126 SkCodecPrintf("Warning: could not skip to ico offset.\n");
127 break; 127 break;
128 } 128 }
129 bytesRead = offset; 129 bytesRead = offset;
130 130
131 // Create a new stream for the embedded codec 131 // Create a new stream for the embedded codec
132 SkAutoTUnref<SkData> data( 132 SkAutoTUnref<SkData> data(
133 SkData::NewFromStream(inputStream.get(), size)); 133 SkData::NewFromStream(inputStream.get(), size));
134 if (NULL == data.get()) { 134 if (nullptr == data.get()) {
135 SkCodecPrintf("Warning: could not create embedded stream.\n"); 135 SkCodecPrintf("Warning: could not create embedded stream.\n");
136 break; 136 break;
137 } 137 }
138 SkAutoTDelete<SkMemoryStream> embeddedStream(new SkMemoryStream(data.get ())); 138 SkAutoTDelete<SkMemoryStream> embeddedStream(new SkMemoryStream(data.get ()));
139 bytesRead += size; 139 bytesRead += size;
140 140
141 // Check if the embedded codec is bmp or png and create the codec 141 // Check if the embedded codec is bmp or png and create the codec
142 const bool isPng = SkPngCodec::IsPng(embeddedStream); 142 const bool isPng = SkPngCodec::IsPng(embeddedStream);
143 SkAssertResult(embeddedStream->rewind()); 143 SkAssertResult(embeddedStream->rewind());
144 SkCodec* codec = NULL; 144 SkCodec* codec = nullptr;
145 if (isPng) { 145 if (isPng) {
146 codec = SkPngCodec::NewFromStream(embeddedStream.detach()); 146 codec = SkPngCodec::NewFromStream(embeddedStream.detach());
147 } else { 147 } else {
148 codec = SkBmpCodec::NewFromIco(embeddedStream.detach()); 148 codec = SkBmpCodec::NewFromIco(embeddedStream.detach());
149 } 149 }
150 150
151 // Save a valid codec 151 // Save a valid codec
152 if (NULL != codec) { 152 if (nullptr != codec) {
153 codecs->push_back().reset(codec); 153 codecs->push_back().reset(codec);
154 } 154 }
155 } 155 }
156 156
157 // Recognize if there are no valid codecs 157 // Recognize if there are no valid codecs
158 if (0 == codecs->count()) { 158 if (0 == codecs->count()) {
159 SkCodecPrintf("Error: could not find any valid embedded ico codecs.\n"); 159 SkCodecPrintf("Error: could not find any valid embedded ico codecs.\n");
160 return NULL; 160 return nullptr;
161 } 161 }
162 162
163 // Use the largest codec as a "suggestion" for image info 163 // Use the largest codec as a "suggestion" for image info
164 uint32_t maxSize = 0; 164 uint32_t maxSize = 0;
165 uint32_t maxIndex = 0; 165 uint32_t maxIndex = 0;
166 for (int32_t i = 0; i < codecs->count(); i++) { 166 for (int32_t i = 0; i < codecs->count(); i++) {
167 SkImageInfo info = codecs->operator[](i)->getInfo(); 167 SkImageInfo info = codecs->operator[](i)->getInfo();
168 uint32_t size = info.width() * info.height(); 168 uint32_t size = info.width() * info.height();
169 if (size > maxSize) { 169 if (size > maxSize) {
170 maxSize = size; 170 maxSize = size;
(...skipping 17 matching lines...) Expand all
188 // direct access to the stream. 188 // direct access to the stream.
189 return new SkIcoCodec(info, codecs.detach()); 189 return new SkIcoCodec(info, codecs.detach());
190 } 190 }
191 191
192 /* 192 /*
193 * Creates an instance of the decoder 193 * Creates an instance of the decoder
194 * Called only by NewFromStream 194 * Called only by NewFromStream
195 */ 195 */
196 SkIcoCodec::SkIcoCodec(const SkImageInfo& info, 196 SkIcoCodec::SkIcoCodec(const SkImageInfo& info,
197 SkTArray<SkAutoTDelete<SkCodec>, true>* codecs) 197 SkTArray<SkAutoTDelete<SkCodec>, true>* codecs)
198 : INHERITED(info, NULL) 198 : INHERITED(info, nullptr)
199 , fEmbeddedCodecs(codecs) 199 , fEmbeddedCodecs(codecs)
200 {} 200 {}
201 201
202 /* 202 /*
203 * Chooses the best dimensions given the desired scale 203 * Chooses the best dimensions given the desired scale
204 */ 204 */
205 SkISize SkIcoCodec::onGetScaledDimensions(float desiredScale) const { 205 SkISize SkIcoCodec::onGetScaledDimensions(float desiredScale) const {
206 // We set the dimensions to the largest candidate image by default. 206 // We set the dimensions to the largest candidate image by default.
207 // Regardless of the scale request, this is the largest image that we 207 // Regardless of the scale request, this is the largest image that we
208 // will decode. 208 // will decode.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 268 }
269 269
270 // On success or partial success, return the result 270 // On success or partial success, return the result
271 return result; 271 return result;
272 } 272 }
273 } 273 }
274 274
275 SkCodecPrintf("Error: No matching candidate image in ico.\n"); 275 SkCodecPrintf("Error: No matching candidate image in ico.\n");
276 return result; 276 return result;
277 } 277 }
OLDNEW
« no previous file with comments | « src/codec/SkCodec_libgif.cpp ('k') | src/codec/SkCodec_libpng.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698