Re: Optimisation OT



This conversion should be correct.. can you test? It adds a few int
multiplications, which can be avoided by adding another set of tables. But I
don't want to do that before I know for sure this one works.

Nils

procedure TsdTransformYCCKToRGBAdobe.Transform(Source, Dest: pointer;
Count: integer);
// YCCK to RGB for Adobe images is different. First, the Y, Cr and Cb are
inverted,
// and k* = 220 - K. The normal YCbCr to RGB is then applied. As a last
step,
// the values are scaled by 0.65 around 128
const
c0_65: integer = round(0.65 * cColorConvScale);
c44_8: integer = round(44.8 * cColorConvScale);// 128 - 0.65 * 128
var
R, G, B, Y, Cb, Cr, K: PByte;
Yi, Ki, Ri, Gi, Bi, Cbi, Cri: integer;
function ScaleAndRangeLimit(A: integer): integer;
begin
// First the scaling
A := (A * c0_65) div cColorConvScale + c44_8;
// Undo fixed precision and range limit
Result := A div cColorConvScale;
if Result < 0 then
Result := 0
else
if Result > 255 then
Result := 255;
end;
begin
Y := Source;
Cb := Source; inc(Cb);
Cr := Source; inc(Cr, 2);
K := Source; inc(K, 3);
// RGB is layed out in memory as BGR
B := Dest;
G := Dest; inc(G);
R := Dest; inc(R, 2);
// Repeat Count times..
while Count > 0 do
begin
// Do the conversion in int
Yi := cY_toRT[255 - Y^];
Cbi := 255 - Cb^;
Cri := 255 - Cr^;
Ki := (220 - K^) * cColorConvScale;
Ri := Yi + cCrtoRT[Cri] + c__toR - Ki;
Gi := Yi + cCbToGT[Cbi] + cCrtoGT[Cri] + c__toG - Ki;
Bi := Yi + cCbtoBT[Cbi] + c__toB - Ki;
R^ := ScaleAndRangeLimit(Ri);
G^ := ScaleAndRangeLimit(Gi);
B^ := ScaleAndRangeLimit(Bi);
// Advance pointers
inc(Y, 4); inc(Cb, 4); inc(Cr, 4); inc(K, 4);
inc(R, 3); inc(G, 3); inc(B, 3);
dec(Count);
end;
end;



.



Relevant Pages

  • Re: Ada Pointer Size Problem
    ... >> int. ... > pointer to an int. ... And you can't assign C pointer to integer without conversion; ... need not provide them if it doesn't have a suitable integer type. ...
    (comp.lang.ada)
  • Re: typedef function with void parameters
    ... void pointer. ... | int foo ... data pointer type, but you need to know what the other type is ... in order to choose the proper conversion. ...
    (comp.lang.c)
  • Re: pointer question
    ... p = (char*) malloc; ... Without a declaration for malloc in scope, C assumes that it returns an int. ... If a void* cannot be represented in an int, then the behavior of the first conversion is undefined. ... And when you have converted some T* to the appropriate integer, the only kind of conversion back to pointer which is guaranteed to work is to T*. ...
    (comp.lang.c)
  • Re: Saving three 16 bit RGB values in 32 bits::
    ... course you can do a conversion like this. ... digits containing data. ... Converting this back to RGB, gives the correct 'R' value, a green value of 32900, but complete loss of the blue data. ... double Utility::RGB_ToDBL(int R, int G, int B) * ...
    (sci.image.processing)
  • Re: Minimum size of void *
    ... Flash Gordon wrote: ... converted losslessly to int. ... The pointer to the global section of the function, ... Keith was talking about whether they could be converted, the conversion being a common extension and gave size as one possible reason why it might not be possible. ...
    (comp.lang.c)