Einzelnen Beitrag anzeigen

TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
2.860 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#5

AW: JPEG dekomprimieren mit TurboJPEG

  Alt 7. Jun 2021, 11:30
Schaue dir mal Vcl.Graphics.TWICImage.RequireBitmap an.
So könntest du es mal versuchen.

Hier im Editor mal so runtergetippt:
Delphi-Quellcode:
procedure TfrmTurboJPEG.btnCreateBitmapClick(Sender: TObject);
var
  JH: TJHandle;
  jpegStream: TMemoryStream;
  i, Width, Height, Res: Integer;
  SubSampling: TJPF;
  OutBuf: TBytes;
  Bitmap: TBitmap;
  BitmapInfo: TBitmapInfo;
begin
  if Assigned(imgJPEG.Picture.Graphic) then
  begin
    JH := Rk.Vcl.Imaging.TurboJPEG.InitDecompress;
    try
      jpegStream := TMemoryStream.Create;
      try
        imgJPEG.Picture.Graphic.SaveToStream(jpegStream);
        Width := 0;
        Height := 0;
        Res := Rk.Vcl.Imaging.TurboJPEG.DecompressHeader2(JH, jpegStream.Memory, jpegStream.Size, @Width, @Height, @SubSampling);
        CheckError(JH, Res);
        SetLength(OutBuf, Width * Height * 4);
        Res := Rk.Vcl.Imaging.TurboJPEG.Decompress2(JH, jpegStream.Memory, jpegStream.Size, @OutBuf[0], Width, 0, Height, TJPF_RGBA, 0);
        CheckError(JH, Res);
      finally
        jpegStream.Free;
      end;
    finally
        Rk.Vcl.Imaging.TurboJPEG.Destroy(JH);
    end;

    FillChar(BitmapInfo, SizeOf(BitmapInfo), 0);
    BitmapInfo.bmiHeader.biSize := SizeOf(BitmapInfo);
    BitmapInfo.bmiHeader.biWidth := Width;
    BitmapInfo.bmiHeader.biHeight := -Height;
    BitmapInfo.bmiHeader.biPlanes := 1;
    BitmapInfo.bmiHeader.biBitCount := 32;

    Bitmap := TBitmap.Create;
    try
      Bitmap.PixelFormat := pf32Bit;
      Bitmap.SetSize(Width, Height);
      SetDIBits(0, Bitmap.Handle, 0, Height, @OutBuf[0], BitmapInfo, DIB_RGB_COLORS);
      Bitmap.AlphaFormat := afDefined;

      imgBitmapDecompressed.Picture.Assign(Bitmap);
    finally
      Bitmap.Free;
    end;
  end;
end;
  Mit Zitat antworten Zitat