<div dir="ltr"><div>Hi,</div><div>I read in comment for Color: <br></div><div>"(r, b and g)    amount, a Float between 0.0 and 1.0. <br>(But, in fact, the three are encoded as values from 0 to 1023 and combined in a single integer, rgb.  The user does not need to know this.)"</div><div><br></div><div>But in several places colors are also represented as 0 to 255 for r, g, b and alpha.</div><div>So when are we using 8 bits and when are we using 10 bits for each color value?</div><div><br></div><div>Best,</div><div>Karl<br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Aug 21, 2022 at 5:37 PM <<a href="mailto:commits@source.squeak.org">commits@source.squeak.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Nicolas Cellier uploaded a new version of Graphics to project The Trunk:<br>
<a href="http://source.squeak.org/trunk/Graphics-nice.536.mcz" rel="noreferrer" target="_blank">http://source.squeak.org/trunk/Graphics-nice.536.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: Graphics-nice.536<br>
Author: nice<br>
Time: 21 August 2022, 5:36:40.736262 pm<br>
UUID: a4930d0f-a408-724e-b9e0-4eb4841607e3<br>
Ancestors: Graphics-nice.535<br>
<br>
Further accelerate Color creation from 8 bits components.<br>
<br>
For this we pre-multiply the constants by the destination shift - 8, so as to omit the right shift >> 8 followed by the left shift << Red/GreenShift.<br>
- RedShift = 20 bits, 16r403 >> (20-8) = 16r403000<br>
- GreenShift = 10 bits, 16r403 >> (10-8) = 16r100C<br>
<br>
=============== Diff against Graphics-nice.535 ===============<br>
<br>
Item was changed:<br>
  ----- Method: Color>>setRed8:green8:blue8: (in category 'private') -----<br>
  setRed8: r green8: g blue8: b<br>
        "Initialize this color's r, g, and b components to the given values in the range [0..255].<br>
        Use an optimized operation rather than a slow division"<br>
<br>
        "<br>
        self assert: ((0 to: 255) allSatisfy: [:e | (e*1023/255) rounded = (e * 16r403 + 16r81 >> 8)]).<br>
        "<br>
<br>
        ComponentMax = 1023 ifFalse: [^self setRed: r / 255 green: g / 255 blue: b / 255].<br>
        rgb == nil ifFalse: [self attemptToMutateError].<br>
+       rgb := (r* 16r403000 + 16r81000 bitAnd: 16r3FF00000 "ComponentMask << RedShift" )<br>
+               + (g* 16r100C + 16r204 bitAnd: 16rFFC00 "ComponentMask << GreenShift" )<br>
+               + (b* 16r403 + 16r81 >> 8).<br>
-       rgb := ((r* 16r403 + 16r81 >> 8) bitShift: RedShift) <br>
-               + ((g* 16r403 + 16r81 >> 8) bitShift: GreenShift) <br>
-               + ((b* 16r403 + 16r81 >> 8)).<br>
        cachedDepth := nil.<br>
        cachedBitPattern := nil.!<br>
<br>
Item was changed:<br>
  ----- Method: Color>>setRed:green:blue:range: (in category 'private') -----<br>
  setRed: r green: g blue: b range: range<br>
        "Initialize this color's r, g, and b components to the given values in the range [0..r]."<br>
<br>
+       range = ComponentMax  ifTrue: [^self setPrivateRed: r green: g blue: b].<br>
        range = 255 ifTrue: [^self setRed8: r green8: g blue8: b].<br>
        ^ self setRed: r / range green: g / range blue: b / range!<br>
<br>
Item was changed:<br>
  DisplayMedium subclass: #Form<br>
        instanceVariableNames: 'bits width height depth offset'<br>
        classVariableNames: 'CompressOnSnapshot'<br>
        poolDictionaries: ''<br>
        category: 'Graphics-Display Objects'!<br>
<br>
+ !Form commentStamp: 'nice 5/3/2020 18:04' prior: 0!<br>
- !Form commentStamp: 'cbc 5/5/2017 10:07' prior: 0!<br>
  A rectangular array of pixels, used for holding images.  All pictures, including character images are Forms.  The depth of a Form is how many bits are used to specify the color at each pixel.  The actual bits are held in a Bitmap, whose internal structure is different at each depth.  Class Color allows you to deal with colors without knowing how they are actually encoded inside a Bitmap.<br>
          The supported depths (in bits) are 1, 2, 4, 8, 16, and 32.  The number of actual colors at these depths are: 2, 4, 16, 256, 32768, and 16 million.<br>
        Forms are indexed starting at 0 instead of 1; thus, the top-left pixel of a Form has coordinates 0@0.<br>
        Forms are combined using BitBlt.  See the comment in class BitBlt.  Forms that repeat many times to fill a large destination are InfiniteForms.<br>
<br>
        colorAt: x@y            Returns the abstract Color at this location<br>
        displayAt: x@y          shows this form on the screen<br>
        displayOn: aMedium at: x@y      shows this form in a Window, a Form, or other DisplayMedium<br>
        fillColor: aColor               Set all the pixels to the color.<br>
        edit            launch an editor to change the bits of this form.<br>
        pixelValueAt: x@y       The encoded color.  The encoding depends on the depth.<br>
<br>
+ Details about internal format for Bitmap: <br>
+ Pixels are organised left to right, top to bottom, that is as a contiguous serie of lines.<br>
+ Each pixel is made of a fixed quantity of bits (depth).<br>
+ Thus a Bitmap can be viewed as a rectangular area of size (width*depth x height) in bits.<br>
+ However, the beginning of each line in the bitmap must fall on a 32-bit word boundary.<br>
+ Thus the actual bitSize of a line is rounded up to next multiple of 32.<br>
+ The Bitmap may somehow have unsued bits near the end of each line.<br>
+ <br>
+ Note: If you want to hook up other external forms/displayScreens, please look at the (successful) Graphics-External package in <a href="http://www.squeaksource.com/Balloon3D" rel="noreferrer" target="_blank">http://www.squeaksource.com/Balloon3D</a>.<br>
+ <br>
+ !<br>
- Note: If you want to hook up other external forms/displayScreens, please look at the (successful) Graphics-External package in <a href="http://www.squeaksource.com/Balloon3D" rel="noreferrer" target="_blank">http://www.squeaksource.com/Balloon3D</a>.!<br>
<br>
<br>
</blockquote></div>