you do realise that the +(255-CR-CG-CB)*BR)/255 is what adds the base colour into it don't you? without it it blends the company colour with the base, but doesn't put the remainder (any company colour not used) as base, it leaves it black.bobingabout wrote:although i get what you trying to do with the +(255-CR-CG-CB)*BR)/255, i feel that simply *BR/255 would give a cleaner result. but feel free to try either method.
Your code seems to use just the company colour (* the base) if the total company colour amount is more than 127, but this would make it very dark for a value of 128, because the result could never be more than 128. in reality it should add on 127*base/255 to brighten it up, after all, the company colour map doesn't control the shading.
Plus my code's shorter.
EDIT: oh, and after untangling my edits in the previous post, this is the formulas I was trying to give:
RR=min(255,((CR*C1R+CG*C2R+CB*C3R)*BR)/255/255+max(0,255-CR-CG-CB)*BR/255);
RG=min(255,((CR*C1G+CG*C2G+CB*C3G)*BG)/255/255+max(0,255-CR-CG-CB)*BG/255);
RB=min(255,((CR*C1B+CG*C2B+CB*C3B)*BB)/255/255+max(0,255-CR-CG-CB)*BB/255);
explained:
(CR*C1R+CG*C2R+CB*C3R) multiplies the red channel of each company colour by the company colour map, to get the final company colour for that pixel
/255 to put it back into the range 0-255 instead of 0-65535 (255*255)
*BR/255 to blend with the base colour to add shading
+max(0,255-CR-CG-CB)*BG/255:
255-CR-CG-CB takes the remainder (amount not used in the company colour map)
max(0,255-CR-CG-CB) means that if it goes below 0 it uses 0
*BG/255 multiplies the remainder by the base colour to keep it bright enough. (so company colour map total of 128 (or some other number not 255) at the edge of a region of company colour doesn't darken.)
min(255, ...) means that the result can't go over 255.
(yes I know min and max seem to work backward, but min(255, ... ) takes the smaller number out of 255 and the formula result, meaning that if it goes over 255 it uses 255.)
they can be simplified to the following, but they don't make sense to read:
RR=min(255,((CR*C1R+CG*C2R+CB*C3R)/255+max(0,255-CR-CG-CB))*BR/255);
RG=min(255,((CR*C1G+CG*C2G+CB*C3G)/255+max(0,255-CR-CG-CB))*BG/255);
RB=min(255,((CR*C1B+CG*C2B+CB*C3B)/255+max(0,255-CR-CG-CB))*BB/255);