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

Side by Side Diff: third_party/WebKit/Source/core/html/ImageData.cpp

Issue 2035113002: Implement ImageBitmapOptions resize (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 5 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 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 return nullptr; 139 return nullptr;
140 } 140 }
141 ASSERT(lengthInPixels && width); 141 ASSERT(lengthInPixels && width);
142 if (height != lengthInPixels / width) { 142 if (height != lengthInPixels / width) {
143 exceptionState.throwDOMException(IndexSizeError, "The input data byte le ngth is not equal to (4 * width * height)."); 143 exceptionState.throwDOMException(IndexSizeError, "The input data byte le ngth is not equal to (4 * width * height).");
144 return nullptr; 144 return nullptr;
145 } 145 }
146 return new ImageData(IntSize(width, height), data); 146 return new ImageData(IntSize(width, height), data);
147 } 147 }
148 148
149 ScriptPromise ImageData::createImageBitmap(ScriptState* scriptState, EventTarget & eventTarget, int sx, int sy, int sw, int sh, const ImageBitmapOptions& options , ExceptionState& exceptionState) 149 ScriptPromise ImageData::createImageBitmap(ScriptState* scriptState, EventTarget & eventTarget, Optional<IntRect> cropRect, const ImageBitmapOptions& options, Ex ceptionState& exceptionState)
150 { 150 {
151 if (!sw || !sh) { 151 if ((cropRect && !ImageBitmap::isSourceSizeValid(cropRect->width(), cropRect ->height(), exceptionState))
152 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s provided is 0.", sw ? "height" : "width")); 152 || !ImageBitmap::isSourceSizeValid(bitmapSourceSize().width(), bitmapSou rceSize().height(), exceptionState))
153 return ScriptPromise(); 153 return ScriptPromise();
154 }
155 if (data()->bufferBase()->isNeutered()) { 154 if (data()->bufferBase()->isNeutered()) {
156 exceptionState.throwDOMException(InvalidStateError, "The source data has been neutered."); 155 exceptionState.throwDOMException(InvalidStateError, "The source data has been neutered.");
157 return ScriptPromise(); 156 return ScriptPromise();
158 } 157 }
159 return ImageBitmapSource::fulfillImageBitmap(scriptState, ImageBitmap::creat e(this, IntRect(sx, sy, sw, sh), options)); 158 if (!ImageBitmap::isResizeOptionValid(options, exceptionState))
159 return ScriptPromise();
160 return ImageBitmapSource::fulfillImageBitmap(scriptState, ImageBitmap::creat e(this, cropRect, options));
160 } 161 }
161 162
162 v8::Local<v8::Object> ImageData::associateWithWrapper(v8::Isolate* isolate, cons t WrapperTypeInfo* wrapperType, v8::Local<v8::Object> wrapper) 163 v8::Local<v8::Object> ImageData::associateWithWrapper(v8::Isolate* isolate, cons t WrapperTypeInfo* wrapperType, v8::Local<v8::Object> wrapper)
163 { 164 {
164 wrapper = ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrappe r); 165 wrapper = ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrappe r);
165 166
166 if (!wrapper.IsEmpty() && m_data.get()) { 167 if (!wrapper.IsEmpty() && m_data.get()) {
167 // Create a V8 Uint8ClampedArray object and set the "data" property 168 // Create a V8 Uint8ClampedArray object and set the "data" property
168 // of the ImageData object to the created v8 object, eliminating the 169 // of the ImageData object to the created v8 object, eliminating the
169 // C++ callback when accessing the "data" property. 170 // C++ callback when accessing the "data" property.
170 v8::Local<v8::Value> pixelArray = toV8(m_data.get(), wrapper, isolate); 171 v8::Local<v8::Value> pixelArray = toV8(m_data.get(), wrapper, isolate);
171 if (pixelArray.IsEmpty() || !v8CallBoolean(wrapper->DefineOwnProperty(is olate->GetCurrentContext(), v8AtomicString(isolate, "data"), pixelArray, v8::Rea dOnly))) 172 if (pixelArray.IsEmpty() || !v8CallBoolean(wrapper->DefineOwnProperty(is olate->GetCurrentContext(), v8AtomicString(isolate, "data"), pixelArray, v8::Rea dOnly)))
172 return v8::Local<v8::Object>(); 173 return v8::Local<v8::Object>();
173 } 174 }
174 return wrapper; 175 return wrapper;
175 } 176 }
176 177
177 ImageData::ImageData(const IntSize& size, DOMUint8ClampedArray* byteArray) 178 ImageData::ImageData(const IntSize& size, DOMUint8ClampedArray* byteArray)
178 : m_size(size) 179 : m_size(size)
179 , m_data(byteArray) 180 , m_data(byteArray)
180 { 181 {
181 ASSERT(size.width() >= 0 && size.height() >= 0); 182 ASSERT(size.width() >= 0 && size.height() >= 0);
182 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h eight() * 4) <= m_data->length()); 183 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h eight() * 4) <= m_data->length());
183 } 184 }
184 185
185 } // namespace blink 186 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/ImageData.h ('k') | third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698