ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order...

64
c Filling polygons How to determine the interior of a polygon: Odd parity rule: A point lies inside a polygon if a line starting at the point intersects with an odd number of edges of the polygon. Java 2D provides the method g2d.fill(s); for filling a Shape s. In order to apply the odd parity rule for filling, f.e. a GeneralPath gp, gp.setWindingRule(GeneralPath.WIND_EVEN_ODD); is needed. Computer Graphics: Areas, text and colours – p.1/64

Transcript of ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order...

Page 1: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Fill

ing

po

lyg

on

s

How

tode

term

ine

the

inte

rior

ofa

poly

gon:

Od

dp

arit

yru

le:

Apo

intl

ies

insi

dea

poly

gon

ifa

line

star

ting

atth

epo

inti

nter

sect

sw

ithan

odd

num

ber

ofed

ges

ofth

epo

lygo

n.

Java

2Dpr

ovid

esth

em

etho

dg2d.fill(s);

for

fillin

gaShape

s.

Inor

der

toap

ply

the

odd

parit

yru

lefo

rfil

ling,

f.e.a

GeneralPath

gp

,

gp.setWindingRule(GeneralPath.WIND_EVEN_ODD);

isne

eded

.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.1/

64

Page 2: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Od

dp

arit

yru

le

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

������������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

�����������������

1 (i

nt)

3 (i

nt)

2 (e

xt)

6 (e

xt)

4 (e

xt)

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.2/

64

Page 3: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Fill

ing

po

lyg

on

s

Inor

der

tofil

lapo

lygo

nw

itha

give

nco

lour

,asc

anlin

eis

used

for

each

� -val

uean

dth

epo

ints

tobe

draw

nal

ong

the

scan

line

are

dete

rmin

ed.

1.D

eter

min

eal

lint

erse

ctio

npo

ints

ofth

esc

anlin

ew

ithal

lpol

ygon

edge

s.

2.S

ortt

hein

ters

ectio

npo

ints

inin

crea

sing

orde

rw

.r.t.

thei

r� -c

oord

inat

es.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.3/

64

Page 4: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Fill

ing

po

lyg

on

s

3.A

pply

the

odd

parit

yru

leto

dete

rmin

ew

hich

poin

tslie

insi

deth

epo

lygo

n.

Sta

rtfr

omth

ele

ftw

ithev

enpa

rity.

Jum

pto

the

first

inte

rsec

tion

poin

toft

hesc

anlin

ew

ithth

epo

lygo

n,(c

hang

eth

epa

rity

tood

dan

d)dr

awal

lpix

elun

tilth

ene

xtin

ters

ectio

npo

inti

sre

ache

d.

The

nsk

ipth

epi

xels

until

the

next

inte

rsec

tion

poin

tis

reac

hed.

Dra

wal

lpix

elun

tilth

ene

xtin

ters

ectio

npo

inti

sre

ache

d.

� Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.4/

64

Page 5: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Fill

ing

po

lyg

on

s

Alia

sing

effe

ctoc

curr

ing

whe

nth

inpo

lygo

nsar

efil

led:

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.5/

64

Page 6: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Fill

ing

clo

sed

curv

es

Fill

ing

circ

les,

ellip

ses,

arcs

ofci

rcle

sor

ellip

ses

isdo

nein

the

sam

ew

ay.

Sym

met

rypr

oper

ties

shou

ldbe

expl

oite

dto

redu

ceth

eca

lcul

atio

ns.

Fill

ing

ofar

bitr

ary

clos

edcu

rves

isal

sodo

nein

the

sam

ew

ay.

Whe

nth

ebo

unda

ryof

anar

eais

draw

nus

ing

antia

liasi

ng,t

hepi

xels

belo

ngin

gto

the

edge

are

nolo

nger

uniq

uely

defin

ed.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.6/

64

Page 7: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Text

ure

s

Usi

nga

text

ure

once

orm

ore

than

once

for

fillin

gan

area

.

An

anch

or

mus

tbe

spec

ified

.T

hean

chor

defin

esa

star

ting

poin

tfro

mw

hich

the

text

ure

isla

idlik

etil

es.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.7/

64

Page 8: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Bu

ffer

edIm

ages

ABufferedImage

isan

imag

ein

the

mem

ory

whi

chca

nbe

draw

non

and

whi

chca

nal

sobe

draw

non

anImage

.

BufferedImage

bi

=new

BufferedImage(width,height,

BufferedImage.TYPE_INT_RGB);

Graphics2D

g2dbi

=bi.createGraphics();

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.8/

64

Page 9: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Bu

ffer

edIm

ages

g2dbi.draw(...);

g2dbi.fill(...)

g2d.drawImage(bi,xpos,ypos,null);

drawImage

can

beus

edto

draw

ona

win

dow

oron

aBufferedImage

.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.9/

64

Page 10: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Do

ub

leB

uff

erin

g

Prin

cipl

eof

doub

lebu

fferin

g:U

se

aBufferedImage

theBackground

cont

aini

ngth

est

atic

back

grou

ndth

atw

illno

tcha

nge,

aBufferedImage

theImage

onw

hich

afte

rea

chst

epof

anim

atio

nfir

stth

etheBackground

isdr

awn

and

then

the

anim

ated

obje

cts,

and

aG

raph

ics2

Dob

ject

(as

usua

lg2d

)w

hich

isus

edfo

rdr

awin

gtheImage

onth

ew

indo

w.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.10

/64

Page 11: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Do

ub

leB

uff

erin

g

Win

dow

tobe

draw

nup

on(BufferedImageDrawer

):A

ttrib

utes

:public

BufferedImage

bi;

public

Graphics2D

g2dbi;

Met

hods

:public

void

paint(Graphics

g)

{update(g);

} public

void

update(Graphics

g)

{g2d

=(Graphics2D)

g;

g2d.drawImage(bi,0,0,null);

}C

ompu

ter

Gra

phic

s:A

reas

,tex

tand

colo

urs

–p.

11/6

4

Page 12: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Do

ub

leB

uff

erin

g

Impl

emen

tatio

nof

thes

em

etho

dsin

the

clas

sBufferedImageDrawer

.N

eces

sary

step

s:

Com

puta

tions

take

plac

ein

acl

ass

exte

ndin

gth

eJa

vacl

assTimerTask

.

The

run

met

hod

inth

iscl

ass

cont

ains

the

com

puta

tions

that

wer

epr

evio

usly

done

inth

eF

OR

-loop

ofth

epaint

-Met

hod.

Dra

win

gis

notd

one

with

theGraphics2D

obje

ctof

thepaint

met

hod

ofth

ew

indo

w,b

utw

ithth

eGraphics2D

obje

ctof

the

corr

espo

ndin

gBufferedImage

bi

.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.12

/64

Page 13: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Do

ub

leB

uff

erin

g

Inst

ead

ofcl

earin

gth

edr

awin

gar

ea(p

aint

ing

the

BufferedImage

bi

whi

te)

inea

chst

ep,a

noth

erBufferedImage

cont

aini

ngth

eba

ckgr

ound

isdr

awn

onbi

each

step

.

The

repaint

met

hod

ofth

eBufferedImageDrawer

mus

tbe

calle

dat

the

end

ofth

erun

met

hod.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.13

/64

Page 14: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Do

ub

leB

uff

erin

g

Initi

alis

atio

nsta

kepl

ace

inth

emain

met

hod

and

inth

eco

nstr

ucto

rof

the

spec

ific

clas

s.

The

run

met

hod,

inw

hich

the

sequ

ence

ofim

ages

isco

mpu

ted

and

whi

chin

itiat

esdr

awin

g,is

calle

dre

peat

edly

by

Timer

t=

new

Timer();

t.scheduleAtFixedRate(dbce,0,delay);

(see

DoubleBufferingClockExample.java

)

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.14

/64

Page 15: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Lo

adin

gim

ages

Usi

ng

Image

theImage;

theImage

=new

javax.swing.ImageIcon(

"filename.jpg").getImage();

anim

age

can

belo

aded

.T

his

imag

eca

nbe

draw

nat

the

posi

tion

���

��

usin

g

g2d.drawImage(theImage,x,y,null);

g2d

isth

eG

raph

ics2

Dob

ject

ofth

ew

indo

wor

ofa

BufferedImages

.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.15

/64

Page 16: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Sav

ing

imag

es

Gen

erat

eaBufferedImage

theImage

.

Gen

erat

eth

eco

rres

pond

ing

Gra

phic

s2D

obje

ct:

Graphics2D

g2dImage

=theImage.createGraphics();

Dra

wth

eim

age

(usi

ngg2dImage

).

Gen

erat

eaFileOutputStream

fos

for

the

file

inw

hich

the

imag

esh

ould

best

ored

.

Sto

reth

eim

age

usin

gth

eJPEGImageEncoder

.

(see

ImageSavingExample.java

)

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.16

/64

Page 17: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Sav

ing

imag

es

try

{FileOutputStream

fos

=new

FileOutputStream("test.jpg");

JPEGImageEncoder

jie

=JPEGCodec.createJPEGEncoder(fos);

jie.encode(theImage);

} catch

(Exception

e)

{System.out.println(e);

}

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.17

/64

Page 18: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Text

ure

sin

Java

2D

Usi

nga

text

uretheImage

(for

inst

ance

,obt

aine

dfr

omJP

EG

imag

e)on

ceto

filla

Shape

s:

Shape

clipShape

=g2d.getClip();

g2d.setClip(s);

g2d.drawImage(theImage,50,50,null);

g2d.setClip(clipShape);

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.18

/64

Page 19: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Text

ure

sin

Java

2D

Fill

ing

aShape

sre

peat

edly

with

ate

xtur

etheImage

give

nas

aJP

EG

imag

e:

The

text

ure

mus

tbe

load

edan

ddr

awn

onto

aBufferedImage

buffImage

.

Gen

erat

ea

TexturePaint

tp

=new

TexturePaint(buffImage,

new

Rectangle(0,0,

buffImage.getWidth(),

buffImage.getHeight()));

g2d.setPaint(tp);

g2d.fill(s);

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.19

/64

Page 20: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Text

Lette

rsan

dsy

mbo

lsca

nbe

save

din

two

form

s:

As

abi

tmap

(pix

elm

atrix

)or

inth

efo

rmof

poly

gons

orcu

rves

.

Whe

nbi

tmap

sar

eus

ed,e

ach

sym

bolm

ustb

est

ored

inal

lsiz

esan

dal

lsty

les

(nor

mal

,bol

dfac

e,ita

lic,

bold

face

italic

).A

repr

esen

tatio

nas

poly

gons

orcu

rves

issc

alab

le.

Diff

eren

tsiz

esca

nbe

com

pute

dfr

omon

ere

pres

enta

tion

ofth

ele

tter.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.20

/64

Page 21: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Text

An

old,

sim

ple,

butn

otve

ryni

cete

chni

que

for

gene

ratin

gita

lican

dbo

ldfa

cesy

mbo

lsfr

ombi

tmap

s:

norm

alita

licb

old

face

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.21

/64

Page 22: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Text

inJa

va2D

Dra

win

g/w

ritin

gte

xt:

g2d.drawString("text",posx,posy);

Cho

osin

gth

efo

nt:

Font

f=

new

Font("type",Font.STYLE,size);

Ava

ilabl

efo

nts

(for

type

):Font[]

fl

=GraphicsEnvironment.

getLocalGraphicsEnvironment(

).getAllFonts();

for

(int

i=0;

i<fl.length;

i++)

{System.out.println(fl[i].getName());

}C

ompu

ter

Gra

phic

s:A

reas

,tex

tand

colo

urs

–p.

22/6

4

Page 23: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Text

Val

ues

forSTYLE

:

PLAIN

(nor

mal

)

ITALIC

(ital

ic/s

lant

ed)

BOLD

(bol

dfac

e)

ITALIC

|BOLD

(ital

ican

dbo

ldfa

ce)

size

spec

ifies

the

size

ofth

efo

nt(in

the

unit

pt,n

otin

pixe

ls).

Afte

rca

lling

the

met

hodg2d.setFont(f)

,drawString

isus

ing

the

fontf

.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.23

/64

Page 24: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Mo

dif

yin

gfo

nts

App

lyin

ga

tran

sfor

mat

ionaffTrans

toth

ew

hole

font

:Font

transformedFont

=f.deriveFont(affTrans);

Tran

sfor

mat

ion

ofsi

ngle

sym

bols

ofa

strin

gs

:FontRenderContext

frc

=g2d.getFontRenderContext();

GlyphVector

gv=

f.createGlyphVector(frc,s);

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.24

/64

Page 25: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Mo

dif

yin

gsy

mb

ols

Point2D

p=

gv.getGlyphPosition(i);

Shape

glyph

=gv.getGlyphOutline(i);

Shape

transGlyph

=at.createTransformedShape(glyph);

g2d.fill(transfGlyph);

(see

TextExample.java

)

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.25

/64

Page 26: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Gre

y&

colo

ur

imag

es

Inte

nsi

tyle

vels

for

gre

yo

rco

lou

rva

lues

:

Pix

els

cann

otbe

only

blac

kor

whi

te.

Inst

ead

afin

itenu

mbe

rof

inte

nsity

leve

ls(g

rey-

leve

lsor

inte

nsity

leve

lsfo

rco

lour

s)is

avai

labl

e.

The

hum

anpe

rcep

tion

oflig

htin

tens

ities

ism

ainl

ya

rela

tive

one.

A60

-wat

tlig

htbu

lbis

muc

hbr

ight

erin

com

paris

onto

a20

-wat

tlig

htbu

lbth

ana

100-

wat

tlig

htbu

lbin

com

paris

onto

a60

-wat

tlig

htbu

lb.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.26

/64

Page 27: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Gre

y&

colo

ur

imag

es

The

inte

nsity

leve

lssh

ould

noti

ncre

ase

linea

rly,b

utex

pone

ntia

lly.

Sta

rtin

gfr

omth

elo

wes

tint

ensi

ty((

alm

ost)

blac

kfo

rgr

eyva

lues

)

��� ,th

ele

vels

shou

ldbe

chos

enac

cord

ing

to

� �

�� � �

���

��� � �

���

�����

���� � �

upto

am

axim

umin

tens

ity

���

���� � .

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.27

/64

Page 28: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Gre

y&

colo

ur

imag

es

The

aver

age

hum

anvi

sion

syst

emis

able

todi

stin

guis

hbe

twee

ngr

ey-le

vels

whe

nth

eydi

ffer

byat

leas

t1%

,i.e

.,if

��� �

��

hold

s.

Ass

umin

ga

max

imum

inte

nsity

���

�� an

da

min

imum

inte

nsity

��� ,de

pend

ing

onth

eou

tput

devi

ce,f

rom

� �

���� �

�� �

follo

ws

that

mor

eth

an

��

���� � ��

����

� �

���

grey

-leve

lsw

illno

tcon

trib

ute

tobe

tter

imag

equ

ality

.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.28

/64

Page 29: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Gre

y&

colo

ur

imag

es

Med

ium

���

(ca.

)M

ax.n

o.of

grey

-leve

ls

mon

itor

0.00

5-0.

025

372-

533

new

spap

er0.

123

2ph

oto

0.01

464

slid

e0.

001

695

Ifan

outp

utde

vice

allo

ws

only

bina

rypi

xels

,for

inst

ance

abl

ack-

and-

whi

tela

ser

prin

ter,

diffe

rent

inte

nsity

leve

lsca

nbe

repr

esen

ted

for

the

pric

eof

alo

wer

reso

lutio

n.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.29

/64

Page 30: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Hal

fto

nin

g

Com

bini

ng

�� -P

ixel

toa

larg

erpi

xel,

5in

tens

ityle

vels

can

bere

pres

ente

d.F

or

��

pixe

ls10

,for

��

pixe

ls

��

�� .

The

coar

sene

dre

solu

tion

mus

tstil

lbe

high

enou

ghso

that

the

pixe

lras

ter

isno

tim

med

iate

lyvi

sibl

e.

The

pixe

lsfo

rth

egr

ey-le

vel

shou

ldbe

chos

enin

such

aw

ayth

atth

eyar

ene

ighb

ourin

gpi

xels

and

they

dono

tfor

ma

regu

lar

patte

rnlik

ea

line.

Oth

erw

ise,

this

mig

htin

trod

uce

new

visu

alar

tifac

tslik

est

ripes

inan

area

ofid

entic

alin

tens

ityva

lues

.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.30

/64

Page 31: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Hal

fto

nin

g

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.31

/64

Page 32: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Hal

fto

nin

g

Rep

rese

ntat

ion

bydi

ther

mat

rices

:

� �

���

��

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.32

/64

Page 33: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Hal

fto

nin

g

Asi

mila

rre

finem

entt

echn

ique

can

beap

plie

dw

hen

nonb

inar

yin

tens

ityle

vels

are

avai

labl

ein

the

first

plac

e.F

orin

stan

ce,u

sing

2

� 2pi

xelm

atric

esw

here

each

pixe

lcan

have

four

diffe

rent

inte

nsity

leve

lsyi

elds

13po

ssib

lein

tens

ityle

vels

:

� �

� � �

� �

� � �

� �

� � �

� �

� � �

� �

� � �

� �

� � �

� �

� � �

� �

� � �

� �

� � �

� �

� � �

� �

� � �

� �

� � �

� �

� �

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.33

/64

Page 34: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Co

lou

rm

od

els

The

oret

ical

desc

riptio

nof

aco

lour

:In

tens

ities

inth

eco

lour

spec

trum

.

Mai

nch

arac

teris

tics

ofa

colo

ur:

Hu

eco

rres

pond

ing

toth

edo

min

antw

avel

engt

hin

the

spec

trum

ofth

eco

lour

,

Sat

ura

tio

nor

purit

yw

hich

ishi

ghw

hen

the

spec

trum

cons

ists

ofa

narr

owpe

akat

the

dom

inan

twav

elen

gth,

and

whi

chis

low

for

afla

tter

spec

trum

,and

Inte

nsity

orlig

htn

ess

depe

ndin

gon

the

ener

gyof

the

spec

trum

.T

hehi

gher

the

ener

gyof

the

sing

lefr

eque

ncie

s,th

ehi

gher

isth

ein

tens

ity.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.34

/64

Page 35: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Co

lou

rm

od

els

visi

ble

rang

e:ca

.400

nm(v

iole

t)to

700n

m(r

ed)

Hig

hsa

tura

tion:

Hig

hco

ncen

trat

ion

inth

esp

ectr

um.

400

700

wavelength [nm]

energy

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.35

/64

Page 36: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Co

lou

rm

od

els

Low

satu

ratio

n:W

ide-

spre

adsp

ectr

um.

400

700

wavelength [nm]

energy

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.36

/64

Page 37: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Ad

dit

ive/

sub

trac

tive

colo

ur

mo

del

s

Add

itive

colo

urm

odel

sfo

rlig

ht:

Bla

ck(d

ark)

back

grou

nd

red+

gree

n+bl

ueyi

elds

whi

te.

Exa

mpl

e:m

onito

r

subt

ract

ive

colo

urm

odel

for

colo

urs:

Whi

te(li

ght)

back

grou

nd

red+

gree

n+bl

ueyi

elds

blac

k/da

rkbr

own.

Exa

mpl

e:pr

inte

r

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.37

/64

Page 38: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Th

eR

GB

mo

del

Sta

ndar

dco

lour

mod

elfo

rm

onito

rs:

RG

Bm

od

el.

Eac

hco

lour

isco

mpo

sed

ofth

eth

ree

prim

ary

colo

urs

red,

gree

nan

dbl

ue.

colo

ur

��

����

��

�� ��

whe

re

� ���

��

� � �

� .

� �

� �

��

corr

espo

nds

tobl

ack,

� �

� �

��

isw

hite

,

���

���

��

defin

esa

light

eror

dark

ergr

ey,d

epen

ding

onth

ech

oice

of

� ,

� �

� �

��en

code

sre

d,

� �

� �

��

gree

nan

d

� �

� �

��

blue

.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.38

/64

Page 39: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Th

eR

GB

mo

del

Usu

ally

,for

the

codi

ngof

the

inte

nsity

ofa

colo

ur,o

neby

teis

used

,so

that

each

ofth

epr

imar

yco

lour

sha

s25

6di

ffere

ntle

vels

ofin

tens

ity.

InJa

va2D

,aco

lour

can

bede

fined

usin

gth

eco

nstr

ucto

rs

new

Color(float

r,

float

g,

float

b)

(r,g,b

�� � �

� )or

new

Color(int

r,

int

g,

int

b)

(r,g,b

��

� �

� �

��

���

� ).

Not

ever

yco

lour

can

bere

pres

ente

dw

ithin

the

RG

Bm

odel

.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.39

/64

Page 40: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Th

eC

IEX

YZ

mo

del

For

this

reas

on,t

heC

omm

issi

onIn

tern

atio

nale

del’É

clai

rage

(CIE

)in

trod

uced

am

odel

with

thre

ear

tifici

alco

lour

s

� ,

� and

� whi

chca

nre

pres

enta

nyot

her

colo

ur.

colo

ur

��

��

��

����

��

whe

re

���

� ��

�� � �

� .

How

ever

,find

ing

suita

ble

com

bina

tions

ofth

eth

ree

artifi

cial

colo

urs

tom

odel

ade

sire

dco

lour

isno

tver

yin

tuiti

ve,s

oth

atth

eC

IEX

YZ

mod

elis

seld

omus

ed.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.40

/64

Page 41: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Th

eC

MY

mo

del

The

subt

ract

ive

CM

Ym

odel

isth

edu

alto

the

RG

Bm

odel

and

isus

edfo

rpr

inte

rsan

dpl

otte

rs

The

prim

ary

colo

urs

are

cyan

,mag

enta

and

yello

w.

Red

Green

Blue

B la ck

Yellow

Cya

n

Mag

enta

Wh it e

� � �

�����

� � �

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.41

/64

Page 42: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Th

eC

MY

Km

od

el

The

CM

YK

mod

elus

esbl

ack

(K:k

ey)

asa

four

thco

lour

.

The

CM

YK

mod

elis

the

stan

dard

colo

urm

odel

for

prin

ters

yiel

ding

bette

rco

lour

sth

anth

eC

MY

mod

el.

CM

Y

� CM

YK

���

�� ��

� �

� �

��

� �

� �

� �

� �

���

� �

� Atl

east

one

ofth

efo

urva

lues

� �

� �

� �

� is0.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.42

/64

Page 43: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Th

eY

IQm

od

el

The

YIQ

mod

elis

notb

ased

onth

ree

prim

ary

colo

urs

asin

the

RG

Ban

dth

eC

MY

mod

el,b

utit

uses

the

thre

eco

mpo

nent

s

lum

inan

ce

� and

chro

mat

icit

y

� ,

tode

fine

aco

lour

.

Use

din

the

Am

eric

anN

TS

Cte

levi

sion

norm

.

Col

our

� grey

imag

e:U

seon

lyth

e

� -val

ue.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.43

/64

Page 44: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Th

eY

IQm

od

el

� � �

��

� �

���

� �

���

� �

���

� �

����

� �

����

� �

���

� �

����

� �

���

� �

���

��

� � �

Adv

anta

ges

ofth

eY

IQm

odel

:

Eas

ytr

ansf

orm

atio

nfr

omco

lour

sto

grey

-leve

ls,

dete

rmin

edon

lyby

the

� -val

ue.

Hel

pful

whe

nco

mpu

ter

mon

itors

with

diffe

rent

brig

htne

sssh

ould

bead

just

ed,s

oth

atth

eco

lour

sth

eysh

owar

em

ore

orle

ssth

esa

me

for

iden

tical

RG

Bva

lues

.M

uch

easi

erto

adju

ston

lyth

e

� -val

ueth

anto

adju

stth

eth

ree

valu

es

� ,

� and

atth

esa

me

time.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.44

/64

Page 45: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Th

eH

SV

mo

del

Par

amet

ers:

hue

satu

ratio

n

valu

e

Mod

elin

the

form

ofan

upsi

dedo

wn

pyra

mid

:

Tip

ofth

epy

ram

id:

blac

k.

The

hue

� isgi

ven

byth

ean

gle.

Sat

urat

ion

(

� ):0

inth

em

iddl

e,1

atth

esu

rfac

e.

The

mid

dle

axis

dete

rmin

esth

eva

lue

� .

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.45

/64

Page 46: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Th

eH

SV

mo

del

1.0

White

V

HS (relativ)

0.0

Blue

Cyan

Green

Yellow

Red

Magenta

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.46

/64

Page 47: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Th

eH

LS

mo

del

Sim

ilar

prin

cipl

eas

inth

eH

SV

mod

el.

Hu

e:A

ngle

betw

een

��

and

���� .

Lig

htn

ess:

Val

uebe

twee

n0

and

1.

Sat

ura

tio

n:

Dis

tanc

eof

aco

lour

toth

ece

ntre

(rep

rese

ntin

ggr

eyva

lues

)be

twee

n0

and

1.

For

hue:

Col

our

circ

lew

ithre

dat

�� ,yel

low

at

��� ,

gree

nat

���� ,b

lue

at����

and

viol

etat

���

� .

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.47

/64

Page 48: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Th

eH

LS

mo

del

SH

LWhite

black

grey axis

full

saturation

HS

L

Som

etim

esa

doub

leco

neis

pref

erre

dfo

rth

eH

LSm

odel

.T

hedo

uble

cone

refle

cts

the

fact

that

itdo

esno

tmak

ese

nse

tosp

eak

ofsa

tura

tion

for

the

colo

urs

blac

kan

dw

hite

,whe

ngr

ey-v

alue

sar

eal

read

ych

arac

teris

edby

the

lum

inan

ceva

lue.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.48

/64

Page 49: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Tran

sfo

rmat

ion

fro

mR

GB

toH

LS

max

=Max(R,G,B);

min

=Min(R,G,B);

L=

(max+min)/2;

if

(min==max)

{

S=0;

//H

arbitrary

return;

} mm

=max-min;

if

(L<=0.5)

S=

mm/(max+min);

else

S=

mm/(2-max-min);

r=

(R-min)/mm;

g=

(G-min)/mm;

b=

(B-min)/mm;

if

(R==max)

H=

g-b;

else

{if

(G==max)

H=

2+b-r;

else

H=

4+r-g;}

if

(H<0)

H=H+6;

H=

H*60;

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.49

/64

Page 50: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Per

cep

tio

n-o

rien

ted

colo

ur

mo

del

s

The

HS

Van

dth

eH

LSm

odel

belo

ngto

the

clas

sof

per

cep

tio

n-o

rien

ted

colo

ur

mo

del

ssi

nce

they

refle

ctth

ein

tuiti

vepe

rcep

tion

ofco

lour

sbe

tter.

Spe

cify

ing

the

para

met

ers

ofa

desi

red

colo

uris

easi

erw

ithpe

rcep

tion-

orie

nted

mod

els

than

with

mod

els

like

RG

Bor

CM

Y.

CN

Sis

anot

her

perc

eptio

n-or

ient

edco

lour

mod

el.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.50

/64

Page 51: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Th

eC

NS

mo

del

As

inH

SV

and

HLS

:Col

ours

are

defin

edby

hue

(col

our)

,sat

urat

ion

and

light

ness

.

Inst

ead

ofnu

mbe

rs,w

ords

are

used

for

the

valu

es:

Co

lou

r:pu

rple

,red

,ora

nge,

brow

n,ye

llow

,gre

en,b

lue

(with

furt

her

refin

emen

tslik

eye

llow

ish

gree

n,gr

een-

yello

w,g

reen

ish

yello

w)

Lig

htn

ess:

very

dark

,dar

k,m

ediu

m,l

ight

,ver

ylig

ht

Sat

ura

tio

n:

grey

ish,

mod

erat

e,st

rong

,viv

id

Res

tric

tion

to56

0co

mbi

natio

ns,b

utve

ryin

tuiti

ve.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.51

/64

Page 52: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Java

2D:

Co

lou

rm

od

els

Java

2Dsu

ppor

tsth

efo

llow

ing

colo

urm

odel

s( ColorSpace

type

s):

CIE

XY

Z:TYPEXYZ

RG

B:TYPERGB

Gre

y-va

lue

imag

es:TYPEGRAY

HS

V:TYPEHSV

CM

Y:TYPECMY

CM

YK

:TYPECMYK

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.52

/64

Page 53: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Java

2D:

RG

Bco

lou

rs

RG

Bco

lour

sca

nbe

defin

edw

ithth

eco

nstr

ucto

rnew

Color(

� ).

Pos

sibl

ear

gum

ents

ofth

eco

nstr

ucto

r:

Thr

eefloat

-val

ues

betw

een

0an

d1,

spec

ifyin

gth

ere

d,gr

een

and

blue

inte

nsity

,res

pect

ivel

y.

Thr

eeint

-val

ues

betw

een

0an

d25

5,sp

ecify

ing

the

red,

gree

nan

dbl

uein

tens

ity,r

espe

ctiv

ely.

Asi

ngleint

-val

uein

terp

rete

das

aby

teve

ctor

offo

urva

lues

.T

hree

byte

sar

eus

edfo

rR

GB

,the

four

thon

eas

aso

-cal

led

alph

a-va

lue

whi

chde

fines

how

tran

spar

entt

heco

lour

is.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.53

/64

Page 54: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Java

2D:

RG

Bco

lou

rs

The

met

hodg2d.setPaint(col)

sets

the

draw

ing

colo

urtocol

.

The

clas

sGradientPaint

gradPaint

=new

GradientPaint(x0,y0,colour0,

x1,y1,colour1,

repeat);

allo

ws

colo

urin

terp

olat

ion

inte

rms

ofco

lour

grad

ient

s.

Col

our

inte

rpol

atio

nta

kes

plac

eal

ong

the

vect

orfr

om(x0,y0)

to(x1,y1)

.

The

colour0

isus

edin

poin

t(x0,y0)

,the

colour1

inpo

int(x1,y1)

.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.54

/64

Page 55: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Java

2D:

RG

Bco

lou

rs

RG

B-v

alue

sar

ein

terp

olat

edal

ong

this

vect

orby

corr

espo

ndin

gco

nvex

com

bina

tions

ofcolour0

andcolour1

.(T

hesa

me

appl

ied

tove

ctor

sto

the

spec

ified

vect

or.)

repeat

isa

valu

eof

type

boolean

.

Inca

seoftrue

,the

colo

urgr

adie

ntis

repe

ated

agai

nan

dag

ain,

reve

rsin

gits

dire

ctio

nea

chtim

e.

Inca

seoffalse

,colour0

isus

edbe

fore

the

poin

t (x0,y0)

and

afte

r(x1,y1)

.

Use

:g2d.setPaint(gradPaint);

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.55

/64

Page 56: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Co

lou

rin

terp

ola

tio

n

GradientPaint

inte

rpol

ates

colo

urs

usin

gco

nvex

com

bina

tions

:

� ���

���

� ���

��

� � ��� �

� ��

��

� � ��� �

� ��

�� � �

��

Col

our

inte

rpol

atio

nfo

rte

xtur

esto

avoi

dth

etil

ing

effe

ct:

Inte

rpol

ate

atth

eed

ges,

for

inst

ance

with

afil

ter

mat

rix0.

10.

10.

10.

10.

20.

10.

10.

10.

1

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.56

/64

Page 57: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Co

lou

rin

terp

ola

tio

n

Inte

rpol

ated

colo

urfo

rpi

xel

� �

:

� ���

���

� �

������ �

�� �

� � �

� � �

neig

hbou

rof

� � �

� ����� ����

� ��

Inst

ead

ofa

filte

rm

atrix

larg

erm

atric

esca

nbe

used

.

Dyn

amic

filte

rm

atrix

:A

tthe

edge

,the

abov

efil

ter

mat

rixis

used

.W

ithin

crea

sing

dist

ance

toth

eed

geth

eva

lue

inth

ece

ntre

ofth

em

atrix

tend

sto

1,al

loth

erva

lues

to0.

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.57

/64

Page 58: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Sh

ape

and

colo

ur

inte

rpo

lati

on

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.58

/64

Page 59: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Sh

ape

and

colo

ur

inte

rpo

lati

on

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.59

/64

Page 60: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Sh

ape

and

colo

ur

inte

rpo

lati

on

Con

vex

com

bina

tions

ofth

eve

rtic

esof

corr

espo

ndin

gtr

iang

les

are

com

pute

dto

defin

etr

iang

ulat

ions

for

inte

rpol

ated

imag

es.

Eve

rypi

xel

has

aun

ique

repr

esen

tatio

nfo

rea

chtr

iang

lein

the

form

� ��

� �

� ��

� �

� ��

� �

whe

re

� �

� �

� �

�� �

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.60

/64

Page 61: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Sh

ape

and

colo

ur

inte

rpo

lati

on

lies

insi

deth

etr

iang

le

� ��

� ��

� �

ifan

don

lyif

can

repr

esen

ted

asa

conv

exco

mbi

natio

nof

the

vert

ices

,i.e

.

� ��

� ��

� �

� �

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.61

/64

Page 62: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Sh

ape

and

colo

ur

inte

rpo

lati

on

Inea

chtr

iang

leof

anin

term

edia

teim

age,

the

grey

-or

colo

urva

lue

ofa

pixe

lis

obta

ined

asth

eco

rres

pond

ing

conv

exco

mbi

natio

nof

the

corr

espo

ndin

gtw

opi

xels

inth

ein

itial

and

final

imag

e. initi

alin

term

edia

tefin

altr

iang

le

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.62

/64

Page 63: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Co

lou

rin

terp

ola

tio

nin

Java

2D

Rea

ding

the

colo

urof

api

xel

���

��

ina

BufferedImage

bi

:

int

rgbValue

=bi.getRGB(x,y);

Color

pixelColour

=new

Color(rgbValue);

Com

pute

the

RG

B-v

alue

s:int

red

=pixelColour.getRed();

int

green

=pixelColour.getGreen();

int

blue

=pixelColour.getBlue();

Com

pute

rG

raph

ics:

Are

as,t

exta

ndco

lour

s–

p.63

/64

Page 64: ODD ygons VEN Filling WINklawonn/computergraphics/e-buch/Folien/... · Filling pol ygons In order to fill a polygon with a giv en colour, a scan line is used f or each-v alue and

c

Co

lou

rin

terp

ola

tio

nin

Java

2D

Com

pute

anin

terp

olat

edco

lour

with

RG

B-v

alue

s( rMix,

gMix,

bMix

).

Ass

ign

the

inte

rpol

ated

colo

urto

the

pixe

l

���

��

inth

eBufferedImage

mixedBi

:

Color

mixedColour

=new

Color(rMix,

gMix,

bMix);

mixedBi.setRGB(x,y,pixelColour.getRGB());

(see

MorphingCandS.java

and

TriangulatedImage.java

)C

ompu

ter

Gra

phic

s:A

reas

,tex

tand

colo

urs

–p.

64/6

4