-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is RGB565Model correct?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and also here NewXRGB?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/2/4/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Ah, sorry, I had the comments ready for some time and now I submitted them without checking the current state of discussion. |
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. |
There was a problem hiding this 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.
The operations on the colour and alpha channels in the color model are because the |
Updates ev3go/ev3#2. |
@dlech Please take a look.
This will provide the construction function required for ev3go/ev3#3.