Issue 2972: Canvas toDataURL isn't supported
http://code.google.com/p/chromium/issues/detail?id=2972
Comment #6 by [EMAIL PROTECTED]:
When implementing this be sure and pick up the tests identified in 2972,
they are all related.
Here's an implementation of getImageData I started on:
PassRefPtr<ImageData> ImageBuffer::getImageData(const IntRect& rect) const
{
PassRefPtr<ImageData> result = ImageData::create(rect.width(),
rect.height());
unsigned char* data = result->data()->data().data();
if (rect.x() < 0 || rect.y() < 0 || (rect.x() + rect.width()) >
m_size.width() || (rect.y() +
rect.height()) > m_size.height())
memset(data, 0, result->data()->length());
int originx = rect.x();
int destx = 0;
if (originx < 0) {
destx = -originx;
originx = 0;
}
int endx = rect.x() + rect.width();
if (endx > m_size.width())
endx = m_size.width();
int numColumns = endx - originx;
int originy = rect.y();
int desty = 0;
if (originy < 0) {
desty = -originy;
originy = 0;
}
int endy = rect.y() + rect.height();
if (endy > m_size.height())
endy = m_size.height();
int numRows = endy - originy;
unsigned srcBytesPerRow = 4 * m_size.width();
unsigned destBytesPerRow = 4 * numColumns;
unsigned char* srcRows = reinterpret_cast<unsigned
char*>(context()->platformContext()->bitmap()-
>getAddr32(0, 0)) + originy * srcBytesPerRow + originx * 4;
unsigned char* destRows = data + desty * destBytesPerRow + destx * 4;
for (int y = 0; y < numRows; ++y) {
memcpy(destRows, srcRows, destBytesPerRow);
srcRows += srcBytesPerRow;
destRows += destBytesPerRow;
}
return result;
}
Additionally you'll need to define a custom indexed getters in the v8
binding code. Here's a start at
that (in v8_proxy.cc):
static v8::Handle<v8::Value> GetIndexedPropertyOfCanvasPixelArray(
uint32_t index, v8::Local<v8::Object> object, v8::Local<v8::Value>
data) {
// TODO, assert that object must be a collection type
ASSERT(V8Proxy::MaybeDOMWrapper(object));
V8ClassIndex::V8WrapperType t = V8Proxy::GetDOMWrapperType(object);
ASSERT(t != V8ClassIndex::NODE);
CanvasPixelArray* pixel_array =
V8Proxy::ToNativeObject<CanvasPixelArray>(t, object);
unsigned char result;
if (!pixel_array->get(index, result))
return return v8::Handle<v8::Value>();
// Need to return value here.
}
And add the following switch to V8Proxy::GetTemplate:
case V8ClassIndex::CANVASPIXELARRAY:
desc->InstanceTemplate()->SetIndexedPropertyHandler(
GetIndexedPropertyOfCanvasPixelArray());
break;
The IDL also defines a custom index setter. That'll have to be wired up in
the binding code as well
with a custom function.
Issue attribute updates:
Cc: [EMAIL PROTECTED]
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Chromium-bugs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/chromium-bugs?hl=en
-~----------~----~----~----~------~----~------~--~---