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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp

Issue 1812273003: Eliminate copies of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 14 matching lines...) Expand all
25 #include "platform/image-decoders/bmp/BMPImageDecoder.h" 25 #include "platform/image-decoders/bmp/BMPImageDecoder.h"
26 #include "platform/image-decoders/gif/GIFImageDecoder.h" 26 #include "platform/image-decoders/gif/GIFImageDecoder.h"
27 #include "platform/image-decoders/ico/ICOImageDecoder.h" 27 #include "platform/image-decoders/ico/ICOImageDecoder.h"
28 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h" 28 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h"
29 #include "platform/image-decoders/png/PNGImageDecoder.h" 29 #include "platform/image-decoders/png/PNGImageDecoder.h"
30 #include "platform/image-decoders/webp/WEBPImageDecoder.h" 30 #include "platform/image-decoders/webp/WEBPImageDecoder.h"
31 #include "wtf/PassOwnPtr.h" 31 #include "wtf/PassOwnPtr.h"
32 32
33 namespace blink { 33 namespace blink {
34 34
35 static unsigned copyFromSharedBuffer(char* buffer, unsigned bufferLength, const SharedBuffer& sharedBuffer, unsigned offset) 35 inline bool matchesJPEGSignature(const char* contents)
36 {
37 unsigned bytesExtracted = 0;
38 const char* moreData;
39 while (unsigned moreDataLength = sharedBuffer.getSomeData(moreData, offset)) {
40 unsigned bytesToCopy = std::min(bufferLength - bytesExtracted, moreDataL ength);
41 memcpy(buffer + bytesExtracted, moreData, bytesToCopy);
42 bytesExtracted += bytesToCopy;
43 if (bytesExtracted == bufferLength)
44 break;
45 offset += bytesToCopy;
46 }
47 return bytesExtracted;
48 }
49
50 inline bool matchesJPEGSignature(char* contents)
51 { 36 {
52 return !memcmp(contents, "\xFF\xD8\xFF", 3); 37 return !memcmp(contents, "\xFF\xD8\xFF", 3);
53 } 38 }
54 39
55 inline bool matchesPNGSignature(char* contents) 40 inline bool matchesPNGSignature(const char* contents)
56 { 41 {
57 return !memcmp(contents, "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", 8); 42 return !memcmp(contents, "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", 8);
58 } 43 }
59 44
60 inline bool matchesGIFSignature(char* contents) 45 inline bool matchesGIFSignature(const char* contents)
61 { 46 {
62 return !memcmp(contents, "GIF87a", 6) || !memcmp(contents, "GIF89a", 6); 47 return !memcmp(contents, "GIF87a", 6) || !memcmp(contents, "GIF89a", 6);
63 } 48 }
64 49
65 inline bool matchesWebPSignature(char* contents) 50 inline bool matchesWebPSignature(const char* contents)
66 { 51 {
67 return !memcmp(contents, "RIFF", 4) && !memcmp(contents + 8, "WEBPVP", 6); 52 return !memcmp(contents, "RIFF", 4) && !memcmp(contents + 8, "WEBPVP", 6);
68 } 53 }
69 54
70 inline bool matchesICOSignature(char* contents) 55 inline bool matchesICOSignature(const char* contents)
71 { 56 {
72 return !memcmp(contents, "\x00\x00\x01\x00", 4); 57 return !memcmp(contents, "\x00\x00\x01\x00", 4);
73 } 58 }
74 59
75 inline bool matchesCURSignature(char* contents) 60 inline bool matchesCURSignature(const char* contents)
76 { 61 {
77 return !memcmp(contents, "\x00\x00\x02\x00", 4); 62 return !memcmp(contents, "\x00\x00\x02\x00", 4);
78 } 63 }
79 64
80 inline bool matchesBMPSignature(char* contents) 65 inline bool matchesBMPSignature(const char* contents)
81 { 66 {
82 return !memcmp(contents, "BM", 2); 67 return !memcmp(contents, "BM", 2);
83 } 68 }
84 69
85 PassOwnPtr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, AlphaOpt ion alphaOption, GammaAndColorProfileOption colorOptions) 70 PassOwnPtr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, AlphaOp tion alphaOption, GammaAndColorProfileOption colorOptions)
86 { 71 {
87 const unsigned longestSignatureLength = sizeof("RIFF????WEBPVP") - 1; 72 const unsigned longestSignatureLength = sizeof("RIFF????WEBPVP") - 1;
88 ASSERT(longestSignatureLength == 14); 73 ASSERT(longestSignatureLength == 14);
89 74
90 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod edImageBytes() : noDecodedImageByteLimit; 75 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod edImageBytes() : noDecodedImageByteLimit;
91 76
92 char contents[longestSignatureLength]; 77 // No implementation of SegmentReader will return less than 14 bytes from a read from the beginning, unless there is no more data.
Peter Kasting 2016/03/23 02:42:58 Does this comment matter? It looks like we check
scroggo_chromium 2016/03/24 13:59:45 Removed.
93 if (copyFromSharedBuffer(contents, longestSignatureLength, data, 0) < longes tSignatureLength) 78 const char* contents;
79 if (data.getSomeData(contents, 0) < longestSignatureLength)
94 return nullptr; 80 return nullptr;
95 81
96 if (matchesJPEGSignature(contents)) 82 if (matchesJPEGSignature(contents))
97 return adoptPtr(new JPEGImageDecoder(alphaOption, colorOptions, maxDecod edBytes)); 83 return adoptPtr(new JPEGImageDecoder(alphaOption, colorOptions, maxDecod edBytes));
98 84
99 if (matchesPNGSignature(contents)) 85 if (matchesPNGSignature(contents))
100 return adoptPtr(new PNGImageDecoder(alphaOption, colorOptions, maxDecode dBytes)); 86 return adoptPtr(new PNGImageDecoder(alphaOption, colorOptions, maxDecode dBytes));
101 87
102 if (matchesGIFSignature(contents)) 88 if (matchesGIFSignature(contents))
103 return adoptPtr(new GIFImageDecoder(alphaOption, colorOptions, maxDecode dBytes)); 89 return adoptPtr(new GIFImageDecoder(alphaOption, colorOptions, maxDecode dBytes));
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 return m_planes[i]; 251 return m_planes[i];
266 } 252 }
267 253
268 size_t ImagePlanes::rowBytes(int i) const 254 size_t ImagePlanes::rowBytes(int i) const
269 { 255 {
270 ASSERT((i >= 0) && i < 3); 256 ASSERT((i >= 0) && i < 3);
271 return m_rowBytes[i]; 257 return m_rowBytes[i];
272 } 258 }
273 259
274 } // namespace blink 260 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698