Resolve bugs

This commit is contained in:
Laurent Le Goff 2011-09-29 09:46:16 +02:00
parent 94ad4b370e
commit afad20dce7
31 changed files with 19 additions and 17 deletions

View file

@ -1,7 +1,7 @@
include $(GOROOT)/src/Make.inc include $(GOROOT)/src/Make.inc
TARG=gettingStarted testdraw2d testX11draw testandroid testgopher testimage testpostscript draw2dgl TARG=gettingStarted testdraw2d testX11draw testandroid testgopher testimage testpostscript #draw2dgl
OFILES=$(TARG:%=%.$O) OFILES=$(TARG:%=%.$O)

View file

@ -37,7 +37,7 @@ func saveToPngFile(filePath string, m image.Image) {
} }
func main() { func main() {
i := image.NewRGBA(200, 200) i := image.NewRGBA(image.Rect(0,0,200, 200))
gc := draw2d.NewGraphicContext(i) gc := draw2d.NewGraphicContext(i)
gc.MoveTo(10.0, 10.0) gc.MoveTo(10.0, 10.0)
gc.LineTo(100.0, 10.0) gc.LineTo(100.0, 10.0)

View file

@ -2,8 +2,8 @@ package main
import ( import (
"fmt" "fmt"
"image/draw" "exp/gui"
"image/draw/x11" "exp/gui/x11"
"image" "image"
"math" "math"
"draw2d.googlecode.com/hg/draw2d" "draw2d.googlecode.com/hg/draw2d"
@ -37,11 +37,11 @@ func main() {
for { for {
switch evt := (<-window.EventChan()).(type) { switch evt := (<-window.EventChan()).(type) {
case draw.KeyEvent: case gui.KeyEvent:
if evt.Key == 'q' { if evt.Key == 'q' {
window.Close() window.Close()
} }
case draw.MouseEvent: case gui.MouseEvent:
if evt.Buttons&1 != 0 { if evt.Buttons&1 != 0 {
if nbclick%2 == 0 { if nbclick%2 == 0 {
gc.MoveTo(float64(evt.Loc.X), float64(evt.Loc.Y)) gc.MoveTo(float64(evt.Loc.X), float64(evt.Loc.Y))

View file

@ -24,7 +24,7 @@ var (
) )
func initGc(w, h int) (image.Image, draw2d.GraphicContext) { func initGc(w, h int) (image.Image, draw2d.GraphicContext) {
i := image.NewRGBA(w, h) i := image.NewRGBA(image.Rect(0, 0,w, h))
gc := draw2d.NewGraphicContext(i) gc := draw2d.NewGraphicContext(i)
lastTime = time.Nanoseconds() lastTime = time.Nanoseconds()

View file

@ -26,7 +26,7 @@ var (
) )
func initGc(w, h int) (image.Image, draw2d.GraphicContext) { func initGc(w, h int) (image.Image, draw2d.GraphicContext) {
i := image.NewRGBA(w, h) i := image.NewRGBA(image.Rect(0, 0, w, h))
gc := draw2d.NewGraphicContext(i) gc := draw2d.NewGraphicContext(i)
lastTime = time.Nanoseconds() lastTime = time.Nanoseconds()

View file

@ -24,7 +24,7 @@ var (
) )
func initGc(w, h int) (image.Image, draw2d.GraphicContext) { func initGc(w, h int) (image.Image, draw2d.GraphicContext) {
i := image.NewRGBA(w, h) i := image.NewRGBA(image.Rect(0, 0, w, h))
gc := draw2d.NewGraphicContext(i) gc := draw2d.NewGraphicContext(i)
lastTime = time.Nanoseconds() lastTime = time.Nanoseconds()

View file

@ -55,7 +55,7 @@ func loadFromPngFile(filePath string) image.Image {
func main() { func main() {
source := loadFromPngFile("../resource/image/TestAndroid.png") source := loadFromPngFile("../resource/image/TestAndroid.png")
dest := image.NewRGBA(1024, 768) dest := image.NewRGBA(image.Rect(0, 0, 1024, 768))
width, height := float64(source.Bounds().Dx()), float64(source.Bounds().Dy()) width, height := float64(source.Bounds().Dx()), float64(source.Bounds().Dy())
tr := draw2d.NewIdentityMatrix() tr := draw2d.NewIdentityMatrix()
tr.Translate(width/2, height/2) tr.Translate(width/2, height/2)

View file

@ -38,7 +38,7 @@ func saveToPngFile(filePath string, m image.Image) {
} }
func main() { func main() {
i := image.NewRGBA(600, 800) i := image.NewRGBA(image.Rect(0, 0, 600, 800))
gc := draw2d.NewGraphicContext(i) gc := draw2d.NewGraphicContext(i)
gc.Translate(0, 380) gc.Translate(0, 380)
gc.Scale(1, -1) gc.Scale(1, -1)

View file

@ -37,8 +37,8 @@ func NewGraphicContext(img draw.Image) *ImageGraphicContext {
switch selectImage := img.(type) { switch selectImage := img.(type) {
case *image.RGBA: case *image.RGBA:
painter = raster.NewRGBAPainter(selectImage) painter = raster.NewRGBAPainter(selectImage)
case *image.NRGBA: //case *image.NRGBA:
painter = NewNRGBAPainter(selectImage) // painter = NewNRGBAPainter(selectImage)
default: default:
panic("Image type not supported") panic("Image type not supported")
} }

View file

@ -1,15 +1,15 @@
// Copyright 2010 The draw2d Authors. All rights reserved. // Copyright 2010 The draw2d Authors. All rights reserved.
// created: 21/11/2010 by Laurent Le Goff // created: 21/11/2010 by Laurent Le Goff
package draw2d package draw2d
/*
import ( import (
"image/draw" "image/draw"
"image" "image"
"freetype-go.googlecode.com/hg/freetype/raster" "freetype-go.googlecode.com/hg/freetype/raster"
) )*/
const M = 1<<16 - 1 const M = 1<<16 - 1
/*
type NRGBAPainter struct { type NRGBAPainter struct {
// The image to compose onto. // The image to compose onto.
Image *image.NRGBA Image *image.NRGBA
@ -46,7 +46,7 @@ func (r *NRGBAPainter) Paint(ss []raster.Span, done bool) {
ma := s.A >> 16 ma := s.A >> 16
if r.Op == draw.Over { if r.Op == draw.Over {
for i, nrgba := range p { for i, nrgba := range p {
dr, dg, db, da := nrgba.RGBA() dr, dg, db, da := nrgba.
a := M - (r.ca*ma)/M a := M - (r.ca*ma)/M
da = (da*a + r.ca*ma) / M da = (da*a + r.ca*ma) / M
if da != 0 { if da != 0 {
@ -74,6 +74,7 @@ func (r *NRGBAPainter) Paint(ss []raster.Span, done bool) {
} }
} }
} }
} }
// SetColor sets the color to paint the spans. // SetColor sets the color to paint the spans.
@ -85,3 +86,4 @@ func (r *NRGBAPainter) SetColor(c image.Color) {
func NewNRGBAPainter(m *image.NRGBA) *NRGBAPainter { func NewNRGBAPainter(m *image.NRGBA) *NRGBAPainter {
return &NRGBAPainter{Image: m} return &NRGBAPainter{Image: m}
} }
*/

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 158 KiB

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB