Changeset 87032 in webkit
- Timestamp:
- May 22, 2011 9:56:55 AM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r87029 r87032 1 2011-05-22 Andrew Wason <rectalogic@rectalogic.com> 2 3 Reviewed by Benjamin Poulain. 4 5 [Qt] Implement toImageData() in QtWebKit Bridge 6 https://bugs.webkit.org/show_bug.cgi?id=60897 7 8 Tests are in WebKit/qt/tests/hybridPixmap 9 10 * bridge/qt/qt_pixmapruntime.cpp: 11 (JSC::Bindings::QtPixmapToImageDataMethod::name): 12 (JSC::Bindings::QtPixmapToImageDataMethod::invoke): 13 (JSC::Bindings::QtPixmapToImageDataMethod::copyPixels): 14 (JSC::Bindings::QtPixmapClass::methodsNamed): 15 (JSC::Bindings::QtPixmapInstance::getPropertyNames): 16 Add toImageData() to Qt Bridge, alternative to 17 assignToHTMLImageElement(). 18 1 19 2011-05-22 Dominic Cooney <dominicc@chromium.org> 2 20 -
trunk/Source/WebCore/bridge/qt/qt_pixmapruntime.cpp
r84556 r87032 22 22 #include "CachedImage.h" 23 23 #include "HTMLImageElement.h" 24 #include "ImageData.h" 25 #include "IntSize.h" 24 26 #include "JSGlobalObject.h" 25 27 #include "JSHTMLImageElement.h" 28 #include "JSImageData.h" 26 29 #include "JSLock.h" 27 30 #include "ObjectPrototype.h" 28 31 #include "StillImageQt.h" 32 #include <QtEndian> 29 33 #include <QBuffer> 30 34 #include <QByteArray> 35 #include <QColor> 31 36 #include <QImage> 32 37 #include <QPixmap> … … 80 85 }; 81 86 87 class QtPixmapToImageDataMethod : public QtPixmapRuntimeMethod { 88 public: 89 static const char* name() { return "toImageData"; } 90 JSValue invoke(ExecState* exec, QtPixmapInstance* instance) 91 { 92 int width = instance->width(); 93 int height = instance->height(); 94 RefPtr<ByteArray> byteArray = ByteArray::create(width * height * 4); 95 copyPixels(instance->toImage(), width, height, byteArray->data()); 96 RefPtr<ImageData> imageData = ImageData::create(IntSize(width, height), byteArray); 97 return toJS(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), imageData.get()); 98 } 99 private: 100 void copyPixels(const QImage& sourceImage, int width, int height, unsigned char* destPixels) 101 { 102 QImage image(sourceImage); 103 switch (image.format()) { 104 case QImage::Format_RGB888: 105 for (int y = 0; y < height; y++) { 106 const uchar* scanLine = image.scanLine(y); 107 for (int x = 0; x < width; x++) { 108 *(destPixels++) = *(scanLine++); 109 *(destPixels++) = *(scanLine++); 110 *(destPixels++) = *(scanLine++); 111 *(destPixels++) = 0xFF; 112 } 113 } 114 break; 115 default: 116 image = image.convertToFormat(QImage::Format_ARGB32); 117 // Fall through 118 case QImage::Format_RGB32: 119 case QImage::Format_ARGB32: 120 for (int y = 0; y < height; y++) { 121 const quint32* scanLine = reinterpret_cast_ptr<const quint32*>(image.scanLine(y)); 122 for (int x = 0; x < width; x++) { 123 QRgb pixel = scanLine[x]; 124 qToBigEndian<quint32>((pixel << 8) | qAlpha(pixel), destPixels); 125 destPixels += 4; 126 } 127 } 128 break; 129 } 130 } 131 }; 132 82 133 // this function receives an HTML image element as a parameter, makes it display the pixmap/image from Qt 83 134 class QtPixmapAssignToElementMethod : public QtPixmapRuntimeMethod { … … 137 188 struct QtPixmapMetaData { 138 189 QtPixmapToDataUrlMethod toDataUrlMethod; 190 QtPixmapToImageDataMethod toImageDataMethod; 139 191 QtPixmapAssignToElementMethod assignToElementMethod; 140 192 QtPixmapToStringMethod toStringMethod; … … 199 251 if (identifier == QtPixmapToDataUrlMethod::name()) 200 252 methods.append(&qt_pixmap_metaData.toDataUrlMethod); 253 else if (identifier == QtPixmapToImageDataMethod::name()) 254 methods.append(&qt_pixmap_metaData.toImageDataMethod); 201 255 else if (identifier == QtPixmapAssignToElementMethod::name()) 202 256 methods.append(&qt_pixmap_metaData.assignToElementMethod); … … 218 272 { 219 273 arr.add(Identifier(exec, UString(QtPixmapToDataUrlMethod::name()))); 274 arr.add(Identifier(exec, UString(QtPixmapToImageDataMethod::name()))); 220 275 arr.add(Identifier(exec, UString(QtPixmapAssignToElementMethod::name()))); 221 276 arr.add(Identifier(exec, UString(QtPixmapToStringMethod::name()))); -
trunk/Source/WebKit/qt/ChangeLog
r86981 r87032 1 2011-05-22 Andrew Wason <rectalogic@rectalogic.com> 2 3 Reviewed by Benjamin Poulain. 4 5 [Qt] Implement toImageData() in QtWebKit Bridge 6 https://bugs.webkit.org/show_bug.cgi?id=60897 7 8 * docs/qtwebkit-bridge.qdoc: 9 * docs/webkitsnippets/qtwebkit_bridge_snippets.cpp: 10 (wrapInFunction): 11 Document Qt bridge toImageData() feature. 12 * tests/hybridPixmap/test.html: 13 * tests/hybridPixmap/widget.cpp: 14 (Widget::Widget): 15 (Widget::abcImage): 16 * tests/hybridPixmap/widget.h: 17 Add tests for Qt bridge toImageData() feature. 18 1 19 2011-05-20 Simon Fraser <simon.fraser@apple.com> 2 20 -
trunk/Source/WebKit/qt/docs/qtwebkit-bridge.qdoc
r64621 r87032 364 364 which allows using the pixmap as the \c{src} attribute of an image or as a \c{background-image} URL. Note that the \c{toDataURL()} 365 365 function is costly and should be used with caution. 366 It can also use the \c{toImageData()} function to convert the pixmap to a JavaScript \c{ImageData} object. 366 367 367 368 Example code: -
trunk/Source/WebKit/qt/docs/webkitsnippets/qtwebkit_bridge_snippets.cpp
r64621 r87032 16 16 toDataURL: function() { ... }, 17 17 assignToHTMLImageElement: function(element) { ... } 18 toImageData: function() { ... } 18 19 } 19 20 //! [1] … … 42 43 { 43 44 myObject.myPixmap.assignToHTMLImageElement(document.getElementById("imageElement")); 45 var context = document.getElementById("canvasElement").getContext("2d"); 46 context.putImageData(myObject.myPixmap.toImageData()); 44 47 } 45 48 </script> … … 47 50 <body onload="loadImage()"> 48 51 <img id="imageElement" width="300" height="200" /> 52 <canvas id="canvasElement" width="300" height="200" /> 49 53 </body> 50 54 </html> -
trunk/Source/WebKit/qt/tests/hybridPixmap/test.html
r54986 r87032 5 5 </style> 6 6 <script> 7 function testImageData() { 8 var obj = myWidget.image; 9 var pxm = myWidget.pixmap; 10 11 function compareImageDataSize(o, imageData) { 12 myWidget.compare(imageData.height, o.height); 13 myWidget.compare(imageData.width, o.width); 14 } 15 compareImageDataSize(obj, obj.toImageData()); 16 compareImageDataSize(pxm, pxm.toImageData()); 17 18 function compareImageDataPixel(o, imageData) { 19 compareImageDataSize(o, imageData); 20 // Make sure pixels are 0xAABBCCFF 21 var data = imageData.data; 22 for (var i = 0; i < data.length; i += 4) { 23 myWidget.compare(data[i], 0xaa); // R 24 myWidget.compare(data[i+1], 0xbb); // G 25 myWidget.compare(data[i+2], 0xcc); // B 26 myWidget.compare(data[i+3], 0xff); // A 27 } 28 } 29 var objARGB32 = myWidget.abcImage(5); 30 compareImageDataPixel(objARGB32, objARGB32.toImageData()); 31 var objRGB32 = myWidget.abcImage(4); 32 compareImageDataPixel(objRGB32, objRGB32.toImageData()); 33 var objRGB888 = myWidget.abcImage(13); 34 compareImageDataPixel(objRGB888, objRGB888.toImageData()); 35 var objRGB444 = myWidget.abcImage(14); 36 compareImageDataPixel(objRGB444, objRGB444.toImageData()); 37 } 38 7 39 function startTest() 8 40 { 41 testImageData(); 42 9 43 var obj = myWidget.image; 10 44 var pxm = myWidget.pixmap; -
trunk/Source/WebKit/qt/tests/hybridPixmap/widget.cpp
r53611 r87032 28 28 Widget::Widget(QWidget* parent) : 29 29 QWidget(parent), 30 ui(new Ui::Widget) 30 ui(new Ui::Widget), 31 abcFilledImage(32, 32, QImage::Format_ARGB32) 31 32 { 32 33 ui->setupUi(this); 34 abcFilledImage.fill(qRgba(0xaa, 0xbb, 0xcc, 0xff)); 33 35 } 34 36 … … 81 83 } 82 84 85 QImage Widget::abcImage(int format) 86 { 87 return abcFilledImage.convertToFormat(static_cast<QImage::Format>(format)); 88 } 89 83 90 Widget::~Widget() 84 91 { -
trunk/Source/WebKit/qt/tests/hybridPixmap/widget.h
r74741 r87032 57 57 void pixmapSlot(const QPixmap&); 58 58 void randomSlot(const QPixmap&); 59 QImage abcImage(int format); 59 60 60 61 signals: … … 68 69 private: 69 70 Ui::Widget* ui; 71 QImage abcFilledImage; 70 72 }; 71 73
Note: See TracChangeset
for help on using the changeset viewer.