lazarus-ccr/components/powerpdf/PdfJpegImage.pas
jesusr 87fdff01a2 PowerPDF Check In
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@585 8e941d3f-bd1b-0410-a28a-d453659cc2b4
2008-10-06 15:02:30 +00:00

84 lines
2.2 KiB
ObjectPascal

{*
* << P o w e r P d f >> -- PdfJpegImage.pas
*
* Copyright (c) 1999-2001 Takezou. <takeshi_kanno@est.hi-ho.ne.jp>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Library General Public License as published
* by the Free Software Foundation; either version 2 of the License, or any
* later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library.
*
* 2001.06.14 create
* 2001.09.07 changes the implementation of TPdfImageCreator.
*
*}
unit PdfJpegImage;
interface
uses
SysUtils, Classes, Graphics, PdfTypes, PdfDoc, PdfImages
{$IFDEF LAZ_POWERPDF}
{$ELSE}
,JPEG
{$ENDIF}
;
type
{ TPdfJpegImage }
TPdfJpegImage = class(TPdfImageCreator)
public
function CreateImage(AImage: TGraphic): TPdfImage; override;
end;
implementation
// CreateImage
function TPdfJpegImage.CreateImage(AImage: TGraphic): TPdfImage;
begin
// check whether specified graphic is valid image.
if not (AImage is TJpegImage) then
raise EPdfInvalidValue.Create('only jpeg image is allowed.');
result := TPdfImage.CreateStream(nil);
with result do
try
TJpegImage(AImage).SaveToStream(Stream);
with Attributes do
begin
AddItem('Type', TPdfName.CreateName('XObject'));
AddItem('Subtype', TPdfName.CreateName('Image'));
AddItem('ColorSpace', TPdfName.CreateName('DeviceRGB'));
AddItem('Width', TPdfNumber.CreateNumber(AImage.Width));
AddItem('Height', TPdfNumber.CreateNumber(AImage.Height));
AddItem('BitsPerComponent', TPdfNumber.CreateNumber(8));
PdfArrayByName('Filter').AddItem(TPdfName.CreateName('DCTDecode'));
end;
except
result.Free;
raise;
end;
end;
initialization
{$IFDEF LAZ_POWERPDF}
PdfLazRegisterClassAlias(TPdfJpegImage, 'Pdf-Jpeg');
{$ELSE}
RegisterClassAlias(TPdfJpegImage, 'Pdf-Jpeg');
{$ENDIF}
finalization
UnRegisterClass(TPdfJpegImage);
end.