mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-22 03:09:24 +02:00
SetSize with output dimensions depending on orientation
This commit is contained in:
parent
abdbe4065b
commit
6d03a2582e
@ -217,31 +217,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFPReaderJPEG.ReadHeader(Str: TStream; Img: TFPCustomImage);
|
procedure TFPReaderJPEG.ReadHeader(Str: TStream; Img: TFPCustomImage);
|
||||||
var
|
|
||||||
S: TSize;
|
|
||||||
|
|
||||||
function TranslateSize(const Sz: TSize): TSize;
|
|
||||||
begin
|
|
||||||
case FOrientation of
|
|
||||||
eoUnknown, eoNormal, eoMirrorHor, eoMirrorVert, eoRotate180: Result := Sz;
|
|
||||||
eoMirrorHorRot270, eoRotate90, eoMirrorHorRot90, eoRotate270:
|
|
||||||
begin
|
|
||||||
Result.Width := Sz.Height;
|
|
||||||
Result.Height := Sz.Width;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
jpeg_read_header(@FInfo, TRUE);
|
jpeg_read_header(@FInfo, TRUE);
|
||||||
|
|
||||||
|
FWidth := FInfo.image_width;
|
||||||
|
FHeight := FInfo.image_height;
|
||||||
|
|
||||||
if FInfo.saw_EXIF_marker and (FInfo.orientation >= Ord(Low(TExifOrientation))) and (FInfo.orientation <= Ord(High(TExifOrientation))) then
|
if FInfo.saw_EXIF_marker and (FInfo.orientation >= Ord(Low(TExifOrientation))) and (FInfo.orientation <= Ord(High(TExifOrientation))) then
|
||||||
FOrientation := TExifOrientation(FInfo.orientation)
|
FOrientation := TExifOrientation(FInfo.orientation)
|
||||||
else
|
else
|
||||||
FOrientation := Low(TExifOrientation);
|
FOrientation := Low(TExifOrientation);
|
||||||
S := TranslateSize(TSize.Create(FInfo.image_width, FInfo.image_height));
|
|
||||||
FWidth := S.Width;
|
|
||||||
FHeight := S.Height;
|
|
||||||
|
|
||||||
FGrayscale := FInfo.jpeg_color_space = JCS_GRAYSCALE;
|
FGrayscale := FInfo.jpeg_color_space = JCS_GRAYSCALE;
|
||||||
FProgressiveEncoding := jpeg_has_multiple_scans(@FInfo);
|
FProgressiveEncoding := jpeg_has_multiple_scans(@FInfo);
|
||||||
@ -262,6 +247,7 @@ var
|
|||||||
c: word;
|
c: word;
|
||||||
Status,Scan: integer;
|
Status,Scan: integer;
|
||||||
ReturnValue,RestartLoop: Boolean;
|
ReturnValue,RestartLoop: Boolean;
|
||||||
|
LOutputSize: TSize;
|
||||||
|
|
||||||
procedure InitReadingPixels;
|
procedure InitReadingPixels;
|
||||||
var d1,d2:integer;
|
var d1,d2:integer;
|
||||||
@ -460,6 +446,24 @@ var
|
|||||||
inc(y);
|
inc(y);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TranslateSize(AWidth, AHeight: Integer): TSize;
|
||||||
|
begin
|
||||||
|
// image dimension depending on orientation
|
||||||
|
case FOrientation of
|
||||||
|
eoUnknown, eoNormal, eoMirrorHor, eoRotate180, eoMirrorVert:
|
||||||
|
begin
|
||||||
|
Result.Width := AWidth;
|
||||||
|
Result.Height := AHeight;
|
||||||
|
end;
|
||||||
|
eoMirrorHorRot270, eoRotate90, eoMirrorHorRot90, eoRotate270:
|
||||||
|
begin
|
||||||
|
Result.Width := AHeight;
|
||||||
|
Result.Height := AWidth;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
InitReadingPixels;
|
InitReadingPixels;
|
||||||
|
|
||||||
@ -469,7 +473,10 @@ begin
|
|||||||
|
|
||||||
jpeg_start_decompress(@FInfo);
|
jpeg_start_decompress(@FInfo);
|
||||||
|
|
||||||
Img.SetSize(FWidth,FHeight);
|
LOutputSize := TranslateSize(FInfo.output_width, FInfo.output_height);
|
||||||
|
FWidth := LOutputSize.Width;
|
||||||
|
FHeight := LOutputSize.Height;
|
||||||
|
Img.SetSize(FWidth, FHeight);
|
||||||
|
|
||||||
GetMem(SampArray,SizeOf(JSAMPROW));
|
GetMem(SampArray,SizeOf(JSAMPROW));
|
||||||
GetMem(SampRow,FInfo.output_width*FInfo.output_components);
|
GetMem(SampRow,FInfo.output_width*FInfo.output_components);
|
||||||
|
Loading…
Reference in New Issue
Block a user