THotPDF.AddImageWithSMask 메서드

 

THotPDF.AddImageWithSMask

THotPDF

 

Top  Previous  Next

컬러 image XObject와 PDF 1.4 soft-mask image XObject(ISO 32000-1 8.9.5.4)를 함께 추가하여, 기존 /ImageMask 경로의 이진 켜짐/꺼짐 한계 대신 픽셀 단위의 완전한 투명도를 가진 이미지를 만듭니다

 

Delphi syntax:

function AddImageWithSMask(Width, Height: Integer; const RGB: array of Byte; const Alpha: array of Byte): Integer;

function AddImageWithTransparency(Width, Height: Integer; const RGB: array of Byte; const Alpha: array of Byte): Integer;

function AddImageWithSMask32(Width, Height: Integer; const Pixels: array of Byte): Integer;

function AddImageWithTransparency32(Width, Height: Integer; const Pixels: array of Byte): Integer;

 

C++ syntax:

int AddImageWithSMask(int Width, int Height, const TBytes& RGB, const TBytes& Alpha);

int AddImageWithTransparency(int Width, int Height, const TBytes& RGB, const TBytes& Alpha);

int AddImageWithSMask32(int Width, int Height, const TBytes& Pixels);

int AddImageWithTransparency32(int Width, int Height, const TBytes& Pixels);

 

Description

SMask 이미지는 독립된 8비트 DeviceGray 채널을 가지며, 이 채널의 휘도가 그리는 시점에 컬러 이미지의 알파를 결정합니다(0 = 완전 투명, 255 = 완전 불투명). HotPDF는 두 plane을 모두 Flate 압축 image XObject로 기록하고, 컬러 이미지 dictionary의 /SMask 항목이 soft-mask XObject를 가리키도록 연결한 뒤, XImages 인덱스를 반환합니다. 이 인덱스는 THPDFPage.ShowImage가 그대로 받으므로 이후의 배치 코드는 모두 그대로 동작합니다

AddImageWithTransparency와 AddImageWithTransparency32는 동일한 PDF 1.4 soft-mask 워크플로우를 가리키는 별칭입니다. PDF 딕셔너리 용어보다 투명 이미지라는 관점으로 코드를 작성하는 호출부를 위해 제공됩니다

 

AddImageWithSMask(Width, Height, RGB, Alpha)

- Width / Height: pixel dimensions, identical for both planes.

- RGB: Width * Height * 3 bytes, row-major top-down, R G B interleaved per pixel (no row padding).

- Alpha: Width * Height bytes, row-major top-down, 8-bit luminosity per pixel.

 

AddImageWithSMask32(Width, Height, Pixels)

32비트 RGBA 패킹 입력을 위한 편의 오버로드입니다. Pixels에는 R, G, B, A 순서의 Width * Height * 4 바이트가 들어 있어야 합니다. HotPDF는 이 버퍼를 RGB 컬러 플레인과 8비트 알파 플레인으로 분리한 뒤 AddImageWithSMask에 넘깁니다

 

반환 값: XImages의 인덱스이며, AddImage가 반환하는 값과 동일합니다. 이 값을 THPDFPage.ShowImage에 전달하면 페이지에 이미지를 배치할 수 있습니다. -1을 반환하는 경우는 StrictVersionLock이 켜져 있고 현재 Version이 PDF 1.4 미만일 때입니다(그렇지 않으면 버전이 1.4로 자동 상향됩니다).

 

Code Example

// Raw-bytes path: build a 64x64 magenta-on-white plane + horizontal
// alpha gradient and place the result on the page
var
  RGB, Alpha: TBytes;
  W, H, X, Y, Idx, ImIdx: Integer;
begin
  W := 64;
  H := 64;
  SetLength(RGB,   W * H * 3);
  SetLength(Alpha, W * H);
  for Y := 0 to H - 1 do
    for X := 0 to W - 1 do
    begin
      Idx := Y * W + X;
      RGB[Idx * 3 + 0] := 255;    // R
      RGB[Idx * 3 + 1] := 0;      // G
      RGB[Idx * 3 + 2] := 255;    // B
      Alpha[Idx]       := Byte((X * 255) div (W - 1));
    end;

  HPDF.Version    := pdf14;       // SMask requires PDF 1.4
  HPDF.Compression := cmFlateDecode;
  HPDF.BeginDoc;
  ImIdx := HPDF.AddImageWithSMask(W, H, RGB, Alpha);
  HPDF.CurrentPage.ShowImage(ImIdx, 80, 80, 256, 256, 0);
  HPDF.EndDoc;
end;

 

See Also

AddImage, THPDFPage.ShowImage, Version, PDF Filter Support