| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "webkit/tools/test_shell/image_decoder_unittest.h" | 7 #include "webkit/tools/test_shell/image_decoder_unittest.h" |
| 8 | 8 |
| 9 #if !defined(OS_WIN) | 9 #if !defined(OS_WIN) |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // It is mainly used for comparison. | 74 // It is mainly used for comparison. |
| 75 class Image { | 75 class Image { |
| 76 public: | 76 public: |
| 77 // Creates the image from the given filename on disk. | 77 // Creates the image from the given filename on disk. |
| 78 Image(const std::wstring& filename) : ignore_alpha_(true) { | 78 Image(const std::wstring& filename) : ignore_alpha_(true) { |
| 79 Vector<char> compressed; | 79 Vector<char> compressed; |
| 80 ReadFileToVector(filename, &compressed); | 80 ReadFileToVector(filename, &compressed); |
| 81 EXPECT_TRUE(compressed.size()); | 81 EXPECT_TRUE(compressed.size()); |
| 82 WebCore::PNGImageDecoder decoder; | 82 WebCore::PNGImageDecoder decoder; |
| 83 decoder.setData(WebCore::SharedBuffer::adoptVector(compressed).get(), true); | 83 decoder.setData(WebCore::SharedBuffer::adoptVector(compressed).get(), true); |
| 84 SetSkBitmap(decoder.frameBufferAtIndex(0)->bitmap()); | 84 scoped_ptr<NativeImageSkia> image_data( |
| 85 decoder.frameBufferAtIndex(0)->asNewNativeImage()); |
| 86 SetSkBitmap(*image_data); |
| 85 } | 87 } |
| 86 | 88 |
| 87 // Loads the image from a canvas. | 89 // Loads the image from a canvas. |
| 88 Image(const skia::PlatformCanvasWin& canvas) : ignore_alpha_(true) { | 90 Image(const skia::PlatformCanvasWin& canvas) : ignore_alpha_(true) { |
| 89 // Use a different way to access the bitmap. The normal way would be to | 91 // Use a different way to access the bitmap. The normal way would be to |
| 90 // query the SkBitmap. | 92 // query the SkBitmap. |
| 91 HDC context = canvas.getTopPlatformDevice().getBitmapDC(); | 93 HDC context = canvas.getTopPlatformDevice().getBitmapDC(); |
| 92 HGDIOBJ bitmap = GetCurrentObject(context, OBJ_BITMAP); | 94 HGDIOBJ bitmap = GetCurrentObject(context, OBJ_BITMAP); |
| 93 EXPECT_TRUE(bitmap != NULL); | 95 EXPECT_TRUE(bitmap != NULL); |
| 94 // Initialize the clip region to the entire bitmap. | 96 // Initialize the clip region to the entire bitmap. |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 } | 320 } |
| 319 | 321 |
| 320 void LoadPngFileToSkBitmap(const std::wstring& filename, | 322 void LoadPngFileToSkBitmap(const std::wstring& filename, |
| 321 SkBitmap* bitmap, | 323 SkBitmap* bitmap, |
| 322 bool is_opaque) { | 324 bool is_opaque) { |
| 323 Vector<char> compressed; | 325 Vector<char> compressed; |
| 324 ReadFileToVector(filename, &compressed); | 326 ReadFileToVector(filename, &compressed); |
| 325 EXPECT_TRUE(compressed.size()); | 327 EXPECT_TRUE(compressed.size()); |
| 326 WebCore::PNGImageDecoder decoder; | 328 WebCore::PNGImageDecoder decoder; |
| 327 decoder.setData(WebCore::SharedBuffer::adoptVector(compressed).get(), true); | 329 decoder.setData(WebCore::SharedBuffer::adoptVector(compressed).get(), true); |
| 328 *bitmap = decoder.frameBufferAtIndex(0)->bitmap(); | 330 scoped_ptr<NativeImageSkia> image_data( |
| 331 decoder.frameBufferAtIndex(0)->asNewNativeImage()); |
| 332 *bitmap = *image_data; |
| 329 EXPECT_EQ(is_opaque, bitmap->isOpaque()); | 333 EXPECT_EQ(is_opaque, bitmap->isOpaque()); |
| 330 Premultiply(*bitmap); | 334 Premultiply(*bitmap); |
| 331 } | 335 } |
| 332 | 336 |
| 333 } // namespace | 337 } // namespace |
| 334 | 338 |
| 335 // Streams an image. | 339 // Streams an image. |
| 336 inline std::ostream& operator<<(std::ostream& out, const Image& image) { | 340 inline std::ostream& operator<<(std::ostream& out, const Image& image) { |
| 337 return out << "Image(" << image.width() << ", " | 341 return out << "Image(" << image.width() << ", " |
| 338 << image.height() << ", " << image.row_length() << ")"; | 342 << image.height() << ", " << image.row_length() << ")"; |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 { | 956 { |
| 953 vcanvas_->rotate(67); | 957 vcanvas_->rotate(67); |
| 954 pcanvas_->rotate(67); | 958 pcanvas_->rotate(67); |
| 955 vcanvas_->drawBitmap(bitmap, 20, -50, NULL); | 959 vcanvas_->drawBitmap(bitmap, 20, -50, NULL); |
| 956 pcanvas_->drawBitmap(bitmap, 20, -50, NULL); | 960 pcanvas_->drawBitmap(bitmap, 20, -50, NULL); |
| 957 EXPECT_EQ(0., ProcessImage(L"rotate")); | 961 EXPECT_EQ(0., ProcessImage(L"rotate")); |
| 958 } | 962 } |
| 959 } | 963 } |
| 960 | 964 |
| 961 } // namespace skia | 965 } // namespace skia |
| OLD | NEW |