U value of the YUV color space.
Syntax
u
Synonyms
u0
u1
Formula
u=(-19*r-37*g+56*b)/256 (the output range would be u=[-55;55] )
Formula corrected in my patch:
u=(-147407*r-289391*g+436798*b)/2000000 (the output range would be u=[-55;55] )
Original Machine Code (in OPER resource) of Filter Factory 3.0 and 3.0.4 for Photoshop/Win32
8B 77 04 | mov esi,[edi+$04] (g) | . |
8B C6 | mov eax,esi | eax = g; |
8D 34 F6 | lea esi,[esi+esi*8] | g = g + 8*g; |
8D 34 B0 | lea esi,[eax+esi*4] | g = eax + 4*g; |
F7 DE | neg esi | g = -g; // (1) |
8B 07 | mov eax,[edi] (r) | . |
8B C8 | mov ecx,eax | ecx = r; |
8D 04 C0 | lea eax,[eax+eax*8] | r = r + 8*r; |
8D 04 41 | lea eax,[ecx+eax*2] | r = ecx + 2*r; // (2) |
2B F0 | sub esi,eax | u = g - r; |
8B 47 08 | mov eax,[edi+$08] (b) | . |
8B C8 | mov ecx,eax | ecx = b; |
C1 E0 03 | shl eax,$03 (3) | b = b << 3; |
2B C1 | sub eax,ecx | b = b - ecx; // (3) |
8D 04 C6 | lea eax,[esi+eax*8] | u = u + 8*b; // (4) |
99 | cdq | . |
81 E2 FF 00 00 00 | and edx,$000000ff (255) | . |
03 C2 | add eax,edx | . |
C1 F8 08 | sar eax,$08 (8) | u /= 256; // u += (u + 255) >> 8; |
50 | push eax | return u; |
(1) tg = -(g + 4*(g + 8*g)) = -g -4*g -32*g = -37*g
(2) tr = r + 2*(r + 8*r) = r + 2*r + 16*r = 19*r
(3) tb = (b << 3) - b = 8*b - b = 7*b
(4) u = tg - tr + 8*tb u = -37*g - 19*r + 8*(7*b) u = -37*g - 19*r + 56*b ==> correct!