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
Cross Platform Qt
account inactive
 
PPT
Animation Framework: A Step Towards Modern UIs
account inactive
 
PDF
Scripting Your Qt Application
account inactive
 
PDF
Using Multi-Touch and Gestures with Qt
account inactive
 
PDF
Efficient Graphics with Qt
Ariya Hidayat
 
PDF
Copy Your Favourite Nokia App with Qt
account inactive
 
PDF
Qt Widget In-Depth
account inactive
 
PDF
Petri Niemi Qt Advanced Part 2
NokiaAppForum
 
Cross Platform Qt
account inactive
 
Animation Framework: A Step Towards Modern UIs
account inactive
 
Scripting Your Qt Application
account inactive
 
Using Multi-Touch and Gestures with Qt
account inactive
 
Efficient Graphics with Qt
Ariya Hidayat
 
Copy Your Favourite Nokia App with Qt
account inactive
 
Qt Widget In-Depth
account inactive
 
Petri Niemi Qt Advanced Part 2
NokiaAppForum
 

What's hot (19)

PDF
Qt on Real Time Operating Systems
account inactive
 
PDF
Qt State Machine Framework
account inactive
 
PDF
Petri Niemi Qt Advanced Part 1
NokiaAppForum
 
PDF
Qt Animation
William Lee
 
PDF
Qt Graphics View Framework (Qt Developers Meetup Isreal)
vitalipe
 
PDF
05 - Qt External Interaction and Graphics
Andreas Jakl
 
PDF
The Next Generation Qt Item Views
account inactive
 
PDF
Qt multi threads
Ynon Perek
 
PDF
QThreads: Are You Using Them Wrong?
ICS
 
PDF
Open gl
EU Edge
 
PDF
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
ICS
 
PPTX
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
ICS
 
PPT
Qt Programming on TI Processors
Prabindh Sundareson
 
PDF
Graphics programming in open gl
Arvind Devaraj
 
PDF
The Future of Qt Widgets
Marius Bugge Monsen
 
PDF
A Brief Introduction to the Qt Application Framework
Zachary Blair
 
PDF
Necessitas - Qt on Android - from FSCONS 2011
Johan Thelin
 
PDF
State of the Art OpenGL and Qt
ICS
 
ODP
Qt Workshop
Johan Thelin
 
Qt on Real Time Operating Systems
account inactive
 
Qt State Machine Framework
account inactive
 
Petri Niemi Qt Advanced Part 1
NokiaAppForum
 
Qt Animation
William Lee
 
Qt Graphics View Framework (Qt Developers Meetup Isreal)
vitalipe
 
05 - Qt External Interaction and Graphics
Andreas Jakl
 
The Next Generation Qt Item Views
account inactive
 
Qt multi threads
Ynon Perek
 
QThreads: Are You Using Them Wrong?
ICS
 
Open gl
EU Edge
 
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
ICS
 
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
ICS
 
Qt Programming on TI Processors
Prabindh Sundareson
 
Graphics programming in open gl
Arvind Devaraj
 
The Future of Qt Widgets
Marius Bugge Monsen
 
A Brief Introduction to the Qt Application Framework
Zachary Blair
 
Necessitas - Qt on Android - from FSCONS 2011
Johan Thelin
 
State of the Art OpenGL and Qt
ICS
 
Qt Workshop
Johan Thelin
 
Ad

Viewers also liked (15)

PDF
Creating Slick User Interfaces With Qt
Espen Riskedal
 
PDF
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
account inactive
 
PDF
How to Make Your Qt App Look Native
account inactive
 
PDF
Optimizing Performance in Qt-Based Applications
account inactive
 
PPTX
Vfx PPT
Mit Shah
 
PDF
06 - Qt Communication
Andreas Jakl
 
PPT
#3 sp effects
kkirschbaum
 
PPTX
Counselors training on VFX pro
Sagar Kapoor
 
PPT
Using Graphics and Visual Media in Instruction
CARLOS MARTINEZ
 
PPTX
Special effects vocabulary
sathornton
 
PPT
Graphic organizers
autumnschaffer
 
PPT
Special effects
simarjeet
 
PPTX
Intro to Exam
johnbranney
 
PPTX
Midnight ride paul revere spelling lesson
angiearriolac
 
PPTX
Special effects f tv vocab lesson
angiearriolac
 
Creating Slick User Interfaces With Qt
Espen Riskedal
 
Case Study: Using Qt to Develop Advanced GUIs & Advanced Visualization Software
account inactive
 
How to Make Your Qt App Look Native
account inactive
 
Optimizing Performance in Qt-Based Applications
account inactive
 
Vfx PPT
Mit Shah
 
06 - Qt Communication
Andreas Jakl
 
#3 sp effects
kkirschbaum
 
Counselors training on VFX pro
Sagar Kapoor
 
Using Graphics and Visual Media in Instruction
CARLOS MARTINEZ
 
Special effects vocabulary
sathornton
 
Graphic organizers
autumnschaffer
 
Special effects
simarjeet
 
Intro to Exam
johnbranney
 
Midnight ride paul revere spelling lesson
angiearriolac
 
Special effects f tv vocab lesson
angiearriolac
 
Ad

Similar to Special Effects with Qt Graphics View (20)

PPTX
Computer Graphics
Adri Jovin
 
PPS
AKS: Image Enhancement Software
Abhimanyu Singh
 
PDF
Graphicsand animations devoxx2010 (1)
Marakana Inc.
 
PPT
Paris Master Class 2011 - 05 Post-Processing Pipeline
Wolfgang Engel
 
PDF
Diagonal Pixel Report
San Man
 
PPTX
Deep Dive into Microsoft Silverlight Graphics
goodfriday
 
PDF
Redefining Mobile Graphics Stack
ofilabs
 
PDF
Chameleon game engine
Victor Porof
 
PDF
Understanding Hardware Acceleration on Mobile Browsers
Ariya Hidayat
 
PPT
Lec-1 Computer Graphics.ppt
MNSUAM
 
PPT
Image processing techniques 1
1988sreejith
 
PPT
GTC 2012: GPU-Accelerated Path Rendering
Mark Kilgard
 
PDF
Edge detection-based post-processing in Warlords of Draenor
Gael Hofemeier
 
PPT
chapter images multimedia subject to make.ppt
StephenCajelo1
 
PDF
Fun with silverlight4 Table of Content @iRajLal
Raj Lal
 
KEY
Visual Experiences with flex 4
Saurabh Narula
 
PDF
Introduction to QtWebKit
Ariya Hidayat
 
PPTX
Witekio custom modern qt quick components
Witekio
 
PPTX
Developing Next-Generation Games with Stage3D (Molehill)
Jean-Philippe Doiron
 
Computer Graphics
Adri Jovin
 
AKS: Image Enhancement Software
Abhimanyu Singh
 
Graphicsand animations devoxx2010 (1)
Marakana Inc.
 
Paris Master Class 2011 - 05 Post-Processing Pipeline
Wolfgang Engel
 
Diagonal Pixel Report
San Man
 
Deep Dive into Microsoft Silverlight Graphics
goodfriday
 
Redefining Mobile Graphics Stack
ofilabs
 
Chameleon game engine
Victor Porof
 
Understanding Hardware Acceleration on Mobile Browsers
Ariya Hidayat
 
Lec-1 Computer Graphics.ppt
MNSUAM
 
Image processing techniques 1
1988sreejith
 
GTC 2012: GPU-Accelerated Path Rendering
Mark Kilgard
 
Edge detection-based post-processing in Warlords of Draenor
Gael Hofemeier
 
chapter images multimedia subject to make.ppt
StephenCajelo1
 
Fun with silverlight4 Table of Content @iRajLal
Raj Lal
 
Visual Experiences with flex 4
Saurabh Narula
 
Introduction to QtWebKit
Ariya Hidayat
 
Witekio custom modern qt quick components
Witekio
 
Developing Next-Generation Games with Stage3D (Molehill)
Jean-Philippe Doiron
 

More from account inactive (19)

ODP
Meet Qt
account inactive
 
PDF
KDE Plasma for Mobile Phones
account inactive
 
PDF
Shipping Mobile Applications Using Qt for Symbian
account inactive
 
PDF
The Future of Qt Widgets
account inactive
 
PDF
Developments in The Qt WebKit Integration
account inactive
 
PDF
Qt Kwan-Do
account inactive
 
PDF
Development with Qt for Windows CE
account inactive
 
PDF
Translating Qt Applications
account inactive
 
PDF
Qt Creator Bootcamp
account inactive
 
PDF
Mobile Development with Qt for Symbian
account inactive
 
PDF
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)
account inactive
 
PDF
The Mobility Project
account inactive
 
PDF
Qt Licensing Explained
account inactive
 
PDF
Case Study: Porting Qt for Embedded Linux on Embedded Processors
account inactive
 
PDF
OGRE: Qt & OGRE for Multimedia Creation
account inactive
 
PDF
HGZ Kaffeemaschinen & Qt Speak Coffee
account inactive
 
PDF
Discover Qt Learning and Certification
account inactive
 
PDF
Accelerating performance on Qt and WebKit for the MIPS architecture
account inactive
 
PDF
Qt Experiences on NXP's Connetcted TV Platforms
account inactive
 
KDE Plasma for Mobile Phones
account inactive
 
Shipping Mobile Applications Using Qt for Symbian
account inactive
 
The Future of Qt Widgets
account inactive
 
Developments in The Qt WebKit Integration
account inactive
 
Qt Kwan-Do
account inactive
 
Development with Qt for Windows CE
account inactive
 
Translating Qt Applications
account inactive
 
Qt Creator Bootcamp
account inactive
 
Mobile Development with Qt for Symbian
account inactive
 
Debugging Qt, Fixing and Contributing a Bug Report (Using Gitorious)
account inactive
 
The Mobility Project
account inactive
 
Qt Licensing Explained
account inactive
 
Case Study: Porting Qt for Embedded Linux on Embedded Processors
account inactive
 
OGRE: Qt & OGRE for Multimedia Creation
account inactive
 
HGZ Kaffeemaschinen & Qt Speak Coffee
account inactive
 
Discover Qt Learning and Certification
account inactive
 
Accelerating performance on Qt and WebKit for the MIPS architecture
account inactive
 
Qt Experiences on NXP's Connetcted TV Platforms
account inactive
 

Recently uploaded (20)

PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 

Special Effects with Qt Graphics View