Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/pdfcpu/readImage.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ func imgToImageDict(xRefTable *XRefTable, img image.Image) (*StreamDict, error)
buf = writeCMYKImageBuf(img)

case *image.YCbCr:
return nil, errors.New("unsupported image type: YCbCr")
cs = DeviceRGBCS
buf = writeRGBAImageBuf(convertToRGBA(img))

case *image.NYCbCrA:
return nil, errors.New("unsupported image type: NYCbCrA")
Expand Down
25 changes: 19 additions & 6 deletions pkg/pdfcpu/stamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/pdfcpu/pdfcpu/pkg/font"
"github.com/pdfcpu/pdfcpu/pkg/log"
"github.com/pdfcpu/pdfcpu/pkg/types"
"golang.org/x/image/webp"

"github.com/pkg/errors"
)
Expand Down Expand Up @@ -1124,7 +1125,7 @@ func createImageResource(xRefTable *XRefTable, r io.Reader) (*IndirectRef, int,
var sd *StreamDict
r = bytes.NewReader(bb)

// We identify JPG via its magic bytes.
// Identify JPG via its magic bytes.
if bytes.HasPrefix(bb, []byte("\xff\xd8")) {
// Process JPG by wrapping byte stream into DCTEncoded object stream.
c, _, err := image.DecodeConfig(r)
Expand All @@ -1138,11 +1139,23 @@ func createImageResource(xRefTable *XRefTable, r io.Reader) (*IndirectRef, int,
}

} else {
// Process other formats by decoding into an image
// and subsequent object stream encoding,
img, _, err := image.Decode(r)
if err != nil {
return nil, 0, 0, err

var img image.Image

// Identify WEBP via its magic bytes.
if bytes.HasPrefix(bb, []byte("\x52\x49\x46\x46")) &&
bytes.HasPrefix(bb[8:], []byte("\x57\x45\x42\x50")) {
img, err = webp.Decode(r)
if err != nil {
return nil, 0, 0, err
}
} else {
// Process other formats by decoding into an image
// and subsequent object stream encoding,
img, _, err = image.Decode(r)
if err != nil {
return nil, 0, 0, err
}
}

sd, err = imgToImageDict(xRefTable, img)
Expand Down