SlideShare a Scribd company logo
Special F/X with Graphics View
                                 09/25/09
Ariya Hidayat
About Myself




   Open-source Developer




                   Ph.D in EE




                                2
Agenda

Four Dot Five
     – What you can do already
Four Dot Six
     – What you can (ab)use soon




                                   3
Goals


Provoke ideas!
Incite passion!
Engage creativity!




                     4
A Word of Caution
   With great power must come great responsibility.




                                                      5
Spread the Love

        All examples are available from...




             labs.qt.nokia.com
            bit.ly/graphicsdojo




                                             6
Qt 4.5


         7
Gradients
Transformation
Animation, Kinetic Scrolling
Composition Modes




                               8
Linear Gradient




                  9
Radial Gradient




                  10
Gradients: Quick Recipe

Applies to: QAbstractGraphicsShapeItem
  QGraphicsEllipseItem, QGraphicsPathItem,
  QGraphicsPolygonItem, QGraphicsRectItem
or your own subclass(es).

Classes to use:
   – QLinearGradient
   – QRadialGradient
   – QConicalGradient


                                             11
Linear Gradient: The Code

QPoint start(0, 0);
QPoint end(0, 20);

QLinearGradient g(start, end);
g.setColorAt(0, Qt::white);
g.setColorAt(1, Qt::black);

item->setBrush(g);




                                 12
Radial Gradient: The Code

QRadialGradient gr(100, 100, 100, 60, 60);
gr.setColorAt(0.0, QColor(255, 255, 255, 191));
gr.setColorAt(0.2, QColor(255, 255, 127, 191));
gr.setColorAt(0.9, QColor(150, 150, 200, 63));
p.setBrush(gr);
p.drawEllipse(0, 0, 200, 200);




                                                  13
Shadow with Gradients




                        magnifier




                                    14
Shadow: The Code
QRadialGradient g;
g.setCenter(radius, radius);
g.setFocalPoint(radius, radius);
g.setRadius(radius);
g.setColorAt(1.0, QColor(255, 255, 255, 0));
g.setColorAt(0.5, QColor(128, 128, 128, 255));

QPainter mask(&maskPixmap);
mask.setCompositionMode
  (QPainter::CompositionMode_Source);
mask.setBrush(g);
mask.drawRect(maskPixmap.rect());
mask.setBrush(QColor(Qt::transparent));
mask.drawEllipse(g.center(), radius-15, radius-15);
mask.end();




                                                      15
Translucent Reflection




                         16
Flip Vertically




             QImage::mirrored()



                                  17
More Natural Look




       Linear gradient, on the alpha channel



                                               18
Reflection: The Code
QPoint start(0, 0);
QPoint end(0, img.height());
QLinearGradient gradient(start, end);
gradient.setColorAt(0.5, Qt::black);
gradient.setColorAt(0, Qt::white);

QImage mask = img;
QPainter painter(&mask);
painter.fillRect(img.rect(), gradient);
painter.end();

QImage reflection = img.mirrored();
reflection.setAlphaChannel(mask);

                                          19
Opacity




          QPainter::setOpacity(...)



                                      20
Transformation



           Scaling   Rotation   Perspective




                                              21
Rotation

           transform.rotate(30, Qt::ZAxis)




                                             22
Perspective Transformation: The Recipe



transform.rotate
(60, Qt::XAxis)




                   transform.rotate(60, Qt::YAxis)


                                                     23
Reflection & Transformation




                              24
Timeline-based Animation




                              deacceleration




               acceleration

                                               25
Linear Motion vs Non-linear Motion


      Linear    EaseInOut
                                       deacceleration




                            acceleration

                                                    26
Flick List (or Kinetic Scrolling)




                                    27
Using FlickCharm

QGraphicsView canvas;

FlickCharm charm;
charm.activateOn(&canvas);




                             28
Flick Charm & Event Filtering

                                             Mouse move
 Mouse press            Pressed

                                             Manual Scroll
               Mouse release
  Steady                                 Mouse release

                    Mouse
                    move                      Auto Scroll
                               Mouse press
                    Stop
                                                  Timer tick


                                                               29
Parallax Effect




                  30
Composition Modes




                    31
Colorize (or Tint Effect)




                            32
Grayscale Conversion




int pixels = img.width() * img.height();
unsigned int *data = (unsigned int *)img.bits();
for (int i = 0; i < pixels; ++i) {
    int val = qGray(data[i]);
    data[i] = qRgb(val, val, val);
}


                                                   33
Overlay with Color




QPainter painter(&resultImage);
painter.drawImage(0, 0, grayscaled(image));
painter.setCompositionMode
  (QPainter::CompositionMode_Overlay);
painter.fillRect(resultImage.rect(), color);
painter.end();


                                               34
Glow Effect




              35
Night Mode




             36
Night Mode with Color Inversion

QPainter p(this);
p.setCompositionMode
  (QPainter::CompositionMode_Difference);
p.fillRect(event->rect(), Qt::white);
p.end();

               red = 255 – red
            green = 255 – green
              blue = 255 - blue




                                            37
A Friendly Advice: Fast Prototyping


  – avoid long edit-compile-debug cycle
  – use JavaScript, e.g. with Qt Script
  – use Python, e.g. with PyQt or PySide
  – use <insert your favorite dynamic language>




                                                  38
Qt 4.6


         39
Animation Framework
State Machine
Graphics Effects




                      40
Animation Framework




                      41
What People Want


 – (soft) drop shadow
 – blur
 – colorize
 – some other random stuff




                             42
Graphics F/X

  QGraphicsEffect

  QGraphicsColorizeEffect
  QGraphicsGrayscaleEffect
  QGraphicsPixelizeEffect
  QGraphicsBlurEffect
  QGraphicsDropShadowEffect
  QGraphicsOpacityEffect




                              43
Challenges


 – software vs hardware
 – good API




                          44
Software vs Hardware


  – software implementation
     • consistent and reliable
     • easy to test
     • cumbersome, (dog)slow
  – hardware acceleration
     • blazing fast
     • custom effects are easy
     • silicon/driver dependent



                                  45
API
      One API to rule them all, ...




                                      46
Simple API


  – Effect is a QObject
     • might have property, e.g. Color
     • property change emits a signal
     • can be animated easily
  – Effect applies to QGraphicsItem & QWidget
  – Custom effect? Subclass QGraphicsEffect




                                                47
As Simple As...

QGraphicsGrayscaleEffect *effect;
effect = new QGraphicsGrayscaleEffect;
item->setGraphicsEffect(effect);




           Effect is applied to the item
                 and its children!




                                           48
Grayscale Effect




                   49
Grayscale Effect with Strength=0.8




                                     50
Colorize Effect




                  51
Colorize Effect with Strength=0.8




                                    52
Pixelize Effect




                  53
Blur Effect




              54
Drop Shadow Effect




                     55
Lighting Example




                   56
Blur Picker Example



                      blurry




             sharp


                               57
Fade Message Example




          Something will happen
                                  58
Scale Effect




               59
Scale Effect Implementation
void draw(QPainter *painter,
          QGraphicsEffectSource *source) {

    QPixmap pixmap;
    pixmap = source->pixmap(Qt::DeviceCoordinates);

    painter->save();
    painter->setBrush(Qt::NoBrush);
    painter->setPen(Qt::red);
    painter->drawRect(pixmap.rect());

    painter->scale(0.5, 0.5);
    painter->translate(pixmap.rect().bottomRight()/2);
    painter->drawPixmap(0, 0, pixmap);

    painter->restore();
}


                                                         60
Night Mode Effect




                    61
Night Mode Effect Implementation

void draw(QPainter *painter,
          QGraphicsEffectSource *source) {

    QPixmap pixmap;
    pixmap = source->pixmap(Qt::DeviceCoordinates);

    QPainter p(&pixmap);
    p.setCompositionMode
      (QPainter::CompositionMode_Difference);
    p.fillRect(pixmap.rect(), Qt::white);
    p.end();
    painter->drawPixmap(0, 0, pixmap);
}




                                                      62
Frame Effect




               63
Extending the Bounding Box

QRectF boundingRectFor(const QRectF &rect) const {
  return rect.adjusted(-5, -5, 5, 5);
}




         item bounding box



    “effective” bounding box




                                                     64
Frame Effect Implementation

void draw(QPainter *painter,
          QGraphicsEffectSource *source) {

    QPixmap pixmap;
    pixmap = source->pixmap(Qt::DeviceCoordinates);
    QRectF bound = boundingRectFor(pixmap.rect());

    painter->save();
    painter->setPen(Qt::NoPen);
    painter->setBrush(Qt::green);
    painter->drawRoundedRect(bound, 15, 15);
    painter->drawPixmap(0, 0, pixmap);
    painter->restore();
}




                                                      65
Reflection Effect




                    66
Enlarging the Bounding Box (Again)

QRectF boundingRectFor(const QRectF &rect) const {
  return rect.adjusted(0, 0, 0, rect.height());
}




             item bounding box




       “effective” bounding box




                                                     67
Reflection Effect Implementation

void draw(QPainter *painter,
          QGraphicsEffectSource *source) {

    QPixmap pixmap;
    pixmap = source->pixmap(Qt::DeviceCoordinates);

    painter->save();
    painter->drawPixmap(0, 0, pixmap);
    painter->setOpacity(0.2);
    painter->scale(1, -1);
    painter->translate(0, -pixmap.height());
    painter->drawPixmap(0, 0, pixmap);
    painter->restore();
}




                                                      68
Qt 4.7?
Future?
          69
Declarative UI




                 70
Further Directions


  – Optimization!
  – Composite effects
  – Geometry deformation
  – Morphing
  – More physics: force, gravity, ...
  – Bitmap vs vector




                                        71
Genie Effect




               72
Deformation




              73
Underwater Effect




                    74
That's all, folks...




        Thank You!


                       75
Bleeding-Edge




           labs.qt.nokia.com
           bit.ly/graphicsdojo




                                 76

More Related Content

PDF
Agile Testing – embedding testing into agile software development lifecycle
PPTX
ちょっと使えるようになる信頼度成長曲線(移行済)
PPTX
[DL輪読会]Live-Streaming Fraud Detection: A Heterogeneous Graph Neural Network A...
PDF
Azure machine learning service 最新の機械学習プラットフォーム
PPTX
Bug reporting and tracking
PDF
VSlam 2017 11_20(張閎智)
PDF
Factorization machines with r
PPTX
Mastering Atari, Go, Chess and Shogi by Planning with a Learned Model (MuZero)
Agile Testing – embedding testing into agile software development lifecycle
ちょっと使えるようになる信頼度成長曲線(移行済)
[DL輪読会]Live-Streaming Fraud Detection: A Heterogeneous Graph Neural Network A...
Azure machine learning service 最新の機械学習プラットフォーム
Bug reporting and tracking
VSlam 2017 11_20(張閎智)
Factorization machines with r
Mastering Atari, Go, Chess and Shogi by Planning with a Learned Model (MuZero)

What's hot (20)

PDF
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
PDF
ドキュメントを作りたくなってしまう魔法のツール「Sphinx」
PDF
OpenAPI 3.0でmicroserviceのAPI定義を試みてハマった話
PDF
なぜGPUはディープラーニングに向いているか
PDF
機械学習品質マネジメントプロジェクトのご紹介
PDF
Jenkinsfileのlintで救える命がある
PPTX
input type = password autocomplete = off は使ってはいけない
PPTX
Guide to Agile testing
PPT
Difference between functional testing and non functional testing
PDF
ジャストシステムJava100本ノックのご紹介
PDF
MoveItの新機能、 OMPL Constrained Planningを試してみた
PDF
Behavior Driven Development and Automation Testing Using Cucumber
PDF
シナリオテストについて考えてみる
PPTX
Introduction to Deep Learning
PDF
だいたい30分で分かるオブジェクト指向
PDF
見えない壁を越えよう!アジャイルやマイクロサービスを阻む「今までのやり方」 - デブサミ夏2023
PDF
小さなサービスも契約する時代
PDF
2022年度秋学期 画像情報処理 第10回 Radon変換と投影切断面定理 (2022. 12. 2)
PPTX
Manual Testing tutorials and Interview Questions.pptx
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
ドキュメントを作りたくなってしまう魔法のツール「Sphinx」
OpenAPI 3.0でmicroserviceのAPI定義を試みてハマった話
なぜGPUはディープラーニングに向いているか
機械学習品質マネジメントプロジェクトのご紹介
Jenkinsfileのlintで救える命がある
input type = password autocomplete = off は使ってはいけない
Guide to Agile testing
Difference between functional testing and non functional testing
ジャストシステムJava100本ノックのご紹介
MoveItの新機能、 OMPL Constrained Planningを試してみた
Behavior Driven Development and Automation Testing Using Cucumber
シナリオテストについて考えてみる
Introduction to Deep Learning
だいたい30分で分かるオブジェクト指向
見えない壁を越えよう!アジャイルやマイクロサービスを阻む「今までのやり方」 - デブサミ夏2023
小さなサービスも契約する時代
2022年度秋学期 画像情報処理 第10回 Radon変換と投影切断面定理 (2022. 12. 2)
Manual Testing tutorials and Interview Questions.pptx
Ad

Viewers also liked (19)

PDF
Efficient Graphics with Qt
PDF
Qt Animation
PDF
Creating Slick User Interfaces With Qt
PDF
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
PDF
How to Make Your Qt App Look Native
PDF
Optimizing Performance in Qt-Based Applications
PPTX
Vfx PPT
PDF
05 - Qt External Interaction and Graphics
PPT
Qt Programming on TI Processors
PDF
06 - Qt Communication
PPT
#3 sp effects
PPTX
Counselors training on VFX pro
PPT
Using Graphics and Visual Media in Instruction
PPTX
Special effects vocabulary
PPT
Graphic organizers
PPT
Special effects
PPTX
Intro to Exam
PPTX
Midnight ride paul revere spelling lesson
PPTX
Special effects f tv vocab lesson
Efficient Graphics with Qt
Qt Animation
Creating Slick User Interfaces With Qt
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
How to Make Your Qt App Look Native
Optimizing Performance in Qt-Based Applications
Vfx PPT
05 - Qt External Interaction and Graphics
Qt Programming on TI Processors
06 - Qt Communication
#3 sp effects
Counselors training on VFX pro
Using Graphics and Visual Media in Instruction
Special effects vocabulary
Graphic organizers
Special effects
Intro to Exam
Midnight ride paul revere spelling lesson
Special effects f tv vocab lesson
Ad

Similar to Special Effects with Qt Graphics View (20)

PDF
Copy Your Favourite Nokia App with Qt
PPTX
Computer Graphics
PPT
Animation Framework: A Step Towards Modern UIs
PPS
AKS: Image Enhancement Software
PDF
Petri Niemi Qt Advanced Part 1
PDF
Graphicsand animations devoxx2010 (1)
PPT
Paris Master Class 2011 - 05 Post-Processing Pipeline
PDF
Diagonal Pixel Report
PPTX
Deep Dive into Microsoft Silverlight Graphics
PDF
Redefining Mobile Graphics Stack
PDF
Chameleon game engine
PDF
Understanding Hardware Acceleration on Mobile Browsers
PPT
Lec-1 Computer Graphics.ppt
PPT
Image processing techniques 1
PPT
GTC 2012: GPU-Accelerated Path Rendering
PDF
Edge detection-based post-processing in Warlords of Draenor
PPT
chapter images multimedia subject to make.ppt
PDF
Fun with silverlight4 Table of Content @iRajLal
KEY
Visual Experiences with flex 4
PDF
Introduction to QtWebKit
Copy Your Favourite Nokia App with Qt
Computer Graphics
Animation Framework: A Step Towards Modern UIs
AKS: Image Enhancement Software
Petri Niemi Qt Advanced Part 1
Graphicsand animations devoxx2010 (1)
Paris Master Class 2011 - 05 Post-Processing Pipeline
Diagonal Pixel Report
Deep Dive into Microsoft Silverlight Graphics
Redefining Mobile Graphics Stack
Chameleon game engine
Understanding Hardware Acceleration on Mobile Browsers
Lec-1 Computer Graphics.ppt
Image processing techniques 1
GTC 2012: GPU-Accelerated Path Rendering
Edge detection-based post-processing in Warlords of Draenor
chapter images multimedia subject to make.ppt
Fun with silverlight4 Table of Content @iRajLal
Visual Experiences with flex 4
Introduction to QtWebKit

More from account inactive (20)

ODP
PDF
KDE Plasma for Mobile Phones
PDF
Shipping Mobile Applications Using Qt for Symbian
PDF
The Future of Qt Widgets
PDF
Scripting Your Qt Application
PDF
Developments in The Qt WebKit Integration
PDF
Qt Kwan-Do
PDF
Qt on Real Time Operating Systems
PDF
Development with Qt for Windows CE
PDF
Translating Qt Applications
PDF
Qt Creator Bootcamp
PDF
Qt Widget In-Depth
PDF
Qt State Machine Framework
PDF
Mobile Development with Qt for Symbian
PDF
Using Multi-Touch and Gestures with Qt
PDF
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)
PDF
The Mobility Project
PDF
The Next Generation Qt Item Views
PDF
Qt Licensing Explained
PDF
Case Study: Porting Qt for Embedded Linux on Embedded Processors
KDE Plasma for Mobile Phones
Shipping Mobile Applications Using Qt for Symbian
The Future of Qt Widgets
Scripting Your Qt Application
Developments in The Qt WebKit Integration
Qt Kwan-Do
Qt on Real Time Operating Systems
Development with Qt for Windows CE
Translating Qt Applications
Qt Creator Bootcamp
Qt Widget In-Depth
Qt State Machine Framework
Mobile Development with Qt for Symbian
Using Multi-Touch and Gestures with Qt
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)
The Mobility Project
The Next Generation Qt Item Views
Qt Licensing Explained
Case Study: Porting Qt for Embedded Linux on Embedded Processors

Recently uploaded (20)

PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Encapsulation theory and applications.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
KodekX | Application Modernization Development
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Understanding_Digital_Forensics_Presentation.pptx
Chapter 3 Spatial Domain Image Processing.pdf
cuic standard and advanced reporting.pdf
Machine learning based COVID-19 study performance prediction
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Encapsulation theory and applications.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
Advanced methodologies resolving dimensionality complications for autism neur...
20250228 LYD VKU AI Blended-Learning.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectroscopy.pptx food analysis technology
KodekX | Application Modernization Development
“AI and Expert System Decision Support & Business Intelligence Systems”
Agricultural_Statistics_at_a_Glance_2022_0.pdf

Special Effects with Qt Graphics View