Skip to content

rework 8bit color encoding #5

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

Merged
merged 1 commit into from
Aug 7, 2022
Merged

rework 8bit color encoding #5

merged 1 commit into from
Aug 7, 2022

Conversation

t-bltg
Copy link
Member

@t-bltg t-bltg commented Aug 6, 2022

Superseding JuliaImages/ImageInTerminal.jl#62.
Goes with JuliaImages/ImageInTerminal.jl#68.

using ImageInTerminal, OffsetArrays, ImageCore

main() = begin
  wheel = OffsetArrays.centered(fill(ARGB(0, 0, 0, 0), (128, 128)))

  for I  CartesianIndices(wheel)
    x, y = I.I ./ (size(wheel)  2)
    r = sqrt(x^2 + y^2)
    if r < 1
      h = atand(x, y) + 90
      wheel[I] = RGB(HSV(h, r, 1))
    end
  end

  bar = Gray{N0f8}.(repeat(range(0, stop=1, length=64), 1, 2)')

  for enc  (
    ImageInTerminal.XTermColors.TermColor8bit(),
    ImageInTerminal.XTermColors.TermColor24bit()
  )
    @show enc
    display(enc.(wheel))
    display(enc.(bar))
  end
  return
end

main()

@johnnychen94 could you tell me if you obtain the same images with this PR ?

Your graybar image seems better than mine (https://user-images.githubusercontent.com/8684355/147930881-ef076fb5-3252-4d9b-8f00-11a32fa9648f.png), my gradient is not uniform and I have thin dark lines appearing ...

Output with this PR:

8bit colors
xtc-24bit

sixel
xtc-sixel

@codecov
Copy link

codecov bot commented Aug 6, 2022

Codecov Report

Merging #5 (bbb5152) into master (e5d72b5) will decrease coverage by 1.38%.
The diff coverage is 86.36%.

@@            Coverage Diff             @@
##           master       #5      +/-   ##
==========================================
- Coverage   95.13%   93.75%   -1.39%     
==========================================
  Files           3        3              
  Lines         144      144              
==========================================
- Hits          137      135       -2     
- Misses          7        9       +2     
Impacted Files Coverage Δ
src/ascii.jl 93.91% <66.66%> (ø)
src/colorant2ansi.jl 89.47% <87.50%> (-10.53%) ⬇️
src/XTermColors.jl 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us.

@johnnychen94
Copy link
Member

FWIW, this is what I get in iTerm (macOS) for this branch, it does look like the gray version is getting worse:

image

@t-bltg
Copy link
Member Author

t-bltg commented Aug 7, 2022

Thanks, I've slightly updated the test script in #5 (comment).

I've fixed the grayscale issue, here is the output using the 2 color depths (8bit, 24bit), in a sixel compatible terminal (mlterm):

xc-six

Here is the test script for comparing refs imgs against current master for visual inspection:

#!/usr/bin/env bash
{
  root="[...]/XTermColors.jl"  # this PR

  for f in $(find $root -path '*/reference/*.txt' | sort -h); do
   tmp=$(mktemp)
   url="https://raw.githubusercontent.com/JuliaImages/XTermColors.jl/master/test/reference/$(basename $f)"
   wget -q -O $tmp $url
   if [ $(wc -c $tmp | awk '{ print $1 }') -eq 0 ]; then
      echo "== disappeared($f) $url =="
      continue
   fi 
   if ! diff $f $tmp 1>/dev/null; then
      echo
      echo "== remote($url) =="
      cat $tmp; echo
      echo "== local($f) =="
      cat $f; echo
    else
      echo "== same($f) =="
   fi
   rm $tmp
  done

  exit
}

@johnnychen94, there are some visual changes, so I'm wondering which reference images are better ?

@t-bltg t-bltg marked this pull request as ready for review August 7, 2022 14:02
@t-bltg t-bltg requested a review from johnnychen94 August 7, 2022 14:02
Copy link
Member

@johnnychen94 johnnychen94 left a comment

Choose a reason for hiding this comment

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

I'd vote for the PR version. But a few packages use ImageInTerminal.encode_img to as test util to compare images, so this will be a breaking change to ImageInTerminal.

@t-bltg
Copy link
Member Author

t-bltg commented Aug 7, 2022

Thanks, this means that we should release ImageInTerminal 1.0 instead of 0.5, right ?

@johnnychen94
Copy link
Member

1.0 means that API is stable and works. I feel ImageInTerminal is far from stable, e.g., the display, sixel and related are still not well tested.

I personally prefer 0.5, but don't take it too seriously, we have many major release versions to use. Just feel free to make 1.0 release if you like it this way!

@t-bltg
Copy link
Member Author

t-bltg commented Aug 7, 2022

Ha, I mismatched semver again, let's make it 0.5. I'll merge this now and we can continue discussions in JuliaImages/ImageInTerminal.jl#68.

@t-bltg t-bltg merged commit 7bae393 into JuliaImages:master Aug 7, 2022
@t-bltg t-bltg deleted the 8bit branch August 7, 2022 14:49
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.

2 participants