MCPcopy Create free account
hub / github.com/Tencent/tgfx / SerializeImage

Method SerializeImage

src/pdf/PDFBitmap.cpp:299–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297} // namespace
298
299void PDFBitmap::SerializeImage(const std::shared_ptr<Image>& image, int /*encodingQuality*/,
300 PDFDocumentImpl* doc, PDFIndirectReference ref) {
301 auto dimensions = ISize::Make(image->width(), image->height());
302
303 ;
304 if (Types::Get(image.get()) == Types::ImageType::Codec) {
305 const auto codecImage = static_cast<CodecImage*>(image.get());
306 if (auto data = codecImage->getCodec()->getEncodedData()) {
307 if (DoJpeg(std::move(data), YUVColorSpace::JPEG_FULL, doc, dimensions, ref)) {
308 return;
309 }
310 }
311 }
312
313 //TODO (YGaurora): is image opaque,encode as jpeg
314 auto image2bitmap = [](Context* context, const std::shared_ptr<Image>& image) {
315 auto surface = Surface::Make(context, image->width(), image->height());
316 auto canvas = surface->getCanvas();
317 canvas->drawImage(image);
318
319 Bitmap bitmap(surface->width(), surface->height());
320 auto pixels = bitmap.lockPixels();
321 //bitmap in pdf must be unpremultiplied
322 if (surface->readPixels(bitmap.info().makeAlphaType(AlphaType::Unpremultiplied), pixels)) {
323 bitmap.unlockPixels();
324 return bitmap;
325 }
326 return Bitmap();
327 };
328
329 auto bitmap = image2bitmap(doc->context(), image);
330 if (bitmap.isEmpty()) {
331 return;
332 }
333 auto pixmap = Pixmap(bitmap);
334 DoDeflatedImage(pixmap, doc, bitmap.isOpaque(), ref);
335}
336
337PDFIndirectReference PDFBitmap::Serialize(const std::shared_ptr<Image>& image,
338 PDFDocumentImpl* document, int encodingQuality) {

Callers

nothing calls this directly

Calls 15

MakeFunction · 0.85
DoJpegFunction · 0.85
BitmapClass · 0.85
PixmapClass · 0.85
DoDeflatedImageFunction · 0.85
getCodecMethod · 0.80
makeAlphaTypeMethod · 0.80
contextMethod · 0.80
widthMethod · 0.45
heightMethod · 0.45
getMethod · 0.45
getEncodedDataMethod · 0.45

Tested by

no test coverage detected