Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ev3dev/fb: add support for XRGB #78

Merged
merged 2 commits into from
Apr 26, 2018
Merged

ev3dev/fb: add support for XRGB #78

merged 2 commits into from
Apr 26, 2018

Conversation

kortschak
Copy link
Member

@dlech Please take a look.

This will provide the construction function required for ev3go/ev3#3.

Copy link
Contributor

@dlech dlech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused by all the use of RGB565 stuff. Is this copy and paste errors or is there something else going on here? If the latter, some comments in the code explaining it would be helpful.

fb/xrgb.go Outdated
// NewXRGB returns a new XRGB image with the given bounds.
func NewXRGB(r image.Rectangle) *XRGB {
w, h := r.Dx(), r.Dy()
stride := 2 * w
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be 4 instead of 2?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

fb/xrgb.go Outdated
return &XRGB{Pix: pix, Stride: stride, Rect: r}, nil
}

// XRGB is an in-memory image whose At method returns Pixel565 values.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the At method returns color.Color, not Pixel565

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed, but At has to return color.Color to satisfy the image.Image interface. The underlying concrete value is a PixelXRGB.

fb/xrgb.go Outdated
// Pix holds the image's pixels, as 32 bit XRGB
// values stored in little-endian order.
// The pixel at (x, y) is the four bytes at
// Pix[2*(x-Rect.Min.X) + (y-Rect.Min.Y)*Stride].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, 4 instead of 2?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}

// ColorModel returns the XRGB color model.
func (p *XRGB) ColorModel() color.Model { return RGB565Model }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is RGB565Model correct?

Copy link
Member Author

@kortschak kortschak Apr 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, The only difference between an XRGB and a color.RGBA is the absence of the A channel. The storage in the image's Pix field` is independent of the colour's representation here.

fb/xrgb.go Outdated
return PixelXRGB{R: p.Pix[i+2], G: p.Pix[i+1], B: p.Pix[i]}
}

// Set sets the color of the pixel565 at (x, y) to c.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, the mention of pixel565 makes me think I am missing something here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is just me. Sorry.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually believe that's an error in the original file. I should not state what type of pixel is being set, and the capitalisation is wrong. But I'll fix that later.

fb/xrgb_test.go Outdated
t.Fatalf("failed to read src image file %v.png: %v", test, err)
}

got := NewRGB565(src.Bounds())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shoudn't this be NewXRGB?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, sorry. Fixed.

fb/xrgb_test.go Outdated
if err != nil {
t.Fatalf("failed to read golden image file %v-xrgb.png: %v", test, err)
}
want := NewRGB565(gol.Bounds())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also here NewXRGB?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -0,0 +1,109 @@
// Copyright ©2016 The ev3go Authors. All rights reserved.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2018? Also in the test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As attested by the horrific level of copy-paste errorism, the code was originally the 565 code.

fb/xrgb.go Outdated
// NewXRGB returns a new XRGB image with the given bounds.
func NewXRGB(r image.Rectangle) *XRGB {
w, h := r.Dx(), r.Dy()
stride := 2 * w

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the stride is 4*w.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

fb/xrgb.go Outdated
// Pix holds the image's pixels, as 32 bit XRGB
// values stored in little-endian order.
// The pixel at (x, y) is the four bytes at
// Pix[2*(x-Rect.Min.X) + (y-Rect.Min.Y)*Stride].

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/2/4/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@vladimir-ch
Copy link

Ah, sorry, I had the comments ready for some time and now I submitted them without checking the current state of discussion.

@kortschak
Copy link
Member Author

Sorry for that. I should not code just before bed.

The issues were largely copy-paste errors. The issue about the return type is a Go-ism for interface satisfaction.

Copy link
Contributor

@dlech dlech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand the return RGB565Model, but looks better now.

@kortschak
Copy link
Member Author

The operations on the colour and alpha channels in the color model are because the RGBA method of color.Color returns 16 bit values (in a uint32), so they need to be reduced to 8 bit width.

@kortschak
Copy link
Member Author

Updates ev3go/ev3#2.

@kortschak kortschak merged commit 4ad4099 into ev3dev-stretch Apr 26, 2018
@kortschak kortschak deleted the fb/xrgb branch April 26, 2018 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants