diff options
author | Charles Yin <charles.yin@nokia.com> | 2012-02-13 10:43:51 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-13 10:27:31 +0100 |
commit | ab84713eb211fdcc2fc63be6860498d4b4186d11 (patch) | |
tree | 587a47368c7944175fa55e5da8254b755390c657 | |
parent | c0100e28cadf8260769eddcc7a0306d832fed92b (diff) |
Remove non-standard canvas filter/mirror functions
They are not standard context 2d APIs, and now the same effects can
be implemented by the ShaderEffect/QtGraphicEffects as well, so remove
them from canvas 2d to reduce the duplicated features.
Change-Id: If77ea6794e839a59927a313702aeea2282384844
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
-rw-r--r-- | examples/declarative/canvas/pixels/pixels.qml | 83 | ||||
-rw-r--r-- | src/quick/items/context2d/qquickcontext2d.cpp | 171 | ||||
-rw-r--r-- | src/quick/items/context2d/qquickcontext2d_p.h | 13 |
3 files changed, 1 insertions, 266 deletions
diff --git a/examples/declarative/canvas/pixels/pixels.qml b/examples/declarative/canvas/pixels/pixels.qml deleted file mode 100644 index bb67eae965..0000000000 --- a/examples/declarative/canvas/pixels/pixels.qml +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import "../contents" -Item { - id:container - width:360 - height:600 - - Column { - spacing:5 - anchors.fill:parent - Text { font.pointSize:25; text:"Processing pixels"; anchors.horizontalCenter:parent.horizontalCenter} - - Canvas { - id:canvas - width:360 - height:360 - smooth:true - renderTarget:Canvas.FramebufferObject - renderStrategy: Canvas.Cooperative - property string image :"../contents/qt-logo.png" - Component.onCompleted:loadImage(image); - onImageLoaded:requestPaint(); - onPaint: { - - var ctx = canvas.getContext('2d'); - if (canvas.isImageLoaded(image)) { - var pixels = ctx.createImageData(image); - //pixels.mirror(); - pixels.filter(ctx.GrayScale); - //pixels.filter(ctx.Threshold, 100); //default 127 - //pixels.filter(ctx.Blur, 20); //default 10 - //pixels.filter(ctx.Opaque); - //pixels.filter(ctx.Invert); - //pixels.filter(ctx.Convolute, [0,-1,0, - // -1,5,-1, - // 0,-1,0]); - //ctx.putImageData(pixels, 0, 0, canvas.width, canvas.height); - ctx.putImageData(pixels, 0, 0); - } - } - } - } -} diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp index 667b55dc63..ba709b7f66 100644 --- a/src/quick/items/context2d/qquickcontext2d.cpp +++ b/src/quick/items/context2d/qquickcontext2d.cpp @@ -2590,166 +2590,6 @@ v8::Handle<v8::Value> ctx2d_imageData_data(v8::Local<v8::String>, const v8::Acce } /*! - \qmlmethod void QtQuick2::CanvasImageData::mirrr( bool horizontal = false, bool vertical = true) - Mirrors the image data in place in the \c horizontal and/or the \c vertical direction depending on - whether horizontal and vertical are set to true or false. - The default \c horizontal value is false, the default \c vertical value is true. -*/ -static v8::Handle<v8::Value> ctx2d_imageData_mirror(const v8::Arguments &args) -{ - bool horizontal = false, vertical = true; - QV8Context2DPixelArrayResource *r = v8_resource_cast<QV8Context2DPixelArrayResource>(args.This()->GetInternalField(0)->ToObject()); - - if (!r) { - //error - return v8::Undefined(); - } - - if (args.Length() > 2) { - //error - return v8::Undefined(); - } - - if (args.Length() == 1) { - horizontal = args[0]->BooleanValue(); - } else if (args.Length() == 2) { - horizontal = args[0]->BooleanValue(); - vertical = args[1]->BooleanValue(); - } - r->image = r->image.mirrored(horizontal, vertical); - return args.This(); -} - -/*! - \qmlmethod void QtQuick2::CanvasImageData::filter(enumeration mode, args) - Filters the image data as defined by one of the following modes: - \list - \o context.Threshold - converts the image to black and white pixels depending - if they are above or below the threshold defined by the level parameter. - The level must be between 0.0 (black) and 1.0(white). - If no level is specified, 0.5 is used. - \o context.Mono - converts the image to the 1-bit per pixel format. - \o context.GrayScale - converts any colors in the image to grayscale equivalents. - \o context.Brightness -increase/decrease a fixed \c adjustment value to each pixel's RGB channel value. - \o context.Invert - sets each pixel to its inverse value. - \o context.Blur - executes a box blur with the pixel \c radius parameter specifying the range of the blurring for each pixel. - the default blur \c radius is 3. This filter also accepts another \c quality parameter, if true, the filter will - execute 3-passes box blur to simulate the Guassian blur. The default \c quality value is false. - \o context.Opaque - sets the alpha channel to entirely opaque. - \o context.Convolute - executes a generic {http://en.wikipedia.org/wiki/Convolution}{Convolution} filter, the second - parameter contains the convoluton matrix data as a number array. - \endlist - -*/ -static v8::Handle<v8::Value> ctx2d_imageData_filter(const v8::Arguments &args) -{ - QV8Context2DPixelArrayResource *r = v8_resource_cast<QV8Context2DPixelArrayResource>(args.This()->GetInternalField(0)->ToObject()); - - if (!r) { - //error - return v8::Undefined(); - } - - if (args.Length() >= 1) { - int filterFlag = args[0]->IntegerValue(); - switch (filterFlag) { - case QQuickContext2D::Mono : - { - r->image = r->image.convertToFormat(QImage::Format_Mono).convertToFormat(QImage::Format_ARGB32_Premultiplied); - } - break; - case QQuickContext2D::GrayScale : - { - for (int y = 0; y < r->image.height(); ++y) { - QRgb *row = (QRgb*)r->image.scanLine(y); - for (int x = 0; x < r->image.width(); ++x) { - unsigned char* rgb = ((unsigned char*)&row[x]); - rgb[0] = rgb[1] = rgb[2] = qGray(rgb[0], rgb[1], rgb[2]); - } - } - } - break; - case QQuickContext2D::Threshold : - { - qreal threshold = 0.5; - if (args.Length() > 1) - threshold = args[1]->NumberValue(); - - for (int y = 0; y < r->image.height(); ++y) { - QRgb *row = (QRgb*)r->image.scanLine(y); - for (int x = 0; x < r->image.width(); ++x) { - unsigned char* rgb = ((unsigned char*)&row[x]); - unsigned char v = qGray(rgb[0], rgb[1], rgb[2]) >= threshold*255 ? 255 : 0; - rgb[0] = rgb[1] = rgb[2] = v; - } - } - } - break; - case QQuickContext2D::Brightness : - { - int adjustment = 1; - if (args.Length() > 1) - adjustment = args[1]->IntegerValue(); - - for (int y = 0; y < r->image.height(); ++y) { - QRgb *row = (QRgb*)r->image.scanLine(y); - for (int x = 0; x < r->image.width(); ++x) { - ((unsigned char*)&row[x])[0] += adjustment; - ((unsigned char*)&row[x])[1] += adjustment; - ((unsigned char*)&row[x])[2] += adjustment; - } - } - } - break; - case QQuickContext2D::Invert : - { - r->image.invertPixels(); - } - break; - case QQuickContext2D::Blur : - { - int radius = 3; - bool quality = false; - - if (args.Length() > 1) - radius = args[1]->IntegerValue() / 2; - if (args.Length() > 2) - quality = args[2]->BooleanValue(); - - qt_image_boxblur(r->image, radius, quality); - } - break; - case QQuickContext2D::Opaque : - { - for (int y = 0; y < r->image.height(); ++y) { - QRgb *row = (QRgb*)r->image.scanLine(y); - for (int x = 0; x < r->image.width(); ++x) { - ((unsigned char*)&row[x])[3] = 255; - } - } - } - break; - case QQuickContext2D::Convolute : - { - if (args.Length() > 1 && args[1]->IsArray()) { - v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(args[1]); - QVector<qreal> weights; - for (uint32_t i = 0; i < array->Length(); ++i) - weights.append(array->Get(i)->NumberValue()); - r->image = qt_image_convolute_filter(r->image, weights); - } else { - //error - } - } - break; - default: - break; - } - } - - return args.This(); -} -/*! \qmlclass QtQuick2::CanvasPixelArray The CanvasPixelArray object provides ordered, indexed access to the color components of each pixel of the image data. The CanvasPixelArray can be accessed as normal Javascript array. @@ -3484,15 +3324,6 @@ QQuickContext2DEngineData::QQuickContext2DEngineData(QV8Engine *engine) ft->PrototypeTemplate()->Set(v8::String::New("getImageData"), V8FUNCTION(ctx2d_getImageData, engine)); ft->PrototypeTemplate()->Set(v8::String::New("putImageData"), V8FUNCTION(ctx2d_putImageData, engine)); - ft->InstanceTemplate()->Set(v8::String::New("Threshold"), v8::Uint32::New(QQuickContext2D::Threshold), v8::ReadOnly); - ft->InstanceTemplate()->Set(v8::String::New("Mono"), v8::Uint32::New(QQuickContext2D::Mono), v8::ReadOnly); - ft->InstanceTemplate()->Set(v8::String::New("GrayScale"), v8::Uint32::New(QQuickContext2D::GrayScale), v8::ReadOnly); - ft->InstanceTemplate()->Set(v8::String::New("Brightness"), v8::Uint32::New(QQuickContext2D::Brightness), v8::ReadOnly); - ft->InstanceTemplate()->Set(v8::String::New("Invert"), v8::Uint32::New(QQuickContext2D::Invert), v8::ReadOnly); - ft->InstanceTemplate()->Set(v8::String::New("Blur"), v8::Uint32::New(QQuickContext2D::Blur), v8::ReadOnly); - ft->InstanceTemplate()->Set(v8::String::New("Opaque"), v8::Uint32::New(QQuickContext2D::Opaque), v8::ReadOnly); - ft->InstanceTemplate()->Set(v8::String::New("Convolute"), v8::Uint32::New(QQuickContext2D::Convolute), v8::ReadOnly); - constructorContext = qPersistentNew(ft->GetFunction()); v8::Local<v8::FunctionTemplate> ftGradient = v8::FunctionTemplate::New(); @@ -3514,8 +3345,6 @@ QQuickContext2DEngineData::QQuickContext2DEngineData(QV8Engine *engine) ftImageData->InstanceTemplate()->SetAccessor(v8::String::New("width"), ctx2d_imageData_width, 0, v8::External::Wrap(engine)); ftImageData->InstanceTemplate()->SetAccessor(v8::String::New("height"), ctx2d_imageData_height, 0, v8::External::Wrap(engine)); ftImageData->InstanceTemplate()->SetAccessor(v8::String::New("data"), ctx2d_imageData_data, 0, v8::External::Wrap(engine)); - ftImageData->PrototypeTemplate()->Set(v8::String::New("mirror"), V8FUNCTION(ctx2d_imageData_mirror, engine)); - ftImageData->PrototypeTemplate()->Set(v8::String::New("filter"), V8FUNCTION(ctx2d_imageData_filter, engine)); ftImageData->InstanceTemplate()->SetInternalFieldCount(1); constructorImageData = qPersistentNew(ftImageData->GetFunction()); } diff --git a/src/quick/items/context2d/qquickcontext2d_p.h b/src/quick/items/context2d/qquickcontext2d_p.h index 6a9c76da57..3cabb6b198 100644 --- a/src/quick/items/context2d/qquickcontext2d_p.h +++ b/src/quick/items/context2d/qquickcontext2d_p.h @@ -55,7 +55,7 @@ -#define QQUICKCONTEXT2D_DEBUG //enable this for just DEBUG purpose! +//#define QQUICKCONTEXT2D_DEBUG //enable this for just DEBUG purpose! #ifdef QQUICKCONTEXT2D_DEBUG #include <QElapsedTimer> @@ -115,17 +115,6 @@ public: GetImageData }; - enum ImageFilterMode { - Threshold, - Mono, - GrayScale, - Brightness, - Invert, - Blur, - Opaque, - Convolute - }; - struct State { State() : strokeStyle(QColor("#000000")) |