⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jidctfst.pas

📁 用pascal寫的jpeg codec, 測試過的
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    end;
{$endif}

    { Even part }

    tmp10 := (DCTELEM(wsptr^[0]) + DCTELEM(wsptr^[4]));
    tmp11 := (DCTELEM(wsptr^[0]) - DCTELEM(wsptr^[4]));

    tmp13 := (DCTELEM(wsptr^[2]) + DCTELEM(wsptr^[6]));
    tmp12 := MULTIPLY(DCTELEM(wsptr^[2]) - DCTELEM(wsptr^[6]), FIX_1_414213562)
	    - tmp13;

    tmp0 := tmp10 + tmp13;
    tmp3 := tmp10 - tmp13;
    tmp1 := tmp11 + tmp12;
    tmp2 := tmp11 - tmp12;

    { Odd part }

    z13 := DCTELEM(wsptr^[5]) + DCTELEM(wsptr^[3]);
    z10 := DCTELEM(wsptr^[5]) - DCTELEM(wsptr^[3]);
    z11 := DCTELEM(wsptr^[1]) + DCTELEM(wsptr^[7]);
    z12 := DCTELEM(wsptr^[1]) - DCTELEM(wsptr^[7]);

    tmp7 := z11 + z13;		{ phase 5 }
    tmp11 := MULTIPLY(z11 - z13, FIX_1_414213562); { 2*c4 }

    z5 := MULTIPLY(z10 + z12, FIX_1_847759065); { 2*c2 }
    tmp10 := MULTIPLY(z12, FIX_1_082392200) - z5; { 2*(c2-c6) }
    tmp12 := MULTIPLY(z10, - FIX_2_613125930) + z5; { -2*(c2+c6) }

    tmp6 := tmp12 - tmp7;	{ phase 2 }
    tmp5 := tmp11 - tmp6;
    tmp4 := tmp10 + tmp5;

    { Final output stage: scale down by a factor of 8 and range-limit }

    outptr^[0] := range_limit^[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
			    and RANGE_MASK];
    outptr^[7] := range_limit^[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
			    and RANGE_MASK];
    outptr^[1] := range_limit^[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
			    and RANGE_MASK];
    outptr^[6] := range_limit^[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
			    and RANGE_MASK];
    outptr^[2] := range_limit^[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
			    and RANGE_MASK];
    outptr^[5] := range_limit^[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
			    and RANGE_MASK];
    outptr^[4] := range_limit^[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
			    and RANGE_MASK];
    outptr^[3] := range_limit^[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
			    and RANGE_MASK];

    Inc(int_ptr(wsptr), DCTSIZE);	{ advance pointer to next row }
  end;
end;

end.

----------------------------------------------------------------------
Nomssi: Feig Method

type
  matasm  = array[0..DCTSIZE2-1] of integer;
  bmatrix  = array[0..DCTSIZE2-1] of byte;
  bmatrixptr = ^bmatrix;

const
  FIX_1_082392200 = INT32(Round(CONST_SCALE*1.082392200));  {277}
  FIX_1_414213562 = INT32(Round(CONST_SCALE*1.414213562));  {362}
  FIX_1_847759065 = INT32(Round(CONST_SCALE*1.847759065));  {473}
  FIX_2_613125930 = INT32(Round(CONST_SCALE*2.613125930));  {669}

procedure ANN_IDCT(count : integer;
                   var coeffs :matasm;
                   var outptr :bmatrix);

Const
  CONST_IC4 = 1.414213562; { 1/0.707106781; }
  FP_IC4    = FIX_1_414213562;
  FP_I_C4_2 = FP_IC4;

  Function Descale(x : integer):byte;
  var y : integer;
  begin
    y := (x + (1 shl (16-1))+ (4 shl PASS_BITS)) div (8 shl PASS_BITS);
    { DeScale := x sar (3 + PASS_BITS);
      Borland Pascal SHR is unsigned }
    if y < 0 then
      descale := 0
    else
      if y > $ff then
        descale := $ff
      else
        descale := y;
  end;

  function Multiply(X, Y: Integer): integer; assembler;
  asm
    mov ax, X
    imul Y
    mov al, ah
    mov ah, dl
  end;


var
  z10, z11, z12, z13,
  tmp0,tmp1,tmp2,tmp3,
  tmp4,tmp5,tmp6,tmp7,
  tmp10,tmp11,
  tmp12,tmp13 : integer;
  column, row : byte;

  Procedure N1(var x, y : integer);   { rotator 1 }
  Const
    FP_a5 = FIX_1_847759065;
    FP_a4 = FIX_2_613125930;
    FP_a2 = FIX_1_082392200;
  var
    z5, tmp : integer;
  begin
    tmp := x;

    z5 := Multiply(tmp + y, FP_a5);  { c6 }
    x := Multiply(y, FP_a2) - z5;  { c2-c6 }
    y := Multiply(tmp, -FP_a4) + z5;  { c2+c6 }
  end;

  Procedure N2(var x, y : integer); { N1 scaled by c4 }
  Const
    FP_b5 = Integer(Round(CONST_SCALE*1.847759065*CONST_IC4));
    FP_b4 = Integer(Round(CONST_SCALE*2.613125930*CONST_IC4));
    FP_b2 = Integer(Round(CONST_SCALE*1.082392200*CONST_IC4));
  var
    z5, tmp : integer;
  begin
    tmp := x;

    z5 := Multiply(tmp + y, FP_b5);
    x := Multiply(y, FP_b2) - z5;
    y := Multiply(tmp,-FP_b4) + z5;
  end;
Const
  RowSize = 8;
var
  a, b : integer;

  sample : ^matasm;
  bbo : bmatrixptr;

  num : integer;
begin
  sample := @coeffs;
  bbo := @outptr;
  for num := 0 to Pred(count) do
  begin
    { R1 x R1 }
    for column := 7 downto 0 do
    BEGIN
      tmp5 := sample^[1*RowSize + column];

      sample^[1*RowSize + column] := sample^[4*RowSize + column];

      tmp7 := sample^[3*RowSize + column];

      a := sample^[2*RowSize + column];
      b := sample^[6*RowSize + column];
      sample^[2*RowSize + column] := a - b;
      sample^[3*RowSize + column] := a + b;

      a := sample^[5*RowSize + column];
      sample^[4*RowSize + column] := a - tmp7;
      z13 := a + tmp7;

      b := sample^[7*RowSize + column];
      sample^[6*RowSize + column] := tmp5 - b;
      z11 := tmp5 + b;

      sample^[5*RowSize + column] := z11 - z13;
      sample^[7*RowSize + column] := z11 + z13;
    END;

    for row := 7 downto 0 do
    BEGIN
      tmp5 := sample^[row*RowSize + 1];

      sample^[row*RowSize + 1] := sample^[row*RowSize + 4];

      tmp7 := sample^[row*RowSize + 3];

      a := sample^[row*RowSize + 2];
      b := sample^[row*RowSize + 6];
      sample^[row*RowSize + 2] := a - b;
      sample^[row*RowSize + 3] := a + b;

      a := sample^[row*RowSize + 5];
      sample^[row*RowSize + 4] := a - tmp7;
      z13 := a + tmp7;

      b := sample^[row*RowSize + 7];
      sample^[row*RowSize + 6] := tmp5 - b;
      z11 := tmp5 + b;

      sample^[row*RowSize + 5] := z11 - z13;
      sample^[row*RowSize + 7] := z11 + z13;
    END;

    { M x M tensor }
    for row := 0 to 7 do
    Case row of
    0,1,3,7: { M1 }
      begin
        sample^[row*RowSize + 2] := Multiply(sample^[row*RowSize + 2], FP_IC4);     { 2/c4 }
        sample^[row*RowSize + 5] := Multiply(sample^[row*RowSize + 5], FP_IC4);     { 2/c4 }

        N1(sample^[row*RowSize +  4], sample^[row*RowSize +  6]);
      end;
    2,5: { M2 }
      begin
        sample^[row*RowSize + 0] := Multiply(sample^[row*RowSize + 0], FP_IC4);
        sample^[row*RowSize + 1] := Multiply(sample^[row*RowSize + 1], FP_IC4);
        sample^[row*RowSize + 3] := Multiply(sample^[row*RowSize + 3], FP_IC4);
        sample^[row*RowSize + 7] := Multiply(sample^[row*RowSize + 7], FP_IC4);

        sample^[row*RowSize + 2] := sample^[row*RowSize + 2] * 2;  { shift }
        sample^[row*RowSize + 5] := sample^[row*RowSize + 5] * 2;

        N2(sample^[row*RowSize + 4], sample^[row*RowSize + 6]);
      end;
    end; { Case }

    { M x N tensor }
    { rows 4,6 }
    begin
      N1(sample^[4*RowSize + 0], sample^[6*RowSize + 0]);
      N1(sample^[4*RowSize + 1], sample^[6*RowSize + 1]);
      N1(sample^[4*RowSize + 3], sample^[6*RowSize + 3]);
      N1(sample^[4*RowSize + 7], sample^[6*RowSize + 7]);

      N2(sample^[4*RowSize + 2], sample^[6*RowSize + 2]);
      N2(sample^[4*RowSize + 5], sample^[6*RowSize + 5]);

      { N3 }
      { two inverse matrices => same as FDCT }
      tmp0 := sample^[4*RowSize + 4];
      tmp3 := sample^[6*RowSize + 6];
      tmp12 := (tmp0 + tmp3) * 2;
      z10 := tmp0 - tmp3;

      tmp1 := sample^[6*RowSize + 4];
      tmp2 := sample^[4*RowSize + 6];
      tmp13 :=-(tmp1 - tmp2)*2;
      z11 := tmp1 + tmp2;

      tmp0 := Multiply(z10 + z11, FP_I_C4_2);
      tmp1 := Multiply(z10 - z11, FP_I_C4_2);


      sample^[4*RowSize + 4] := tmp12 + tmp0;
      sample^[6*RowSize + 4] := tmp1 + tmp13;

      sample^[4*RowSize + 6] := tmp1 - tmp13;
      sample^[6*RowSize + 6] := tmp12 - tmp0;
    end;

    { R2 x R2 }

    for row := 0 to 7 do
    BEGIN
      { Odd part }
      tmp7 := sample^[row*RowSize + 7];
      tmp6 := sample^[row*RowSize + 6] - tmp7;
      tmp5 := sample^[row*RowSize + 5] - tmp6;
      tmp4 :=-sample^[row*RowSize + 4] - tmp5;

      { even part }
      tmp0 := sample^[row*RowSize + 0];
      tmp1 := sample^[row*RowSize + 1];
      tmp10 := tmp0 + tmp1;
      tmp11 := tmp0 - tmp1;

      tmp2 := sample^[row*RowSize + 2];
      tmp13 := sample^[row*RowSize + 3];
      tmp12 := tmp2 - tmp13;

      tmp0 := tmp10 + tmp13;
      tmp3 := tmp10 - tmp13;
      sample^[row*RowSize + 0] := (tmp0 + tmp7);
      sample^[row*RowSize + 7] := (tmp0 - tmp7);

      sample^[row*RowSize + 3] := (tmp3 + tmp4);
      sample^[row*RowSize + 4] := (tmp3 - tmp4);

      tmp1 := tmp11 + tmp12;
      tmp2 := tmp11 - tmp12;

      sample^[row*RowSize + 1] := (tmp1 + tmp6);
      sample^[row*RowSize + 6] := (tmp1 - tmp6);

      sample^[row*RowSize + 2] := (tmp2 + tmp5);
      sample^[row*RowSize + 5] := (tmp2 - tmp5);
    END;

    for column := 0 to 7 do
    BEGIN
      { even part }
      tmp0 := sample^[0*RowSize + column];
      tmp1 := sample^[1*RowSize + column];
      tmp2 := sample^[2*RowSize + column];
      tmp3 := sample^[3*RowSize + column];

      tmp10 := tmp0 + tmp1;
      tmp11 := tmp0 - tmp1;

      tmp13 := tmp3;
      tmp12 := tmp2 - tmp3;

      tmp0 := tmp10 + tmp13;
      tmp3 := tmp10 - tmp13;

      tmp1 := tmp11 + tmp12;
      tmp2 := tmp11 - tmp12;

      { Odd part }
      tmp4 := sample^[4*RowSize + column];
      tmp5 := sample^[5*RowSize + column];
      tmp6 := sample^[6*RowSize + column];
      tmp7 := sample^[7*RowSize + column];

      tmp6 := tmp6 - tmp7;
      tmp5 := tmp5 - tmp6;
      tmp4 :=-tmp4 - tmp5;

      bbo^[0*RowSize + column] := DeScale(tmp0 + tmp7);
      bbo^[1*RowSize + column] := DeScale(tmp1 + tmp6);

      bbo^[2*RowSize + column] := DeScale(tmp2 + tmp5);
      bbo^[3*RowSize + column] := DeScale(tmp3 + tmp4);

      bbo^[4*RowSize + column] := DeScale(tmp3 - tmp4);
      bbo^[5*RowSize + column] := DeScale(tmp2 - tmp5);

      bbo^[6*RowSize + column] := DeScale(tmp1 - tmp6);
      bbo^[7*RowSize + column] := DeScale(tmp0 - tmp7);
    END;

    Inc(bbo);
    Inc(sample);
  End;
End; {----------------------------------------}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -