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

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

Issue 1866243003: Revert of Eliminate copies of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 inline bool matchesJPEGSignature(const char* contents) 35 static size_t copyFromSharedBuffer(char* buffer, size_t bufferLength, const Shar edBuffer& sharedBuffer, size_t offset)
36 {
37 size_t bytesExtracted = 0;
38 const char* moreData;
39 while (size_t moreDataLength = sharedBuffer.getSomeData(moreData, offset)) {
40 size_t bytesToCopy = std::min(bufferLength - bytesExtracted, moreDataLen gth);
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)
36 { 51 {
37 return !memcmp(contents, "\xFF\xD8\xFF", 3); 52 return !memcmp(contents, "\xFF\xD8\xFF", 3);
38 } 53 }
39 54
40 inline bool matchesPNGSignature(const char* contents) 55 inline bool matchesPNGSignature(char* contents)
41 { 56 {
42 return !memcmp(contents, "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", 8); 57 return !memcmp(contents, "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", 8);
43 } 58 }
44 59
45 inline bool matchesGIFSignature(const char* contents) 60 inline bool matchesGIFSignature(char* contents)
46 { 61 {
47 return !memcmp(contents, "GIF87a", 6) || !memcmp(contents, "GIF89a", 6); 62 return !memcmp(contents, "GIF87a", 6) || !memcmp(contents, "GIF89a", 6);
48 } 63 }
49 64
50 inline bool matchesWebPSignature(const char* contents) 65 inline bool matchesWebPSignature(char* contents)
51 { 66 {
52 return !memcmp(contents, "RIFF", 4) && !memcmp(contents + 8, "WEBPVP", 6); 67 return !memcmp(contents, "RIFF", 4) && !memcmp(contents + 8, "WEBPVP", 6);
53 } 68 }
54 69
55 inline bool matchesICOSignature(const char* contents) 70 inline bool matchesICOSignature(char* contents)
56 { 71 {
57 return !memcmp(contents, "\x00\x00\x01\x00", 4); 72 return !memcmp(contents, "\x00\x00\x01\x00", 4);
58 } 73 }
59 74
60 inline bool matchesCURSignature(const char* contents) 75 inline bool matchesCURSignature(char* contents)
61 { 76 {
62 return !memcmp(contents, "\x00\x00\x02\x00", 4); 77 return !memcmp(contents, "\x00\x00\x02\x00", 4);
63 } 78 }
64 79
65 inline bool matchesBMPSignature(const char* contents) 80 inline bool matchesBMPSignature(char* contents)
66 { 81 {
67 return !memcmp(contents, "BM", 2); 82 return !memcmp(contents, "BM", 2);
68 } 83 }
69 84
70 PassOwnPtr<ImageDecoder> ImageDecoder::create(const char* contents, size_t lengt h, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions) 85 PassOwnPtr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, AlphaOpt ion alphaOption, GammaAndColorProfileOption colorOptions)
71 { 86 {
72 const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1; 87 const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1;
73 ASSERT(longestSignatureLength == 14); 88 ASSERT(longestSignatureLength == 14);
74 89
75 if (length < longestSignatureLength) 90 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod edImageBytes() : noDecodedImageByteLimit;
91
92 char contents[longestSignatureLength];
93 if (copyFromSharedBuffer(contents, longestSignatureLength, data, 0) < longes tSignatureLength)
76 return nullptr; 94 return nullptr;
77 95
78 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod edImageBytes() : noDecodedImageByteLimit;
79
80 if (matchesJPEGSignature(contents)) 96 if (matchesJPEGSignature(contents))
81 return adoptPtr(new JPEGImageDecoder(alphaOption, colorOptions, maxDecod edBytes)); 97 return adoptPtr(new JPEGImageDecoder(alphaOption, colorOptions, maxDecod edBytes));
82 98
83 if (matchesPNGSignature(contents)) 99 if (matchesPNGSignature(contents))
84 return adoptPtr(new PNGImageDecoder(alphaOption, colorOptions, maxDecode dBytes)); 100 return adoptPtr(new PNGImageDecoder(alphaOption, colorOptions, maxDecode dBytes));
85 101
86 if (matchesGIFSignature(contents)) 102 if (matchesGIFSignature(contents))
87 return adoptPtr(new GIFImageDecoder(alphaOption, colorOptions, maxDecode dBytes)); 103 return adoptPtr(new GIFImageDecoder(alphaOption, colorOptions, maxDecode dBytes));
88 104
89 if (matchesWebPSignature(contents)) 105 if (matchesWebPSignature(contents))
90 return adoptPtr(new WEBPImageDecoder(alphaOption, colorOptions, maxDecod edBytes)); 106 return adoptPtr(new WEBPImageDecoder(alphaOption, colorOptions, maxDecod edBytes));
91 107
92 if (matchesICOSignature(contents) || matchesCURSignature(contents)) 108 if (matchesICOSignature(contents) || matchesCURSignature(contents))
93 return adoptPtr(new ICOImageDecoder(alphaOption, colorOptions, maxDecode dBytes)); 109 return adoptPtr(new ICOImageDecoder(alphaOption, colorOptions, maxDecode dBytes));
94 110
95 if (matchesBMPSignature(contents)) 111 if (matchesBMPSignature(contents))
96 return adoptPtr(new BMPImageDecoder(alphaOption, colorOptions, maxDecode dBytes)); 112 return adoptPtr(new BMPImageDecoder(alphaOption, colorOptions, maxDecode dBytes));
97 113
98 return nullptr; 114 return nullptr;
99 } 115 }
100 116
101 PassOwnPtr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, AlphaOpt ion alphaOption, GammaAndColorProfileOption colorOptions)
102 {
103 const char* contents;
104 const size_t length = data.getSomeData<size_t>(contents);
105 return create(contents, length, alphaOption, colorOptions);
106 }
107
108 PassOwnPtr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, AlphaOp tion alphaOption, GammaAndColorProfileOption colorOptions)
109 {
110 const char* contents;
111 const size_t length = data.getSomeData(contents, 0);
112 return create(contents, length, alphaOption, colorOptions);
113 }
114
115 size_t ImageDecoder::frameCount() 117 size_t ImageDecoder::frameCount()
116 { 118 {
117 const size_t oldSize = m_frameBufferCache.size(); 119 const size_t oldSize = m_frameBufferCache.size();
118 const size_t newSize = decodeFrameCount(); 120 const size_t newSize = decodeFrameCount();
119 if (oldSize != newSize) { 121 if (oldSize != newSize) {
120 m_frameBufferCache.resize(newSize); 122 m_frameBufferCache.resize(newSize);
121 for (size_t i = oldSize; i < newSize; ++i) { 123 for (size_t i = oldSize; i < newSize; ++i) {
122 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha); 124 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha);
123 initializeNewFrame(i); 125 initializeNewFrame(i);
124 } 126 }
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 358
357 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; 359 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8;
358 360
359 // FIXME: Don't force perceptual intent if the image profile contains an int ent. 361 // FIXME: Don't force perceptual intent if the image profile contains an int ent.
360 m_sourceToOutputDeviceColorTransform = adoptPtr(qcms_transform_create(inputP rofile.get(), dataFormat, gOutputDeviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PE RCEPTUAL)); 362 m_sourceToOutputDeviceColorTransform = adoptPtr(qcms_transform_create(inputP rofile.get(), dataFormat, gOutputDeviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PE RCEPTUAL));
361 } 363 }
362 364
363 #endif // USE(QCMSLIB) 365 #endif // USE(QCMSLIB)
364 366
365 } // namespace blink 367 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698