���������
5.6. ��� ���������� �������� � ���������

������ �����, ������� ������. ��� ����������� ����� ��, ��� �������� ���� ������� � ������������� (r,g,b) � ����������� ������ (light_r,light_g,light_b) ��������� ���

result_r = r * light_r / max(light_r);
result_g = g * light_g / max(light_g);
result_b = b * light_b / max(light_b);

����� max(light_r) - ��� ����������� ��������� �������� ��� light_r. �� ������������ �� ���� ��� ��������� ������������, ��� �� ����������, � ������ ������������ ��� ���� ��������� ��������. ��������, ���� � ��� �������� ��� light_r ����� ������ �� 0 �� 255, � ������� �������� ����� ����� ���� (30, 40,50), �� �������������� �������� ������������ ����� ����� (k*30,k*40,k*50), ��� 0 <= k <= 1, �� max(light_r) = 255, � �� 30. ������� ������� ����������, �� ������ ��� ��������� � �������� ����� ���� ����.

5.6.1. 256-������� ������

����� 1: ������� ��������� �������, ����������� ���� (����, ������������) � ����. ����� �� ������ �������, � ������ ��� ������ ���� (����, ������������) ��������� ������� ������������ �� ����; � ����� (��� ������� � demo.design FAQ) ����� ������� � ������������� �� ��� true color �������� 256x256, � ������� ������ (x, y) ��������� ������ (��� true color!), ��������������� ����� x � ������������ y, � ����� ��������� �� ���-������ ���� Image Alchemy � 256 ������. ����� ���� ������������ ������� ������������ ��������, � � �������� ������� (colorTable) ����� ���� ������������ ��������:

outputColor = colorTable[intensity][color].

����� 2: ���� ��� ������� ������������ ������� ������ � �������� ���������, �� ����� � ������� ����� �������� ��� ��������� �������� ���� ������������ ������. ����� ����������� ������� ������� � ������� - ��� ���� ���������, � ����� - �����, � ���� ��������. ������: ����� � ��� ���� 8 ������ � 32 �������� ������������. ������� ��������� ���: 32 �������� ������� �����, �������, ..., ��������. ����� (��� ����� �������)

outputColor = (color << 5) + intensity.

5.6.2. 24/32-������ ������

����� ��� �������� ���� �� ������ ���������. ������ ������� ��������� �� ���� � ����, � ���������� ����� � ���������� �����. �� ����, ������� ������� redTable[numShades], greenTable[numShades], blueTable[numShades], � ����� ��� ������ ���������� ������� ������� � ������ �������� ������������ �� ���� ������� ���������� �������� �������� ����������:

r = redTable[intensity],
g = greenTable[intensity],
b = blueTable[intensity].

������ ���������� � ���� ������� - ��� ��������� ����, ������� ������� ������� �� ���������.

5.6.3. 15/16-������ ������

����� 1: �����, �� �����������. ������������ ������� ������� � ������� � ��� ��� ��������� ���������� ����� � �������� ���������. ������� ��������� ������ �� ���������, �������� 65536*32 = 2 ���������. � ������� ����� 32, ������ ��� � ���� ������� �� ���������� ��������� �� 5 ��� (�� ����������� 6-������ ������� ���������� � 16-������ �����), � ������ ������ �������� ������������, ��� 32, ������������.

����� 2: ������ ��� ��� ��, ��� � 24/32-������ �������. �������� ��������� ��-�� ����, ��� �������� � ������ �������� ������ ��������� ��� ���������� �� �������. ������� ��� ��������� ����� ������� ������� �� ����� ������� ��������, �.�. �������� ��������� ������ ������ ���� ������ ����:

000bbbbb          - �����, 8 ���
00000gggggg00000  - �������, 16 ���
rrrrr000          - �������, 8 ���

����� �������� ���� ��������� �������� ���:

outputColor =
   (redTable[(color >> 10) & 0x2F] << 8) +
  greenTable[(color >> 5) & 0x1F] +
   blueTable[color & 0x1F].

�� ���������� ��� ��������, ������, ��������� - � ����������. �������� ���:

; ...
mov  bx,color
shr  bx,10
and  bx,02Fh
mov  ah,redTable[bx]
mov  bx,color
and  bx,01Fh
mov  al,blueTable[bx]
mov  bx,color
shr  bx,5      ; ����� �������� ��
and  bx,01Fh   ;   shr  bx,4
shl  bx,1      ;   and  bx,02Eh
or   ax,greenTable[bx]
mov  outputColor,ax
; ...

����� 3: �������� ��� � 24/32-����, ��������� ������������� � ��������� ��������� �� ������ 5.6.2, � ����� ��������������� ��� ������ �� ����� ������ �������������� �� 24/32-��� � 15/16. ��� ������������ PTC � ������������ ������ ������ �������������� ������ ���. PTC - ��� ����� ����������� ������� ��� C++, ����� �� ����� �� http://www.gaffer.org/ptc.



 � ����� ������


demo.design
3D programming FAQ