Home | History | Annotate | Download | only in image
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "ui/gfx/image/image_util.h"
      6 
      7 #include <vector>
      8 
      9 #include "base/memory/scoped_ptr.h"
     10 #include "testing/gtest/include/gtest/gtest.h"
     11 #include "third_party/skia/include/core/SkBitmap.h"
     12 #include "ui/gfx/image/image_unittest_util.h"
     13 
     14 TEST(ImageUtilTest, JPEGEncodeAndDecode) {
     15   gfx::Image original = gfx::test::CreateImage(100, 100);
     16 
     17   std::vector<unsigned char> encoded;
     18   ASSERT_TRUE(gfx::JPEG1xEncodedDataFromImage(original, 80, &encoded));
     19 
     20   gfx::Image decoded =
     21       gfx::ImageFrom1xJPEGEncodedData(&encoded.front(), encoded.size());
     22 
     23   // JPEG is lossy, so simply check that the image decoded successfully.
     24   EXPECT_FALSE(decoded.IsEmpty());
     25 }
     26