Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: third_party/WebKit/Source/core/frame/ImageBitmap.cpp

Issue 1631733003: Implementing ImageBitmap option imageOrientation of flipY (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "core/frame/ImageBitmap.h" 5 #include "core/frame/ImageBitmap.h"
6 6
7 #include "core/html/HTMLCanvasElement.h" 7 #include "core/html/HTMLCanvasElement.h"
8 #include "core/html/HTMLVideoElement.h" 8 #include "core/html/HTMLVideoElement.h"
9 #include "core/html/ImageData.h" 9 #include "core/html/ImageData.h"
10 #include "third_party/skia/include/core/SkSurface.h" 10 #include "third_party/skia/include/core/SkSurface.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque, DoNotInitializeImagePixels); 83 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(cropRect.size(), NonOpaque, DoNotInitializeImagePixels);
84 if (!buffer) 84 if (!buffer)
85 return; 85 return;
86 86
87 if (srcRect.isEmpty()) { 87 if (srcRect.isEmpty()) {
88 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA cceleration)); 88 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoA cceleration));
89 return; 89 return;
90 } 90 }
91 91
92 IntPoint dstPoint = IntPoint(std::min(0, -cropRect.x()), std::min(0, -cropRe ct.y())); 92 IntPoint dstPoint = IntPoint(std::min(0, -cropRect.x()), std::min(0, -cropRe ct.y()));
jbroman 2016/01/26 17:03:37 Is it intended that the crop rect apply to the ima
xidachen 2016/02/03 02:17:19 Upon discussion with kbr@, it actually should be a
93 if (cropRect.x() < 0) 93 if (cropRect.x() < 0)
94 dstPoint.setX(-cropRect.x()); 94 dstPoint.setX(-cropRect.x());
95 if (cropRect.y() < 0) 95 if (cropRect.y() < 0)
96 dstPoint.setY(-cropRect.y()); 96 dstPoint.setY(-cropRect.y());
97 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(), srcRe ct, dstPoint); 97 if (options.orientation() == "flipY" || options.orientation() == "bottomLeft ") {
98 OwnPtr<uint8_t[]> flippedData = copyFlippedSourceData(data->data()->data (), data->width(), data->height());
99 buffer->putByteArray(Unmultiplied, flippedData.get(), data->size(), srcR ect, dstPoint);
100 } else {
101 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(), s rcRect, dstPoint);
102 }
98 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoAccel eration)); 103 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(PreferNoAccel eration));
99 } 104 }
100 105
101 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect, const Ima geBitmapOptions& options) 106 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, const IntRect& cropRect, const Ima geBitmapOptions& options)
102 { 107 {
103 m_image = cropImage(bitmap->bitmapImage(), cropRect); 108 m_image = cropImage(bitmap->bitmapImage(), cropRect);
104 m_image->setOriginClean(bitmap->originClean()); 109 m_image->setOriginClean(bitmap->originClean());
105 } 110 }
106 111
107 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image, const IntRect& cro pRect, const ImageBitmapOptions& options) 112 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image, const IntRect& cro pRect, const ImageBitmapOptions& options)
108 { 113 {
109 m_image = cropImage(image.get(), cropRect); 114 m_image = cropImage(image.get(), cropRect);
110 m_image->setOriginClean(image->originClean()); 115 m_image->setOriginClean(image->originClean());
111 } 116 }
112 117
113 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image) 118 ImageBitmap::ImageBitmap(PassRefPtr<StaticBitmapImage> image)
114 { 119 {
115 m_image = image; 120 m_image = image;
116 } 121 }
117 122
123 PassOwnPtr<uint8_t[]> ImageBitmap::copyFlippedSourceData(const unsigned char* so urce, int width, int height)
jbroman 2016/01/26 17:03:37 This assumes 4-byte pixels, and that the row size
xidachen 2016/02/03 02:17:19 This function won't be needed anymore because we d
124 {
125 const size_t bytesPerRow = 4 * width;
126 OwnPtr<uint8_t[]> dstPixels = adoptArrayPtr(new uint8_t[width * height * 4]) ;
127 for (int i = 0; i < height; i++) {
128 const unsigned char* srcAddr = source + i * bytesPerRow;
129 unsigned char* dstAddr = dstPixels.get() + (height - 1 - i) * bytesPerRo w;
130 memcpy(dstAddr, srcAddr, bytesPerRow);
131 }
132 return dstPixels.release();
133 }
134
118 PassRefPtr<StaticBitmapImage> ImageBitmap::transfer() 135 PassRefPtr<StaticBitmapImage> ImageBitmap::transfer()
119 { 136 {
120 ASSERT(!isNeutered()); 137 ASSERT(!isNeutered());
121 m_isNeutered = true; 138 m_isNeutered = true;
122 return m_image.release(); 139 return m_image.release();
123 } 140 }
124 141
125 ImageBitmap::~ImageBitmap() 142 ImageBitmap::~ImageBitmap()
126 { 143 {
127 } 144 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 { 244 {
228 return FloatSize(width(), height()); 245 return FloatSize(width(), height());
229 } 246 }
230 247
231 DEFINE_TRACE(ImageBitmap) 248 DEFINE_TRACE(ImageBitmap)
232 { 249 {
233 ImageLoaderClient::trace(visitor); 250 ImageLoaderClient::trace(visitor);
234 } 251 }
235 252
236 } // namespace blink 253 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698