18abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)/* 28abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved. 38abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * 48abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 58abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * modification, are permitted provided that the following conditions are 68abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * met: 78abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * 88abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * * Redistributions of source code must retain the above copyright 98abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 108abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * * Redistributions in binary form must reproduce the above 118abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 128abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * in the documentation and/or other materials provided with the 138abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * distribution. 148abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 158abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * contributors may be used to endorse or promote products derived from 168abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * this software without specific prior written permission. 178abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * 188abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 198abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 208abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 218abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 228abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 238abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 248abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 258abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 268abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 278abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 288abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 298abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) */ 308abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 3143e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)#include "config.h" 328abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 33a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/image-decoders/jpeg/JPEGImageDecoder.h" 348abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/SharedBuffer.h" 368abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#include "public/platform/Platform.h" 378abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#include "public/platform/WebData.h" 388abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#include "public/platform/WebSize.h" 398abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#include "public/platform/WebUnitTestSupport.h" 408abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#include "wtf/OwnPtr.h" 418abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#include "wtf/PassOwnPtr.h" 428abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#include "wtf/StringHasher.h" 438abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 448abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#include <gtest/gtest.h> 458abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 4651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)using namespace blink; 47c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 48c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)static const size_t LargeEnoughSize = 1000 * 1000; 498abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 508abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)namespace { 518abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 528abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)PassRefPtr<SharedBuffer> readFile(const char* fileName) 538abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){ 548abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) String filePath = Platform::current()->unitTestSupport()->webKitRootDir(); 558abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) filePath.append(fileName); 568abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 578abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) return Platform::current()->unitTestSupport()->readFromFile(filePath); 588abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)} 598abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 6006f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)PassOwnPtr<JPEGImageDecoder> createDecoder(size_t maxDecodedBytes) 618abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){ 6206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) return adoptPtr(new JPEGImageDecoder(ImageSource::AlphaNotPremultiplied, ImageSource::GammaAndColorProfileApplied, maxDecodedBytes)); 638abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)} 648abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 658abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)} // namespace 668abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)void downsample(size_t maxDecodedBytes, unsigned* outputWidth, unsigned* outputHeight, const char* imageFilePath) 688abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){ 691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) RefPtr<SharedBuffer> data = readFile(imageFilePath); 708abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) ASSERT_TRUE(data.get()); 718abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 7206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) OwnPtr<JPEGImageDecoder> decoder = createDecoder(maxDecodedBytes); 738abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) decoder->setData(data.get(), true); 748abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 758abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) ImageFrame* frame = decoder->frameBufferAtIndex(0); 768abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) ASSERT_TRUE(frame); 778abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) *outputWidth = frame->getSkBitmap().width(); 788abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) *outputHeight = frame->getSkBitmap().height(); 7906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) EXPECT_EQ(IntSize(*outputWidth, *outputHeight), decoder->decodedSize()); 808abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)} 818abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 82c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)void readYUV(size_t maxDecodedBytes, unsigned* outputYWidth, unsigned* outputYHeight, unsigned* outputUVWidth, unsigned* outputUVHeight, const char* imageFilePath) 83c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles){ 84c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) RefPtr<SharedBuffer> data = readFile(imageFilePath); 85c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) ASSERT_TRUE(data.get()); 86c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 87c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) OwnPtr<JPEGImageDecoder> decoder = createDecoder(maxDecodedBytes); 88c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) decoder->setData(data.get(), true); 89c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 90c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes()); 917242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci decoder->setImagePlanes(imagePlanes.release()); 92c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) bool sizeIsAvailable = decoder->isSizeAvailable(); 93c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) ASSERT_TRUE(sizeIsAvailable); 94c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 95c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) IntSize size = decoder->decodedSize(); 967242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci IntSize ySize = decoder->decodedYUVSize(0, ImageDecoder::ActualSize); 977242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci IntSize uSize = decoder->decodedYUVSize(1, ImageDecoder::ActualSize); 987242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci IntSize vSize = decoder->decodedYUVSize(2, ImageDecoder::ActualSize); 99c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 100c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) ASSERT_TRUE(size.width() == ySize.width()); 101c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) ASSERT_TRUE(size.height() == ySize.height()); 102c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) ASSERT_TRUE(uSize.width() == vSize.width()); 103c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) ASSERT_TRUE(uSize.height() == vSize.height()); 104c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 105c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) *outputYWidth = ySize.width(); 106c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) *outputYHeight = ySize.height(); 107c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) *outputUVWidth = uSize.width(); 108c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) *outputUVHeight = uSize.height(); 109c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} 110c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 11106f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)// Tests failure on a too big image. 11206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)TEST(JPEGImageDecoderTest, tooBig) 1138abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){ 11406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) OwnPtr<JPEGImageDecoder> decoder = createDecoder(100); 11506f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) EXPECT_FALSE(decoder->setSize(10000, 10000)); 11606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) EXPECT_TRUE(decoder->failed()); 1178abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)} 1188abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 1191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)// Tests that JPEG decoder can downsample image whose width and height are multiple of 8, 1201e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)// to ensure we compute the correct decodedSize and pass correct parameters to libjpeg to 1211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)// output image with the expected size. 1221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)TEST(JPEGImageDecoderTest, downsampleImageSizeMultipleOf8) 1238abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){ 1241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 256x256 1258abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) unsigned outputWidth, outputHeight; 1268abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 1278abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // 1/8 downsample. 1281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) downsample(40 * 40 * 4, &outputWidth, &outputHeight, jpegFile); 1298abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(32u, outputWidth); 1308abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(32u, outputHeight); 1318abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 1328abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // 2/8 downsample. 1331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) downsample(70 * 70 * 4, &outputWidth, &outputHeight, jpegFile); 1348abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(64u, outputWidth); 1358abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(64u, outputHeight); 1368abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 1378abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // 3/8 downsample. 1381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) downsample(100 * 100 * 4, &outputWidth, &outputHeight, jpegFile); 1398abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(96u, outputWidth); 1408abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(96u, outputHeight); 1418abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 1428abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // 4/8 downsample. 1431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) downsample(130 * 130 * 4, &outputWidth, &outputHeight, jpegFile); 1448abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(128u, outputWidth); 1458abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(128u, outputHeight); 1468abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 1478abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // 5/8 downsample. 1481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) downsample(170 * 170 * 4, &outputWidth, &outputHeight, jpegFile); 1498abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(160u, outputWidth); 1508abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(160u, outputHeight); 1518abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 1528abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // 6/8 downsample. 1531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) downsample(200 * 200 * 4, &outputWidth, &outputHeight, jpegFile); 1548abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(192u, outputWidth); 1558abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(192u, outputHeight); 1568abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 1578abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) // 7/8 downsample. 1581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) downsample(230 * 230 * 4, &outputWidth, &outputHeight, jpegFile); 1598abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(224u, outputWidth); 1608abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(224u, outputHeight); 1618abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)} 1628abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 1631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)// Tests that JPEG decoder can downsample image whose width and height are not multiple of 8. 1641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)// Ensures that we round decodedSize and scale_num using the same algorithm as that of libjpeg. 1651e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)TEST(JPEGImageDecoderTest, downsampleImageSizeNotMultipleOf8) 1661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){ 1671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) const char* jpegFile = "/LayoutTests/fast/images/resources/icc-v2-gbr.jpg"; // 275x207 1681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) unsigned outputWidth, outputHeight; 1691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 1701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) // 1/8 downsample. 1711e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) downsample(40 * 40 * 4, &outputWidth, &outputHeight, jpegFile); 1721e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) EXPECT_EQ(35u, outputWidth); 1731e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) EXPECT_EQ(26u, outputHeight); 1741e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 1751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) // 2/8 downsample. 1761e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) downsample(70 * 70 * 4, &outputWidth, &outputHeight, jpegFile); 1771e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) EXPECT_EQ(69u, outputWidth); 1781e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) EXPECT_EQ(52u, outputHeight); 1791e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 1801e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) // 3/8 downsample. 1811e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) downsample(100 * 100 * 4, &outputWidth, &outputHeight, jpegFile); 1821e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) EXPECT_EQ(104u, outputWidth); 1831e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) EXPECT_EQ(78u, outputHeight); 1841e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 1851e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) // 4/8 downsample. 1861e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) downsample(130 * 130 * 4, &outputWidth, &outputHeight, jpegFile); 1871e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) EXPECT_EQ(138u, outputWidth); 1881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) EXPECT_EQ(104u, outputHeight); 1891e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 1901e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) // 5/8 downsample. 1911e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) downsample(170 * 170 * 4, &outputWidth, &outputHeight, jpegFile); 1921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) EXPECT_EQ(172u, outputWidth); 1931e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) EXPECT_EQ(130u, outputHeight); 1941e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 1951e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) // 6/8 downsample. 1961e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) downsample(200 * 200 * 4, &outputWidth, &outputHeight, jpegFile); 1971e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) EXPECT_EQ(207u, outputWidth); 1981e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) EXPECT_EQ(156u, outputHeight); 1991e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 2001e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) // 7/8 downsample. 2011e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) downsample(230 * 230 * 4, &outputWidth, &outputHeight, jpegFile); 2021e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) EXPECT_EQ(241u, outputWidth); 2031e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) EXPECT_EQ(182u, outputHeight); 2041e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)} 2051e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 2068abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)// Tests that upsampling is not allowed. 2078abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)TEST(JPEGImageDecoderTest, upsample) 2088abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles){ 2091e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 256x256 2108abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) unsigned outputWidth, outputHeight; 211c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) downsample(LargeEnoughSize, &outputWidth, &outputHeight, jpegFile); 2128abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(256u, outputWidth); 2138abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) EXPECT_EQ(256u, outputHeight); 2148abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)} 215c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 216c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)TEST(JPEGImageDecoderTest, yuv) 217c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles){ 218c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 256x256, YUV 4:2:0 219c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) unsigned outputYWidth, outputYHeight, outputUVWidth, outputUVHeight; 220c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) readYUV(LargeEnoughSize, &outputYWidth, &outputYHeight, &outputUVWidth, &outputUVHeight, jpegFile); 221c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) EXPECT_EQ(256u, outputYWidth); 222c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) EXPECT_EQ(256u, outputYHeight); 223c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) EXPECT_EQ(128u, outputUVWidth); 224c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) EXPECT_EQ(128u, outputUVHeight); 225c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} 226