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

add palette.satyg #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add palette.satyg #22

wants to merge 1 commit into from

Conversation

puripuri2100
Copy link
Collaborator

@puripuri2100 puripuri2100 commented Jan 2, 2020

color.satyhよりも提供する色を増やし、Gray, RGB, CMYKでそれぞれ提供するようにしました。
ファイル名については要議論かもしれません。

追加した色はLaTeXのxcolorパッケージで標準で提供されるものです

@nyuichi
Copy link
Owner

nyuichi commented Jan 3, 2020

プルリクを出すときは自分でレビュワーに適当な人をassignしてもらえるとたすかります!


val make-gray : float -> color

val red : color
Copy link
Owner

Choose a reason for hiding this comment

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

Gray.redとかGray.greenとかはどういう場面で使うことを想定していますか?

Copy link
Owner

Choose a reason for hiding this comment

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

Color.to-gray (Color.red)でここのGray.redと同じになるような

Color.to-gray : color -> color

という関数を用意すると便利かもしれません.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Gray.redやGray.greenはモノクロ印刷をするところでもそれらしい色を使い時などを想定しています。
また、RGBやCMYKと同じ色が定義されているのは、「執筆中ではカラーで表示するが、印刷所に提出するときにはモノクロにしたい」時などに

% 試し時
%open RGB
% 印刷時
open Gray

let-inline ctx \emph it = read-inline (set-text-color red blue) it

のようにすることを想定してるからです。

to-gray関数は欲しいですが、どの変換式を採用するかで悩んでいます。
参考:グレースケール画像のうんちく(Qiita)

Copy link
Owner

Choose a reason for hiding this comment

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

あーなるほど,意図は理解しました.

ぷりにゃんさんの方法だと試し時と印刷時でモノクロかどうかを分けたいときに色を使う全てのsatyとsatyh(自分で書いたものだけでなくすでにインストール済みのものも含む)にopen Grayをつけて回る作業が発生してしまいそうですがそれでも問題なさそうですか?(実際にはライブラリから直接色を使うことはない気がするので大丈夫そうではある)

Copy link
Owner

Choose a reason for hiding this comment

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

to-grayは全部実装してもよさそうです:

type grayscale-algorithms = RGBMean | Luma | ...

val to-gray : grayscale-algorithms ?-> color -> color

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

openを付けて回るのは回避したいですが、let f = if !if-gray then Gray.red else RGB.redのように使ってもらえると少し楽になるかもしれません……。

to-grayはできるものから実装していくことにします

Copy link

@matsud224 matsud224 Jan 4, 2020

Choose a reason for hiding this comment

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

SATySFiコードのレベルでモノクロへ切り替えるという方法は外部プログラムに依存しないという利点がありますが、他の方法としてSATySFiでのPDF出力時にコマンドラインオプションで指定するようにしたり(SATySFi本体の改造が必要)、出力したPDFをモノクロ化するという方法(cf. http://rakkyoo.net/?p=131 )も考えられると思います。
コードで切り替えを行う方法の欠点として、例えばカラー画像はそのままになってしまいます。

Copy link
Owner

Choose a reason for hiding this comment

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

はい、カラー画像の扱いなどの問題もありますし、可能であればsatysfi本体への変更が1番だと思います。ただし、satysfi本体への変更はマージされる見込みがなかなか立たないというメタな問題もあるのでひとまずsatysfi-baseで対応可能な範囲で対応するという方針でもいいと思っています。

val make-rgb : float -> float -> float -> color
val make-rgb-256 : int -> int -> int -> color % 0 - 255

val red : color
Copy link
Owner

Choose a reason for hiding this comment

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

RGB.red,CMYK.red,Color.red (color-extの中の定義)はどう違うんでしょうか

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Color.redとRGB.redとの違いはありません。しかし、CMYK.redとRGB.redとの違いは明確で、PDF/X-1aなどの印刷用のPDFファイルを作ろうとした時などのRGBが使えずCMYKが要求される場面で、特にCMYKで定義されているということが明確であるという点で役に立ちます。
同様にRGBモジュールとGrayモジュールも、そこでの色がそれぞれの色空間で定義されているということを保証したいのでそれぞれ独立させています。

colorパッケージで定義されているという理由でRGBモジュールだけからredを無くすというのはGrayモジュールやCMYKモジュールとの整合性との観点から躊躇しています。

let red = Color.red

とするのもありですが、colorパッケージの中での定義がCMYK空間に変更される可能性を考えるとこのままの方が良いと考えました。

Copy link
Owner

Choose a reason for hiding this comment

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

うーんなるほど,RGB.red/CMYK.red/GRAY.redを用意するならColor.redを実行時に切り替えられるようにしたいですね.stage-0 functionを使ってうまくできそう.

% main.saty
@require: stdja
@require: base/color-ext

let () = ~(set-color-mode CMYK) in
...
% color-ext
module Color : sig
  val red : color
end = struct
  let red = match ~(get-color-mode ()) in
  | CMYK -> CMYK.red
  | RGB -> RGB.red
  | Gray -> Gray.red
end

palette.satyg Show resolved Hide resolved
@nyuichi
Copy link
Owner

nyuichi commented Jan 3, 2020

言い忘れていたのですがpalette.satygの中身はcolor-ext.satyhの中に全部入れてしまってもいいかなと思っています.

@zeptometer
Copy link
Collaborator

実装を大きめに変えてしまう提案なので議論をややこしくしてしまったら申し訳ないのですが、open Grayをつけて回る問題については、抽象的な色を扱うモジュールAbstractColor

module AbstractColor : sig
  type t

  val red : t
  val green : t
  val blue : t
  ...
end = struct
...

と、AbstractColor.tcolorとの対応付けを行うモジュールColorSpace

module ColorSpace : sig
  type t
  val into : t -> AbstractColor.t -> color

  val gray : t
  val rgb : t
  val cymk : t

end = struct
...

の二つを用意してやればいい気がします。下のコードのようにColorSpace.tの値を外から与えるようにすれば色空間を切り替えやりやすくなります。コードが長くなってしまうのが難点ですが…

let-inline ctx \todo color-space inner =
  let ctx-todo = ctx |> set-text-color (AbstractColor.red |> ColorSpace.into color-space) in
  read-inline ctx-todo {[TODO: #inner;]}

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.

None yet

4 participants