Mercurial > hg > octave-image
changeset 624:92777e13512e
im2xxx: use actual value rather than calls to intmax when we already know the class
author | carandraug |
---|---|
date | Wed, 26 Sep 2012 15:21:55 +0000 |
parents | a923e5324064 |
children | 300c22195a13 |
files | inst/im2int16.m inst/im2uint16.m inst/im2uint8.m |
diffstat | 3 files changed, 14 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/inst/im2int16.m +++ b/inst/im2int16.m @@ -39,20 +39,22 @@ ## Input checking (private function that is used for all im2class functions) im_class = imconversion (nargin, "im2int16", false, im); - switch im_class + ## for those who may wonder, 32767 = intmax ("int16") + ## for those who may wonder, 65535 = intmax ("uint16") + switch im_class case "int16" ## do nothing, return the same case {"single", "double"} - im = int16 (double (im * intmax ("uint16")) - double (intmax ("int16")) - 1); + im = int16 (double (im * uint16(65535)) - 32767 - 1); case "logical" im(im) = intmax ("int16"); im(!im) = intmin ("int16"); case "uint8" ## 257 is the ratio between the max of uint8 and uint16 ## double (intmax ("uint16")) / double (intmax ("uint8")) == 257 - im = int16 (double (257 * uint16 (im)) - double (intmax ("int16")) - 1); + im = int16 (double (257 * uint16 (im)) - 32767 - 1); case "uint16" - im = int16 (double (im) - double (intmax ("int16")) - 1); + im = int16 (double (im) - 32767 - 1); otherwise error ("unsupported image class %s", im_class); endswitch
--- a/inst/im2uint16.m +++ b/inst/im2uint16.m @@ -40,21 +40,22 @@ ## Input checking (private function that is used for all im2class functions) im_class = imconversion (nargin, "im2uint16", indexed, im); + ## for those who may wonder, 65535 = intmax ("uint16") switch im_class case "uint16" ## do nothing, return the same case {"single", "double"} if (indexed) imax = max (im(:)); - if ( imax > intmax ("uint16")) + if ( imax > 65535) error ("Too many colors '%d' for an indexed uint16 image", imax); endif im = uint16 (im) - 1; else - im = uint16 (im * double (intmax ("uint16"))); + im = uint16 (im * 65535); endif case "logical" - im = uint16 (im) * intmax ("uint16"); + im = uint16 (im) * uint16 (65535); case "uint8" if (indexed) im = uint16 (im);
--- a/inst/im2uint8.m +++ b/inst/im2uint8.m @@ -42,11 +42,12 @@ if (indexed) imax = max (im(:)); - if (imax > intmax ("uint8")) + if (imax > 255) error ("Too many colors '%d' for an indexed uint8 image", imax); endif endif + ## for those who may wonder, 255 = intmax ("uint8") switch im_class case "uint8" ## do nothing, return the same @@ -54,10 +55,10 @@ if (indexed) im = uint8 (im) - 1; else - im = uint8 (im * double (intmax ("uint8"))); + im = uint8 (im * 255); endif case "logical" - im = uint8 (im) * intmax ("uint8"); + im = uint8 (im) * uint8 (255); case "uint16" if (indexed) im = uint8 (im);