| 297 | } // namespace |
| 298 | |
| 299 | void 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 | |
| 337 | PDFIndirectReference PDFBitmap::Serialize(const std::shared_ptr<Image>& image, |
| 338 | PDFDocumentImpl* document, int encodingQuality) { |
nothing calls this directly
no test coverage detected