Skip to content

Commit

Permalink
fix: fix one line and one row effect, and fix the palette sort by mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelesaux committed Apr 15, 2022
1 parent d4ab5ba commit e9c892a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
45 changes: 41 additions & 4 deletions gfx/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,31 @@ func ApplyOneImageAndExport(in image.Image,
fmt.Fprintf(os.Stderr, "Cannot downgrade colors palette for this image %s\n", picturePath)
}
}
newPalette = constants.SortColorsByDistance(newPalette)
var paletteToSort color.Palette
switch mode {
case 1:
paletteToSort = newPalette[0:4]
case 2:
paletteToSort = newPalette[0:2]
default:
paletteToSort = newPalette
}
newPalette = constants.SortColorsByDistance(paletteToSort)

out, _ = DoDithering(out, newPalette, cont.DitheringAlgo, cont.DitheringType, cont.DitheringWithQuantification, cont.DitheringMatrix, float32(cont.DitheringMultiplier), cont.CpcPlus, cont.Size)
if cont.Saturation > 0 || cont.Brightness > 0 {
palette = convert.EnhanceBrightness(newPalette, cont.Brightness, cont.Saturation)
newPalette, downgraded = convert.DowngradingWithPalette(out, palette)
newPalette = constants.SortColorsByDistance(newPalette)
var paletteToSort color.Palette
switch mode {
case 1:
paletteToSort = newPalette[0:4]
case 2:
paletteToSort = newPalette[0:2]
default:
paletteToSort = newPalette
}
newPalette = constants.SortColorsByDistance(paletteToSort)
}

fmt.Fprintf(os.Stdout, "Saving downgraded image into (%s)\n", filename+"_down.png")
Expand Down Expand Up @@ -238,13 +257,31 @@ func ApplyOneImage(in image.Image,
}
}

newPalette = constants.SortColorsByDistance(newPalette)
var paletteToSort color.Palette
switch mode {
case 1:
paletteToSort = newPalette[0:4]
case 2:
paletteToSort = newPalette[0:2]
default:
paletteToSort = newPalette
}
newPalette = constants.SortColorsByDistance(paletteToSort)
out, _ = DoDithering(out, newPalette, cont.DitheringAlgo, cont.DitheringType, cont.DitheringWithQuantification, cont.DitheringMatrix, float32(cont.DitheringMultiplier), cont.CpcPlus, cont.Size)

if cont.Saturation > 0 || cont.Brightness > 0 {
palette = convert.EnhanceBrightness(newPalette, cont.Brightness, cont.Saturation)
newPalette, downgraded = convert.DowngradingWithPalette(out, palette)
newPalette = constants.SortColorsByDistance(newPalette)
var paletteToSort color.Palette
switch mode {
case 1:
paletteToSort = newPalette[0:4]
case 2:
paletteToSort = newPalette[0:2]
default:
paletteToSort = newPalette
}
newPalette = constants.SortColorsByDistance(paletteToSort)
}
var data []byte
var lineSize int
Expand Down
12 changes: 6 additions & 6 deletions gfx/common/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func ToMode2(in *image.NRGBA, p color.Palette, ex *export.MartineContext) []byte

lineToAdd := 1

if ex.OneLine {
if ex.OneRow {
lineToAdd = 2
}

Expand Down Expand Up @@ -97,7 +97,7 @@ func ToMode2(in *image.NRGBA, p color.Palette, ex *export.MartineContext) []byte
}
pp8 = ex.SwapInk(pp8)
firmwareColorUsed[pp8]++
if ex.OneRow {
if ex.OneLine {
pp2 = 0
pp4 = 0
pp6 = 0
Expand All @@ -123,7 +123,7 @@ func ToMode1(in *image.NRGBA, p color.Palette, ex *export.MartineContext) []byte

lineToAdd := 1

if ex.OneLine {
if ex.OneRow {
lineToAdd = 2
}
if ex.Overscan {
Expand Down Expand Up @@ -172,7 +172,7 @@ func ToMode1(in *image.NRGBA, p color.Palette, ex *export.MartineContext) []byte
}
pp4 = ex.SwapInk(pp4)
firmwareColorUsed[pp4]++
if ex.OneRow {
if ex.OneLine {
pp4 = 0
pp2 = 0
}
Expand All @@ -192,7 +192,7 @@ func ToMode0(in *image.NRGBA, p color.Palette, ex *export.MartineContext) []byte
var bw []byte

lineToAdd := 1
if ex.OneLine {
if ex.OneRow {
lineToAdd = 2
}
if ex.Overscan {
Expand Down Expand Up @@ -224,7 +224,7 @@ func ToMode0(in *image.NRGBA, p color.Palette, ex *export.MartineContext) []byte
}
pp2 = ex.SwapInk(pp2)
firmwareColorUsed[pp2]++
if ex.OneRow {
if ex.OneLine {
pp2 = 0
}
pixel := PixelMode0(pp1, pp2)
Expand Down

0 comments on commit e9c892a

Please sign in to comment.