swc@sys.uea.ac.uk (S.W. Cox CMP Staff) (07/11/89)
The RGB colour entries in Mac II's palettes are supposed to be 0 - 65535 but when converted to the conventional range 0 .. 1 by: newcol.red := col.red/65535 etc where newcol.red, green and blue are reals, it starts inserting negative numbers (possibly -32767 to 32767 or something similar). Can anybody think of a suitable assignment for going from the integers to the reals (and vice versa) apart from adding and subtracting 32767 etc. Thanks, S Cox UEA Norwich, UK swc@uk.ac.uea.sys
rmh@apple.com (Rick Holzgrafe) (07/12/89)
In article <635@sys.uea.ac.uk> swc@sys.uea.ac.uk (S.W. Cox CMP Staff) writes: > The RGB colour entries in Mac II's palettes are supposed to be 0 - 65535 > but when converted to the conventional range 0 .. 1 by: > > newcol.red := col.red/65535 etc > > where newcol.red, green and blue are reals, it starts inserting negative > numbers (possibly -32767 to 32767 or something similar). > > Can anybody think of a suitable assignment for going from the integers > to the reals (and vice versa) apart from adding and subtracting 32767 etc. > > Thanks, S Cox UEA Norwich, UK Paraphrase from Inside Mac V-175 (The Color Picker Package): RGBcolor fields are of type INTEGER, which is signed. There is another 16-bit type called SmallFract of range 0..65535 which is assignment- compatible with INTEGERs. There are two conversion routines: FUNCTION SmallFract2Fix(s: SmallFract): Fixed; FUNCTION Fix2SmallFract(f: Fixed): SmallFract; So perhaps this will work for you: newcol.red := SmallFract2Fix(col.red); where newcol.red is of type Fixed rather than Real. I haven't tried this, but I will soon because I have a similar problem. ========================================================================== Rick Holzgrafe | {sun,voder,nsc,mtxinu,dual}!apple!rmh Software Engineer | AppleLink HOLZGRAFE1 rmh@apple.com Apple Computer, Inc. | "All opinions expressed are mine, and do 20525 Mariani Ave. MS: 27-O | not necessarily represent those of my Cupertino, CA 95014 | employer, Apple Computer Inc."
cjp@Apple.COM (Chris Plummer) (07/12/89)
In article <635@sys.uea.ac.uk> swc@uea-sys.UUCP () writes: > >The RGB colour entries in Mac II's palettes are supposed to be 0 - 65535 >but when converted to the conventional range 0 .. 1 by: > > newcol.red := col.red/65535 etc > >where newcol.red, green and blue are reals, it starts inserting negative >numbers (possibly -32767 to 32767 or something similar). > >Can anybody think of a suitable assignment for going from the integers >to the reals (and vice versa) apart from adding and subtracting 32767 etc. According to IM V-136, the RGBColor record consists of 3 INTEGERs and INTEGERs are signed (-32768..32767) so it looks like you'll need to add 32768 to the color values or treat them as unsigned integers (maybe declare a type called UNSIGNEDINT : 0..65535 and then use this as a type cast. Hope this helps. --Chris Plummer