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/PassOwnPtr.h" | 30 #include "wtf/PtrUtil.h" |
| 31 #include <memory> |
31 | 32 |
32 namespace blink { | 33 namespace blink { |
33 | 34 |
34 #if USE(QCMSLIB) | 35 #if USE(QCMSLIB) |
35 struct QCMSProfileDeleter { | 36 struct QCMSProfileDeleter { |
36 void operator()(qcms_profile* profile) | 37 void operator()(qcms_profile* profile) |
37 { | 38 { |
38 if (profile) | 39 if (profile) |
39 qcms_profile_release(profile); | 40 qcms_profile_release(profile); |
40 } | 41 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 inline bool matchesCURSignature(const char* contents) | 73 inline bool matchesCURSignature(const char* contents) |
73 { | 74 { |
74 return !memcmp(contents, "\x00\x00\x02\x00", 4); | 75 return !memcmp(contents, "\x00\x00\x02\x00", 4); |
75 } | 76 } |
76 | 77 |
77 inline bool matchesBMPSignature(const char* contents) | 78 inline bool matchesBMPSignature(const char* contents) |
78 { | 79 { |
79 return !memcmp(contents, "BM", 2); | 80 return !memcmp(contents, "BM", 2); |
80 } | 81 } |
81 | 82 |
82 PassOwnPtr<ImageDecoder> ImageDecoder::create(const char* contents, size_t lengt
h, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions) | 83 std::unique_ptr<ImageDecoder> ImageDecoder::create(const char* contents, size_t
length, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions) |
83 { | 84 { |
84 const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1; | 85 const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1; |
85 ASSERT(longestSignatureLength == 14); | 86 ASSERT(longestSignatureLength == 14); |
86 | 87 |
87 if (length < longestSignatureLength) | 88 if (length < longestSignatureLength) |
88 return nullptr; | 89 return nullptr; |
89 | 90 |
90 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod
edImageBytes() : noDecodedImageByteLimit; | 91 size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecod
edImageBytes() : noDecodedImageByteLimit; |
91 | 92 |
92 if (matchesJPEGSignature(contents)) | 93 if (matchesJPEGSignature(contents)) |
93 return adoptPtr(new JPEGImageDecoder(alphaOption, colorOptions, maxDecod
edBytes)); | 94 return wrapUnique(new JPEGImageDecoder(alphaOption, colorOptions, maxDec
odedBytes)); |
94 | 95 |
95 if (matchesPNGSignature(contents)) | 96 if (matchesPNGSignature(contents)) |
96 return adoptPtr(new PNGImageDecoder(alphaOption, colorOptions, maxDecode
dBytes)); | 97 return wrapUnique(new PNGImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); |
97 | 98 |
98 if (matchesGIFSignature(contents)) | 99 if (matchesGIFSignature(contents)) |
99 return adoptPtr(new GIFImageDecoder(alphaOption, colorOptions, maxDecode
dBytes)); | 100 return wrapUnique(new GIFImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); |
100 | 101 |
101 if (matchesWebPSignature(contents)) | 102 if (matchesWebPSignature(contents)) |
102 return adoptPtr(new WEBPImageDecoder(alphaOption, colorOptions, maxDecod
edBytes)); | 103 return wrapUnique(new WEBPImageDecoder(alphaOption, colorOptions, maxDec
odedBytes)); |
103 | 104 |
104 if (matchesICOSignature(contents) || matchesCURSignature(contents)) | 105 if (matchesICOSignature(contents) || matchesCURSignature(contents)) |
105 return adoptPtr(new ICOImageDecoder(alphaOption, colorOptions, maxDecode
dBytes)); | 106 return wrapUnique(new ICOImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); |
106 | 107 |
107 if (matchesBMPSignature(contents)) | 108 if (matchesBMPSignature(contents)) |
108 return adoptPtr(new BMPImageDecoder(alphaOption, colorOptions, maxDecode
dBytes)); | 109 return wrapUnique(new BMPImageDecoder(alphaOption, colorOptions, maxDeco
dedBytes)); |
109 | 110 |
110 return nullptr; | 111 return nullptr; |
111 } | 112 } |
112 | 113 |
113 PassOwnPtr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, AlphaOpt
ion alphaOption, GammaAndColorProfileOption colorOptions) | 114 std::unique_ptr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, Alp
haOption alphaOption, GammaAndColorProfileOption colorOptions) |
114 { | 115 { |
115 const char* contents; | 116 const char* contents; |
116 const size_t length = data.getSomeData<size_t>(contents); | 117 const size_t length = data.getSomeData<size_t>(contents); |
117 return create(contents, length, alphaOption, colorOptions); | 118 return create(contents, length, alphaOption, colorOptions); |
118 } | 119 } |
119 | 120 |
120 PassOwnPtr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, AlphaOp
tion alphaOption, GammaAndColorProfileOption colorOptions) | 121 std::unique_ptr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, Al
phaOption alphaOption, GammaAndColorProfileOption colorOptions) |
121 { | 122 { |
122 const char* contents; | 123 const char* contents; |
123 const size_t length = data.getSomeData(contents, 0); | 124 const size_t length = data.getSomeData(contents, 0); |
124 return create(contents, length, alphaOption, colorOptions); | 125 return create(contents, length, alphaOption, colorOptions); |
125 } | 126 } |
126 | 127 |
127 size_t ImageDecoder::frameCount() | 128 size_t ImageDecoder::frameCount() |
128 { | 129 { |
129 const size_t oldSize = m_frameBufferCache.size(); | 130 const size_t oldSize = m_frameBufferCache.size(); |
130 const size_t newSize = decodeFrameCount(); | 131 const size_t newSize = decodeFrameCount(); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 | 364 |
364 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; | 365 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; |
365 | 366 |
366 // FIXME: Don't force perceptual intent if the image profile contains an int
ent. | 367 // FIXME: Don't force perceptual intent if the image profile contains an int
ent. |
367 m_sourceToOutputDeviceColorTransform.reset(qcms_transform_create(inputProfil
e.get(), dataFormat, gOutputDeviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPT
UAL)); | 368 m_sourceToOutputDeviceColorTransform.reset(qcms_transform_create(inputProfil
e.get(), dataFormat, gOutputDeviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPT
UAL)); |
368 } | 369 } |
369 | 370 |
370 #endif // USE(QCMSLIB) | 371 #endif // USE(QCMSLIB) |
371 | 372 |
372 } // namespace blink | 373 } // namespace blink |
OLD | NEW |