Skip to content

Commit

Permalink
Merge pull request #25 from owulveryck/colors
Browse files Browse the repository at this point in the history
Color support
  • Loading branch information
owulveryck authored Dec 22, 2021
2 parents 72346ad + 9844656 commit b2d2078
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ It is possible to tweak the configuration via environment variables:
| RK_SERVER_ADDR | remarkabke:2000 | the address of the remarkable
| RK_CLIENT_AUTOROTATE | true | activate autorotate (see below)
| RK_CLIENT_PAPER_TEXTURE | null | a path to a texture
| RK_CLIENT_COLORIZE | false | try to colorize the highliter
| RK_CLIENT_COLORIZE | true | colorize function
| RK_CLIENT_HIGHLIGHT | false | highlight function (cannot work with colorize)

## Features

Expand Down
3 changes: 2 additions & 1 deletion internal/client/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ type Configuration struct {
AutoRotate bool `env:"RK_CLIENT_AUTOROTATE,default=true"`
ScreenShotDest string `env:"RK_CLIENT_SCREENSHOT_DEST,default=."`
PaperTexture string `env:"RK_CLIENT_PAPER_TEXTURE"`
Colorize bool `env:"RK_CLIENT_COLORIZE,default=false"`
Highlight bool `env:"RK_CLIENT_HIGHLIGHT,default=false"`
Colorize bool `env:"RK_CLIENT_COLORIZE,default=true"`
paperTextureLandscape *image.Gray
paperTexturePortrait *image.Gray
}
Expand Down
44 changes: 25 additions & 19 deletions internal/client/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,33 @@ func createTransparentImage(img *image.Gray) *image.RGBA {
}

func colorize(img *image.Gray) *image.RGBA {
/*
yellow := color.RGBA{
R: 255,
G: 253,
B: 84,
A: 255,
}
*/
/*
var m *image.RGBA
switch {
case img.Rect.Dx() == Width && img.Rect.Dy() == Height:
m = rgbaPoolWH.Get().(*image.RGBA)
case img.Rect.Dx() == Height && img.Rect.Dy() == Width:
m = rgbaPoolHW.Get().(*image.RGBA)
m := image.NewRGBA(img.Bounds())
// Create mask for highlighting
// 85 = red / 153 = blue
for i := 0; i < len(img.Pix); i++ {
r := img.Pix[i]
switch r {
case 85:
m.Pix[i*4] = 255
m.Pix[i*4+1] = 0
m.Pix[i*4+2] = 0
m.Pix[i*4+3] = 255
case 153:
m.Pix[i*4] = 0
m.Pix[i*4+1] = 0
m.Pix[i*4+2] = 255
m.Pix[i*4+3] = 255
default:
m = image.NewRGBA(img.Bounds())
m.Pix[i*4] = r
m.Pix[i*4+1] = r
m.Pix[i*4+2] = r
m.Pix[i*4+3] = 255
}
*/
}
return m
}

func highlight(img *image.Gray) *image.RGBA {
m := image.NewRGBA(img.Bounds())
// Create mask for highlighting
maskHighlight := image.NewAlpha(img.Bounds())
Expand All @@ -91,8 +99,6 @@ func colorize(img *image.Gray) *image.RGBA {
maskHighlight.Pix[i] = 255
}
}
//draw.Draw(m, m.Bounds(), image.NewUniform(yellow), image.Point{}, draw.Src)
//draw.DrawMask(m, img.Bounds(), img, image.Point{}, maskHighlight, image.Point{}, draw.Over)
drawRGBAOver(m, img.Bounds(), img, image.Point{}, maskHighlight, image.Point{})
return m
}
Expand Down
2 changes: 1 addition & 1 deletion internal/client/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type voidJpegDisplayer struct{}

func (v *voidJpegDisplayer) Display(img *image.Gray) error {
var b bytes.Buffer
return jpeg.Encode(&b, colorize(img), nil)
return jpeg.Encode(&b, highlight(img), nil)
}

func BenchmarkImageHandler(b *testing.B) {
Expand Down
9 changes: 7 additions & 2 deletions internal/client/mjpeg_displayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ func (m *MJPEGDisplayer) Display(img *image.Gray) error {
defer bufPool.Put(b)

var err error
if m.conf.Colorize {
switch {
case m.conf.Colorize:
colored := colorize(img)
err = jpeg.Encode(b, colored, nil)
defer releaseRGBA(colored)
} else {
case m.conf.Highlight:
colored := highlight(img)
err = jpeg.Encode(b, colored, nil)
defer releaseRGBA(colored)
default:
err = jpeg.Encode(b, img, nil)
}
if err != nil {
Expand Down

0 comments on commit b2d2078

Please sign in to comment.