OLD | NEW |
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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 * | 18 * |
19 */ | 19 */ |
20 | 20 |
21 #include "platform/image-decoders/ImageDecoder.h" | 21 #include "platform/image-decoders/ImageDecoder.h" |
22 | 22 |
23 #include "platform/PlatformInstrumentation.h" | 23 #include "platform/PlatformInstrumentation.h" |
24 #include "platform/image-decoders/bmp/BMPImageDecoder.h" | 24 #include "platform/image-decoders/bmp/BMPImageDecoder.h" |
25 #include "platform/image-decoders/gif/GIFImageDecoder.h" | 25 #include "platform/image-decoders/gif/GIFImageDecoder.h" |
26 #include "platform/image-decoders/ico/ICOImageDecoder.h" | 26 #include "platform/image-decoders/ico/ICOImageDecoder.h" |
27 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h" | 27 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h" |
28 #include "platform/image-decoders/png/PNGImageDecoder.h" | 28 #include "platform/image-decoders/png/PNGImageDecoder.h" |
29 #include "platform/image-decoders/webp/WEBPImageDecoder.h" | 29 #include "platform/image-decoders/webp/WEBPImageDecoder.h" |
30 #include "wtf/PtrUtil.h" | 30 #include "wtf/PassOwnPtr.h" |
31 #include <memory> | |
32 | 31 |
33 namespace blink { | 32 namespace blink { |
34 | 33 |
35 #if USE(QCMSLIB) | 34 #if USE(QCMSLIB) |
36 struct QCMSProfileDeleter { | 35 struct QCMSProfileDeleter { |
37 void operator()(qcms_profile* profile) | 36 void operator()(qcms_profile* profile) |
38 { | 37 { |
39 if (profile) | 38 if (profile) |
40 qcms_profile_release(profile); | 39 qcms_profile_release(profile); |
41 } | 40 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 inline bool matchesCURSignature(const char* contents) | 72 inline bool matchesCURSignature(const char* contents) |
74 { | 73 { |
75 return !memcmp(contents, "\x00\x00\x02\x00", 4); | 74 return !memcmp(contents, "\x00\x00\x02\x00", 4); |
76 } | 75 } |
77 | 76 |
78 inline bool matchesBMPSignature(const char* contents) | 77 inline bool matchesBMPSignature(const char* contents) |
79 { | 78 { |
80 return !memcmp(contents, "BM", 2); | 79 return !memcmp(contents, "BM", 2); |
81 } | 80 } |
82 | 81 |
83 std::unique_ptr<ImageDecoder> ImageDecoder::create(const char* contents, size_t
length, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions) | 82 PassOwnPtr<ImageDecoder> ImageDecoder::create(const char* contents, size_t lengt
h, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions) |
84 { | 83 { |
85 const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1; | 84 const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1; |
86 ASSERT(longestSignatureLength == 14); | 85 ASSERT(longestSignatureLength == 14); |
87 | 86 |
88 if (length < longestSignatureLength) | 87 if (length < longestSignatureLength) |
89 return nullptr; | 88 return nullptr; |
90 | 89 |
91 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod
edImageBytes() : noDecodedImageByteLimit; | 90 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod
edImageBytes() : noDecodedImageByteLimit; |
92 | 91 |
93 if (matchesJPEGSignature(contents)) | 92 if (matchesJPEGSignature(contents)) |
94 return wrapUnique(new JPEGImageDecoder(alphaOption, colorOptions, maxDec
odedBytes)); | 93 return adoptPtr(new JPEGImageDecoder(alphaOption, colorOptions, maxDecod
edBytes)); |
95 | 94 |
96 if (matchesPNGSignature(contents)) | 95 if (matchesPNGSignature(contents)) |
97 return wrapUnique(new PNGImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); | 96 return adoptPtr(new PNGImageDecoder(alphaOption, colorOptions, maxDecode
dBytes)); |
98 | 97 |
99 if (matchesGIFSignature(contents)) | 98 if (matchesGIFSignature(contents)) |
100 return wrapUnique(new GIFImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); | 99 return adoptPtr(new GIFImageDecoder(alphaOption, colorOptions, maxDecode
dBytes)); |
101 | 100 |
102 if (matchesWebPSignature(contents)) | 101 if (matchesWebPSignature(contents)) |
103 return wrapUnique(new WEBPImageDecoder(alphaOption, colorOptions, maxDec
odedBytes)); | 102 return adoptPtr(new WEBPImageDecoder(alphaOption, colorOptions, maxDecod
edBytes)); |
104 | 103 |
105 if (matchesICOSignature(contents) || matchesCURSignature(contents)) | 104 if (matchesICOSignature(contents) || matchesCURSignature(contents)) |
106 return wrapUnique(new ICOImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); | 105 return adoptPtr(new ICOImageDecoder(alphaOption, colorOptions, maxDecode
dBytes)); |
107 | 106 |
108 if (matchesBMPSignature(contents)) | 107 if (matchesBMPSignature(contents)) |
109 return wrapUnique(new BMPImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); | 108 return adoptPtr(new BMPImageDecoder(alphaOption, colorOptions, maxDecode
dBytes)); |
110 | 109 |
111 return nullptr; | 110 return nullptr; |
112 } | 111 } |
113 | 112 |
114 std::unique_ptr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, Alp
haOption alphaOption, GammaAndColorProfileOption colorOptions) | 113 PassOwnPtr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, AlphaOpt
ion alphaOption, GammaAndColorProfileOption colorOptions) |
115 { | 114 { |
116 const char* contents; | 115 const char* contents; |
117 const size_t length = data.getSomeData<size_t>(contents); | 116 const size_t length = data.getSomeData<size_t>(contents); |
118 return create(contents, length, alphaOption, colorOptions); | 117 return create(contents, length, alphaOption, colorOptions); |
119 } | 118 } |
120 | 119 |
121 std::unique_ptr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, Al
phaOption alphaOption, GammaAndColorProfileOption colorOptions) | 120 PassOwnPtr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, AlphaOp
tion alphaOption, GammaAndColorProfileOption colorOptions) |
122 { | 121 { |
123 const char* contents; | 122 const char* contents; |
124 const size_t length = data.getSomeData(contents, 0); | 123 const size_t length = data.getSomeData(contents, 0); |
125 return create(contents, length, alphaOption, colorOptions); | 124 return create(contents, length, alphaOption, colorOptions); |
126 } | 125 } |
127 | 126 |
128 size_t ImageDecoder::frameCount() | 127 size_t ImageDecoder::frameCount() |
129 { | 128 { |
130 const size_t oldSize = m_frameBufferCache.size(); | 129 const size_t oldSize = m_frameBufferCache.size(); |
131 const size_t newSize = decodeFrameCount(); | 130 const size_t newSize = decodeFrameCount(); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 | 363 |
365 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; | 364 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; |
366 | 365 |
367 // FIXME: Don't force perceptual intent if the image profile contains an int
ent. | 366 // FIXME: Don't force perceptual intent if the image profile contains an int
ent. |
368 m_sourceToOutputDeviceColorTransform.reset(qcms_transform_create(inputProfil
e.get(), dataFormat, gOutputDeviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPT
UAL)); | 367 m_sourceToOutputDeviceColorTransform.reset(qcms_transform_create(inputProfil
e.get(), dataFormat, gOutputDeviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPT
UAL)); |
369 } | 368 } |
370 | 369 |
371 #endif // USE(QCMSLIB) | 370 #endif // USE(QCMSLIB) |
372 | 371 |
373 } // namespace blink | 372 } // namespace blink |
OLD | NEW |