Skip to content

Commit

Permalink
operations can work inplace
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Jan 12, 2023
1 parent ee606be commit 7a42330
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- can supply add_rgb_space-format hash-ref to the relevant functions
- add rgb_to_lab, lab_to_rgb, rgb_{to,from}_linear
- add lsRGB colour space
- operations can work inplace

0.201 2022-02-14
- more accurate dependencies
Expand Down
15 changes: 15 additions & 0 deletions color_space.pd
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ pp_addhdr('
pp_def('rgb_to_cmyk',
Pars => 'rgb(c=3); [o]cmyk(d=4)',
HandleBad => 1,
Inplace => 1,
GenericTypes=>['D'],
Code => '
/* First check for bad values */
Expand Down Expand Up @@ -224,6 +225,7 @@ BADDOC
pp_def('cmyk_to_rgb',
Pars => 'cmyk(d=4); [o]rgb(c=3)',
HandleBad => 1,
Inplace => 1,
GenericTypes=>['D'],
Code => '
/* First check for bad values */
Expand Down Expand Up @@ -271,6 +273,7 @@ BADDOC
pp_def('rgb_to_hsl',
Pars => 'rgb(c=3); [o]hsl(c=3)',
HandleBad => 1,
Inplace => 1,
GenericTypes=>['D'],
Code => '
/* First check for bad values */
Expand Down Expand Up @@ -319,6 +322,7 @@ BADDOC
pp_def('hsl_to_rgb',
Pars => 'hsl(c=3); [o]rgb(c=3)',
HandleBad => 1,
Inplace => 1,
GenericTypes=>['D'],
Code => '
/* First check for bad values */
Expand Down Expand Up @@ -366,6 +370,7 @@ BADDOC
pp_def('rgb_to_hsv',
Pars => 'rgb(c=3); [o]hsv(c=3)',
HandleBad => 1,
Inplace => 1,
GenericTypes=>['D'],
Code => '
/* First check for bad values */
Expand Down Expand Up @@ -414,6 +419,7 @@ BADDOC
pp_def('hsv_to_rgb',
Pars => 'hsv(c=3); [o]rgb(c=3)',
HandleBad => 1,
Inplace => 1,
GenericTypes=>['D'],
Code => '
/* First check for bad values */
Expand Down Expand Up @@ -463,6 +469,7 @@ pp_def('xyY_to_xyz',
Pars => 'xyY(c=3); [o]xyz(c=3)',
Doc => 'Internal function for white point calculation. Use it if you must.',
HandleBad => 1,
Inplace => 1,
GenericTypes=>['D'],
Code => '
/* First check for bad values */
Expand All @@ -482,6 +489,7 @@ pp_def('xyY_to_xyz',
pp_def('_rgb_to_xyz',
Pars => 'rgb(c=3); gamma(); m(i=3,rows=3); [o]xyz(c=3)',
HandleBad => 1,
Inplace => ['rgb'],
GenericTypes=>['D'],
Code => '
/* First check for bad values */
Expand All @@ -502,6 +510,7 @@ pp_def('_rgb_to_xyz',
pp_def('_xyz_to_rgb',
Pars => 'xyz(c=3); gamma(); mstar(i=3,rows=3); [o]rgb(c=3)',
HandleBad => 1,
Inplace => ['xyz'],
GenericTypes=>['D'],
Code => '
/* First check for bad values */
Expand All @@ -523,6 +532,7 @@ pp_def('_xyz_to_lab',
Pars => 'xyz(c=3); w(d=2); [o]lab(c=3)',
Doc => undef,
HandleBad => 1,
Inplace => ['xyz'],
GenericTypes=>['D'],
Code => '
/* construct white point */
Expand Down Expand Up @@ -551,6 +561,7 @@ pp_def('_lab_to_xyz',
Doc => undef,

HandleBad => 1,
Inplace => ['lab'],
GenericTypes=>['D'],
Code => '
/* construct white point */
Expand All @@ -577,6 +588,7 @@ pp_def('_lab_to_xyz',
pp_def('lab_to_lch',
Pars => 'lab(c=3); [o]lch(c=3)',
HandleBad => 1,
Inplace => 1,
GenericTypes=>['D'],
Code => '
/* First check for bad values */
Expand Down Expand Up @@ -624,6 +636,7 @@ BADDOC
pp_def('lch_to_lab',
Pars => 'lch(c=3); [o]lab(c=3)',
HandleBad => 1,
Inplace => 1,
GenericTypes=>['D'],
Code => '
/* First check for bad values */
Expand Down Expand Up @@ -671,6 +684,7 @@ BADDOC
pp_def('rgb_to_linear',
Pars => 'rgb(c=3); gamma(); [o]out(c=3)',
HandleBad => 1,
Inplace => ['rgb'],
GenericTypes=>['D'],
Code => '
PDL_IF_BAD(if ($ISBAD(rgb(c=>0)) || $ISBAD(rgb(c=>1)) || $ISBAD(rgb(c=>2))) {
Expand Down Expand Up @@ -705,6 +719,7 @@ BADDOC
pp_def('rgb_from_linear',
Pars => 'rgb(c=3); gamma(); [o]out(c=3)',
HandleBad => 1,
Inplace => ['rgb'],
GenericTypes=>['D'],
Code => '
PDL_IF_BAD(if ($ISBAD(rgb(c=>0)) || $ISBAD(rgb(c=>1)) || $ISBAD(rgb(c=>2))) {
Expand Down
2 changes: 2 additions & 0 deletions t/color_space.t
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ sub tapprox {
my $a = rgb_to_xyz( $rgb_, 'Adobe' );
my $ans = pdl( 0.582073320819542, 0.299955362786115, 0.0546021884576833 );
ok( tapprox( $a, $ans), 'rgb_to_xyz Adobe' ) or diag($a, "\n", $ans);
$rgb_->inplace->rgb_to_xyz( 'Adobe' );
ok( tapprox( $rgb_, $ans), 'rgb_to_xyz inplace' ) or diag($rgb_, "\n", $ans);
}

# xyY_to_xyz
Expand Down

0 comments on commit 7a42330

Please sign in to comment.