What's the difference between "Color Resolution" and "Size of Global Color Table" in the GIF89a spec? - gif

I can't figure out the difference between the "Color Resolution" field and the "Size of Global Color Table" field in the gif89a spec https://www.w3.org/Graphics/GIF/spec-gif89a.txt (page 9-10):
Color Resolution - Number of bits per primary color [...], minus 1. This value represents the size of the entire palette [...]
Size of Global Color Table - [...] To determine that actual size of the color table, raise 2 to [the value of the field + 1].
...
[The Global Color Table] is a sequence of bytes representing red-green-blue color triplets [...] and contains a number of bytes equal to 3 x 2^(Size of Global Color Table+1).
Let's say we want to create an image with 3 colors, red, green and blue. In this case we need at least ceil(log2(3)) = 2 bits per color (00 = red, 01 = green, 10 = blue). Then, according to the spec, the Color Resolution (CR) field must be set to ceil(log2(3)) - 1 = 2 - 1 = 1:
packed fields = X001XXXX
---
CR field
More generally, if N is the number of colors, then CR = ceil(log2(N)) - 1.
Regarding the size of the Global Color Table (GCT), 1 color requires 3 RGB bytes, therefore the number of entries = the number of bytes / 3 = 2^(Size of GCT + 1). Since we want to store 3 colors, I would go for the power of 2 that comes immediately after 3, which is 2 raised to ceil(log2(3)) = 2^2 = 4. Then, 2^(Size of GCT + 1) = 2^ceil(log2(3)), Size of GCT + 1 = ceil(log2(3)) and Size of GCT = ceil(log2(3)) - 1 = 2 - 1 = 1:
packed fields = XXXXX001
---
Size of GCT field
Again, if N is the number of colors, then Size of GCT = ceil(log2(N)) - 1.
As you can see, CR = Size of GCT = ceil(log2(N)) - 1. It seems like the CR field and the Size of GCT field always hold the same value. I suppose I'm wrong because if I was right one of these two fields would be useless, but I didn't find any clarification in the spec so far.
I'm not alone being confused: http://giflib.sourceforge.net/whatsinagif/bits_and_bytes.html. This article applies the definition of the Size of GCT field to the CR field, and the Size of GCT field is simply not defined at all:
[...] the color resolution [...] allow you to compute [the] size [of the GCT]. If the value of this filed is N, the number of entries in the global color table will be 2 ^ (N+1) [...]. Thus, the 001 in the sample image represents 2 bits/pixel; 111 would represent 8 bits/pixel.
Anybody knows a situation where these two fields differ?

From the spec:
iv) Color Resolution - Number of bits per primary color available
to the original image, minus 1. This value represents the size of
the entire palette from which the colors in the graphic were
selected, not the number of colors actually used in the graphic.
For example, if the value in this field is 3, then the palette of
the original image had 4 bits per primary color available to create
the image. This value should be set to indicate the richness of
the original palette, even if not every color from the whole
palette is available on the source machine.
So to be clear, color resolution is supposed to be the number of bits per color (less 1) in the original image the GIF was made from.

Related

Google Sheets - Combine multiple IF Functions into one cell

I'm trying to produce a SKU in Google Sheets for a product using the values of three variants (Title, Colour and Size)
The product is 'Lightweight trainers' with colour variants of 'Red' and 'Blue', and the sizes range from 5 - 12.
Link to spreadsheet
https://docs.google.com/spreadsheets/d/1trq0X3MjR-n2THFnT8gYYlwKscnQavCeeZ8L-ifYaHw/edit?usp=sharing
Aim
I'm hoping to have a SKU that displays the product, the colour variant and the shoes size.
Example: LW-1-8 (Lightweight trainer, colour Red, size 8)
Product is Lightweight Trainers with a value of LW.
Colour variant 'Red' with a value of 1 and 'Blue' with a value of 2.
Shoe size variant = number ranging from 5 to 12.
Here's what I have so far, joining the colour and size variants.
=IFS(I2="Red",1,I2="Blue",2)&"-"& IFS(K2="5",5,K2="6",6,K2="7",7,K2="8",8,K2="9",9,K2="10",10,K2="11",11,K2="12",12)
However, I'm getting stuck in joining the data in column B with this function.
Any help with combining this data from multiple cells into one would be greatly appreciated.
TL;DR
=ARRAYFORMULA(IF(B2:B<>"", IFS(B2:B="Lightweight Trainers", "LW")&"-"&IFS(I2:I="Blue", 1, I2:I="Red", 2)&"-"&K2:K,))
Answer
What you want is basically:
<title>-<color number>-<shoe size>
To convert this to a function we can split it into each part and take it step by step:
Step 1: Title
For the first part -the title- we need to match the value with the shorthand. A simple list in an IFS is enough.
IFS(B2="Lightweight Trainers", "LW")
Obviously for now it only has a single value (Lightweight Trainers) but you could add more:
IFS(B2="Lightweight Trainers", "LW", B2="Heavyweight Trainers", "HW")
Step 2: color number
Similar to the previous step, it’s a mapping using ifs:
IFS(I2="Blue", "-1", I2="Red", "-2")
The dash is added so when adding everything it will only have it if
Step 3: shoe size
In this case we can simply get the value:
K2
Step 4: Adding everything together
We only need to add it with the dashes in between:
=IFS(B2="Lightweight Trainers", "LW")&"-"&IFS(I2="Blue", 1, I2="Red", 2)&"-"&K2
Step 5: Extending for the entire column automatically
We will use ARRAYFORMULA to add a single formula to the first cell and get it automatically extended to the entire column. We first add it to the formula we already have, and then extend the ranges to the entire column:
=ARRAYFORMULA(IFS(B2:B="Lightweight Trainers", "LW")&"-"&IFS(I2:I="Blue", 1, I2:I="Red", 2)&"-"&K2:K)
Remember to remove all the values in the column so array formula doesn’t override them (it would generate an error).
As you can see the formula generates errors for the rows that have no values. A good way of handling this case is to filter the rows without a title. In a single row would be:
=IF(B2<>"", [the entire formula],)
Notice the last comma.
So putting everything together and extending its range to the column, is:
=ARRAYFORMULA(IF(B2:B<>"", IFS(B2:B="Lightweight Trainers", "LW")&"-"&IFS(I2:I="Blue", 1, I2:I="Red", 2)&"-"&K2:K,))
Adding this to N2 should work.
Final notes
It seems that you use 150 when the size it’s not a whole number. If you want to keep that functionality you may use:
IF(K2-int(K2)=0, K2, 150)
On the last component and expand it the same way.
You may also want to prevent having two dashes when a value is missing (LW-5 instead of LW--5). To do so, I’d recommend adding it to each component instead of the formula that adds them together.
References
IFS (Docs Editors Help)
IF (Docs Editors Help)
ARRAYFORMULA (Docs Editors Help)
try in N2:
=IFS(I2="Red",1,I2="Blue",2)&"-"&
IFS(K2=5,5,K2=6,6,K2=7,7,K2=8,8,K2=9,9,K2=10,10,K2=11,11,K2=12,12)
or use:
=IF(I2="red", 1, IF(I2="blue", 2, )&IF((K5>=5)*(K5<=12), "-"&K5, )

Conditional format of cell with different data types in SSRS?

I am trying to add a fill color to a table that I created in SSRS. The data looks like the table as follows:
The task is whenever the value is over 7, then color the cell green, when the value is less than 7 then orange and if the value is below zero then the due time changes to a sentence as shown with ID 2 and is to be colored red.
I have achieved coloring the cells when greater than or less than 7 using the if statement on the Due(Mins) field value however, it fails to color the cell red when less than 0. I have used switch, instr functions, but haven't had any luck.
Can emphasize more. Appreciate the help.
Cheers,
Sid
=SWITCH(
Fields!Due.Value.ToString.Contains("OverDue"), "Red",
VAL(Fields!Due.Value) > 7, "Green",
True, "Orange"
)
Switch will stop when it hits the first expression that evaluates to True
So...
First we test if the value contains overdue and set red
Then we test if the value is greater than 7 and set the result to Green
The True at the end acts like an else

ACCESS: variable text align based upon field length in Report

I would like to have a text box change alignment on a Report based upon the length of the data contained.
For example:
If the length of Text is less than 100, then left justify. If it is greater or equal to 100, then distribute...
Is this possible?
I am not expert at vba programming, so any help would me appreciated
It is possible using vba by determining the alignment dependent on the length of the text. You could apply the same to any other property of your field as well
If Len(myfield) < 100 Then myfield.TextAlign = 1 Else myfield.TextAlign = 4
Check this for further details.
Add this to the details section of the report, to apply the change to each and every single entry. For your approach, the final Sub should look like this:
Private Sub Detail_Paint()
If Len(CommRule) < 100 Then CommRule.TextAlign = 1 Else CommRule.TextAlign = 4
End Sub
In words: If the length of your CommRule value (the number of characters in your text) is smaller than 100 (then) set the alignment for CommRule to "left" (= 1), else set it to "distribute" (= 4)

SSRS indicators setting of values and states

I am tryding to achieve this :
When the column "verwag" is equal to "skatting", I want a yellow flat line, if it is greater than skatting I want a green arrow and when it is smaller than skatting I want a red arrow. I cannot figure out how to set the value and state in the indicator properties to achieve this.
Regards
Assuming those columns are just fields called skatting and verwag; set the Expression for the value to:
=Switch(Fields!verwag.Value > Fields!skatting.Value, 1, Fields!verwag.Value = Fields!skatting.Value, 2, Fields!verwag.Value < Fields!skatting.Value, 3)
And then set the states like this:

What Colour Format/Encoding are these Flash colour values in

I am parsing colour codes that I get from a Flex(Flash ActionScript) application, then creating HTML div elements with that same colour.
My Problem: The colours are all only 8 digits long. So they cant be RGB colour values can they? What color value format are they in? If I can figure the format they are in I can convert them to RGB. Maybe the last/first digit signifies its 0. alpha value?
PS: Should I convert the colours to RGB or something else?
This is an example of the colour code values I getting from the flash application:
16777215
4803910
84545883
16777215
RGB colours are represented by hexadecimal digits (base 16).
Base 16 means that each place in the number can represent numbers 0-15 in this order:
0 1 2 3 4 5 6 7 8 9 A B C D E F
Using 0x in AS3 represents a hex number. As an example, run this:
trace(0xF); // 15
The output as you can see is represented in decimal (base 10). What you're seeing above in your question is the decimal representation of your colours.
If you want to see the hex version, use toString() and parse 16 as the radix parameter. You'll notice that the default is 10 (for base 10 / decimal numbers that we all know and love).
var num:int = 15;
trace(num.toString(16)); // f
Hope this makes sense.