1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68:
| function DecodeJPGFileToBMP(const AStream: TMemoryStream; var ABitmap: TBitmap): Boolean; var Width, Height, nChannels, dibPadBytes: DWord; jcprops : TJPEG_CORE_PROPERTIES; DIB: TDIBSection; Res: Integer; begin Result := False; if ijlInit(@jcprops) = IJL_OK then begin jcprops.JPGFile := nil; jcprops.JPGBytes := AStream.Memory; jcprops.JPGSizeBytes := AStream.Size; Res := ijlRead(@jcprops, IJL_JBUFF_READPARAMS); if Res = IJL_OK then begin Width := jcprops.JPGWidth; Height := jcprops.JPGHeight; nChannels := jcprops.JPGChannels; dibPadBytes := ((((Width * nChannels) + 3) div 4) * 4) - (Width * nChannels); FillChar (DIB, SizeOf(DIB), 0); if GetObject(ABitmap.Handle, SizeOf(DIB), @DIB) <> 0 then begin DIB.dsBmih.biSize := SizeOf(TBitmapInfoHeader); DIB.dsBmih.biWidth := Width; DIB.dsBmih.biHeight := Height; DIB.dsBmih.biPlanes := 1; DIB.dsBmih.biBitCount := 24; DIB.dsBmih.biCompression := BI_RGB; DIB.dsBmih.biSizeImage := 0; DIB.dsBmih.biXPelsPerMeter := 0; DIB.dsBmih.biYPelsPerMeter := 0; DIB.dsBmih.biClrUsed := 0; DIB.dsBmih.biClrImportant := 0; jcprops.DIBWidth := Width; jcprops.DIBHeight := -Height; jcprops.DIBChannels := 3; jcprops.DIBColor := IJL_BGR; jcprops.DIBPadBytes := dibPadBytes; jcprops.DIBBytes := PByte (DIB.dsBm.bmBits); case jcprops.JPGChannels of 1: jcprops.JPGColor := IJL_G; 3: jcprops.JPGColor := IJL_YCBCR; else begin jcprops.DIBColor := TIJL_COLOR(IJL_OTHER); jcprops.JPGColor := TIJL_COLOR(IJL_OTHER); end; end; Res := ijlRead(@jcprops, IJL_JBUFF_READWHOLEIMAGE); if Res = IJL_OK then begin ABitmap.Modified := True; Result := True; end else MessageDlg(ijlErrorStr(Res), mtError, [mbOk], 0); end; end else MessageDlg(ijlErrorStr(Res), mtError, [mbOk], 0); end; ijlFree(@jcprops); end; |