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

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

Issue 2202143002: Fix tests: conformance_textures_image_bitmap_from_image_data on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile error Created 4 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "platform/graphics/skia/SkiaUtils.h" 10 #include "platform/graphics/skia/SkiaUtils.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 delete[] static_cast<const uint8_t*>(pixels); 117 delete[] static_cast<const uint8_t*>(pixels);
118 }, nullptr)); 118 }, nullptr));
119 } 119 }
120 120
121 static void swizzleImageData(unsigned char* srcAddr, int height, int bytesPerRow , bool flipY) 121 static void swizzleImageData(unsigned char* srcAddr, int height, int bytesPerRow , bool flipY)
122 { 122 {
123 if (flipY) { 123 if (flipY) {
124 for (int i = 0; i < height / 2; i++) { 124 for (int i = 0; i < height / 2; i++) {
125 int topRowStartPosition = i * bytesPerRow; 125 int topRowStartPosition = i * bytesPerRow;
126 int bottomRowStartPosition = (height - 1 - i) * bytesPerRow; 126 int bottomRowStartPosition = (height - 1 - i) * bytesPerRow;
127 for (int j = 0; j < bytesPerRow; j += 4) { 127 if (kN32_SkColorType == kBGRA_8888_SkColorType) { // needs to swizzl e
128 std::swap(srcAddr[topRowStartPosition + j], srcAddr[bottomRowSta rtPosition + j + 2]); 128 for (int j = 0; j < bytesPerRow; j += 4) {
129 std::swap(srcAddr[topRowStartPosition + j + 1], srcAddr[bottomRo wStartPosition + j + 1]); 129 std::swap(srcAddr[topRowStartPosition + j], srcAddr[bottomRo wStartPosition + j + 2]);
130 std::swap(srcAddr[topRowStartPosition + j + 2], srcAddr[bottomRo wStartPosition + j]); 130 std::swap(srcAddr[topRowStartPosition + j + 1], srcAddr[bott omRowStartPosition + j + 1]);
131 std::swap(srcAddr[topRowStartPosition + j + 3], srcAddr[bottomRo wStartPosition + j + 3]); 131 std::swap(srcAddr[topRowStartPosition + j + 2], srcAddr[bott omRowStartPosition + j]);
132 std::swap(srcAddr[topRowStartPosition + j + 3], srcAddr[bott omRowStartPosition + j + 3]);
133 }
134 } else {
135 std::swap_ranges(srcAddr + topRowStartPosition, srcAddr + topRow StartPosition + bytesPerRow, srcAddr + bottomRowStartPosition);
132 } 136 }
133 } 137 }
134 } else { 138 } else {
135 for (int i = 0; i < height * bytesPerRow; i += 4) 139 if (kN32_SkColorType == kBGRA_8888_SkColorType) // needs to swizzle
136 std::swap(srcAddr[i], srcAddr[i + 2]); 140 for (int i = 0; i < height * bytesPerRow; i += 4)
141 std::swap(srcAddr[i], srcAddr[i + 2]);
137 } 142 }
138 } 143 }
139 144
140 static PassRefPtr<SkImage> flipSkImageVertically(SkImage* input, AlphaDispositio n alphaOp) 145 static PassRefPtr<SkImage> flipSkImageVertically(SkImage* input, AlphaDispositio n alphaOp)
141 { 146 {
142 int width = input->width(); 147 int width = input->width();
143 int height = input->height(); 148 int height = input->height();
144 SkImageInfo info = SkImageInfo::MakeN32(width, height, (alphaOp == Premultip lyAlpha) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType); 149 SkImageInfo info = SkImageInfo::MakeN32(width, height, (alphaOp == Premultip lyAlpha) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType);
145 int imageRowBytes = width * info.bytesPerPixel(); 150 int imageRowBytes = width * info.bytesPerPixel();
146 std::unique_ptr<uint8_t[]> imagePixels = copySkImageData(input, info); 151 std::unique_ptr<uint8_t[]> imagePixels = copySkImageData(input, info);
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 unsigned char* srcAddr = data->data()->data(); 399 unsigned char* srcAddr = data->data()->data();
395 int srcHeight = data->size().height(); 400 int srcHeight = data->size().height();
396 int dstHeight = parsedOptions.cropRect.height(); 401 int dstHeight = parsedOptions.cropRect.height();
397 402
398 // Using kN32 type, swizzle input if necessary. 403 // Using kN32 type, swizzle input if necessary.
399 SkImageInfo info = SkImageInfo::Make(parsedOptions.cropRect.width(), dst Height, kN32_SkColorType, kUnpremul_SkAlphaType); 404 SkImageInfo info = SkImageInfo::Make(parsedOptions.cropRect.width(), dst Height, kN32_SkColorType, kUnpremul_SkAlphaType);
400 int srcPixelBytesPerRow = info.bytesPerPixel() * data->size().width(); 405 int srcPixelBytesPerRow = info.bytesPerPixel() * data->size().width();
401 int dstPixelBytesPerRow = info.bytesPerPixel() * parsedOptions.cropRect. width(); 406 int dstPixelBytesPerRow = info.bytesPerPixel() * parsedOptions.cropRect. width();
402 RefPtr<SkImage> skImage; 407 RefPtr<SkImage> skImage;
403 if (parsedOptions.cropRect == IntRect(IntPoint(), data->size())) { 408 if (parsedOptions.cropRect == IntRect(IntPoint(), data->size())) {
404 if (kN32_SkColorType == kBGRA_8888_SkColorType) 409 swizzleImageData(srcAddr, srcHeight, srcPixelBytesPerRow, parsedOpti ons.flipY);
405 swizzleImageData(srcAddr, srcHeight, srcPixelBytesPerRow, parsed Options.flipY);
406 skImage = fromSkSp(SkImage::MakeRasterCopy(SkPixmap(info, srcAddr, d stPixelBytesPerRow))); 410 skImage = fromSkSp(SkImage::MakeRasterCopy(SkPixmap(info, srcAddr, d stPixelBytesPerRow)));
407 // restore the original ImageData 411 // restore the original ImageData
408 if (kN32_SkColorType == kBGRA_8888_SkColorType) 412 swizzleImageData(srcAddr, srcHeight, srcPixelBytesPerRow, parsedOpti ons.flipY);
409 swizzleImageData(srcAddr, srcHeight, srcPixelBytesPerRow, parsed Options.flipY);
410 } else { 413 } else {
411 std::unique_ptr<uint8_t[]> copiedDataBuffer = wrapArrayUnique(new ui nt8_t[dstHeight * dstPixelBytesPerRow]()); 414 std::unique_ptr<uint8_t[]> copiedDataBuffer = wrapArrayUnique(new ui nt8_t[dstHeight * dstPixelBytesPerRow]());
412 if (!srcRect.isEmpty()) { 415 if (!srcRect.isEmpty()) {
413 IntPoint srcPoint = IntPoint((parsedOptions.cropRect.x() > 0) ? parsedOptions.cropRect.x() : 0, (parsedOptions.cropRect.y() > 0) ? parsedOptions .cropRect.y() : 0); 416 IntPoint srcPoint = IntPoint((parsedOptions.cropRect.x() > 0) ? parsedOptions.cropRect.x() : 0, (parsedOptions.cropRect.y() > 0) ? parsedOptions .cropRect.y() : 0);
414 IntPoint dstPoint = IntPoint((parsedOptions.cropRect.x() >= 0) ? 0 : -parsedOptions.cropRect.x(), (parsedOptions.cropRect.y() >= 0) ? 0 : -parse dOptions.cropRect.y()); 417 IntPoint dstPoint = IntPoint((parsedOptions.cropRect.x() >= 0) ? 0 : -parsedOptions.cropRect.x(), (parsedOptions.cropRect.y() >= 0) ? 0 : -parse dOptions.cropRect.y());
415 int copyHeight = srcHeight - srcPoint.y(); 418 int copyHeight = srcHeight - srcPoint.y();
416 if (parsedOptions.cropRect.height() < copyHeight) 419 if (parsedOptions.cropRect.height() < copyHeight)
417 copyHeight = parsedOptions.cropRect.height(); 420 copyHeight = parsedOptions.cropRect.height();
418 int copyWidth = data->size().width() - srcPoint.x(); 421 int copyWidth = data->size().width() - srcPoint.x();
419 if (parsedOptions.cropRect.width() < copyWidth) 422 if (parsedOptions.cropRect.width() < copyWidth)
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 FloatSize ImageBitmap::elementSize(const FloatSize&) const 651 FloatSize ImageBitmap::elementSize(const FloatSize&) const
649 { 652 {
650 return FloatSize(width(), height()); 653 return FloatSize(width(), height());
651 } 654 }
652 655
653 DEFINE_TRACE(ImageBitmap) 656 DEFINE_TRACE(ImageBitmap)
654 { 657 {
655 } 658 }
656 659
657 } // namespace blink 660 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698