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

Side by Side Diff: src/images/SkImageDecoder_libwebp.cpp

Issue 888703002: SkStream::read() only returns 0 at end. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 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 | « no previous file | no next file » | 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 2010, The Android Open Source Project 2 * Copyright 2010, The Android Open Source Project
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.0 8 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 // Parse headers of RIFF container, and check for valid Webp (VP8) content. 53 // Parse headers of RIFF container, and check for valid Webp (VP8) content.
54 static bool webp_parse_header(SkStream* stream, int* width, int* height, int* al pha) { 54 static bool webp_parse_header(SkStream* stream, int* width, int* height, int* al pha) {
55 unsigned char buffer[WEBP_VP8_HEADER_SIZE]; 55 unsigned char buffer[WEBP_VP8_HEADER_SIZE];
56 size_t bytesToRead = WEBP_VP8_HEADER_SIZE; 56 size_t bytesToRead = WEBP_VP8_HEADER_SIZE;
57 size_t totalBytesRead = 0; 57 size_t totalBytesRead = 0;
58 do { 58 do {
59 unsigned char* dst = buffer + totalBytesRead; 59 unsigned char* dst = buffer + totalBytesRead;
60 const size_t bytesRead = stream->read(dst, bytesToRead); 60 const size_t bytesRead = stream->read(dst, bytesToRead);
61 if (0 == bytesRead) { 61 if (0 == bytesRead) {
62 // Could not read any bytes. Check to see if we are at the end (exit 62 SkASSERT(stream->isAtEnd());
63 // condition), and continue reading if not. Important for streams 63 break;
64 // that do not have all the data ready.
65 continue;
66 } 64 }
67 bytesToRead -= bytesRead; 65 bytesToRead -= bytesRead;
68 totalBytesRead += bytesRead; 66 totalBytesRead += bytesRead;
69 SkASSERT(bytesToRead + totalBytesRead == WEBP_VP8_HEADER_SIZE); 67 SkASSERT(bytesToRead + totalBytesRead == WEBP_VP8_HEADER_SIZE);
70 } while (!stream->isAtEnd() && bytesToRead > 0); 68 } while (!stream->isAtEnd() && bytesToRead > 0);
71 69
72 WebPBitstreamFeatures features; 70 WebPBitstreamFeatures features;
73 VP8StatusCode status = WebPGetFeatures(buffer, totalBytesRead, &features); 71 VP8StatusCode status = WebPGetFeatures(buffer, totalBytesRead, &features);
74 if (VP8_STATUS_OK != status) { 72 if (VP8_STATUS_OK != status) {
75 return false; // Invalid WebP file. 73 return false; // Invalid WebP file.
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 return SkImageDecoder::kUnknown_Format; 668 return SkImageDecoder::kUnknown_Format;
671 } 669 }
672 670
673 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { 671 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) {
674 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL L; 672 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL L;
675 } 673 }
676 674
677 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory); 675 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory);
678 static SkImageDecoder_FormatReg gFormatReg(get_format_webp); 676 static SkImageDecoder_FormatReg gFormatReg(get_format_webp);
679 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory); 677 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698