51 CFX_DIBAttribute* pAttribute) {
53#if defined(PNG_pHYs_SUPPORTED)
54 pAttribute->m_nXDPI = png_get_x_pixels_per_meter(png_ptr, info_ptr);
55 pAttribute->m_nYDPI = png_get_y_pixels_per_meter(png_ptr, info_ptr);
56 png_uint_32 res_x, res_y;
58 png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, &unit_type);
60 case PNG_RESOLUTION_METER:
61 pAttribute->m_wDPIUnit = CFX_DIBAttribute::kResUnitMeter;
64 pAttribute->m_wDPIUnit = CFX_DIBAttribute::kResUnitNone;
67#if defined(PNG_iCCP_SUPPORTED)
69 png_bytep icc_profile;
70 png_uint_32 icc_proflen;
72 png_get_iCCP(png_ptr, info_ptr, &icc_name, &compress_type, &icc_profile,
75#if defined(PNG_TEXT_SUPPORTED)
77 png_textp text =
nullptr;
78 png_get_text(png_ptr, info_ptr, &text, &num_text);
85 reinterpret_cast<CPngContext*>(png_get_progressive_ptr(png_ptr));
89 png_uint_32 width = 0;
90 png_uint_32 height = 0;
93 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bpc, &color_type,
nullptr,
95 int color_type1 = color_type;
97 png_set_strip_16(png_ptr);
99 png_set_expand_gray_1_2_4_to_8(png_ptr);
102 if (color_type == PNG_COLOR_TYPE_PALETTE)
103 png_set_palette_to_rgb(png_ptr);
105 int pass = png_set_interlace_handling(png_ptr);
107 if (!pContext->m_pDelegate->PngReadHeader(width, height, bpc, pass,
108 &color_type, &gamma)) {
109 png_error(pContext->m_pPng,
"Read Header Callback Error");
112 if (png_get_sRGB(png_ptr, info_ptr, &intent)) {
113 png_set_gamma(png_ptr, gamma, 0.45455);
116 if (png_get_gAMA(png_ptr, info_ptr, &image_gamma))
117 png_set_gamma(png_ptr, gamma, image_gamma);
119 png_set_gamma(png_ptr, gamma, 0.45455);
121 switch (color_type) {
122 case PNG_COLOR_TYPE_GRAY:
123 case PNG_COLOR_TYPE_GRAY_ALPHA: {
124 if (color_type1 & PNG_COLOR_MASK_COLOR) {
125 png_set_rgb_to_gray(png_ptr, 1, 0.299, 0.587);
128 case PNG_COLOR_TYPE_PALETTE:
129 if (color_type1 != PNG_COLOR_TYPE_PALETTE) {
130 png_error(pContext->m_pPng,
"Not Support Output Palette Now");
133 case PNG_COLOR_TYPE_RGB:
134 case PNG_COLOR_TYPE_RGB_ALPHA:
135 if (!(color_type1 & PNG_COLOR_MASK_COLOR)) {
136 png_set_gray_to_rgb(png_ptr);
138 png_set_bgr(png_ptr);
141 if (!(color_type & PNG_COLOR_MASK_ALPHA))
142 png_set_strip_alpha(png_ptr);
144 if (color_type & PNG_COLOR_MASK_ALPHA &&
145 !(color_type1 & PNG_COLOR_MASK_ALPHA)) {
146 png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
148 png_read_update_info(png_ptr, info_ptr);
158 reinterpret_cast<CPngContext*>(png_get_progressive_ptr(png_ptr));
163 if (!pContext->m_pDelegate->PngAskScanlineBuf(row_num, &src_buf))
164 png_error(png_ptr,
"Ask Scanline buffer Callback Error");
167 png_progressive_combine_row(png_ptr, src_buf, new_row);
169 pContext->m_pDelegate->PngFillScanlineBufCompleted(pass, row_num);
185std::unique_ptr<ProgressiveDecoderIface::Context>
PngDecoder::StartDecode(
187 auto p =
std::make_unique<CPngContext>(pDelegate);
189 png_create_read_struct(PNG_LIBPNG_VER_STRING,
nullptr,
nullptr,
nullptr);
193 p->m_pInfo = png_create_info_struct(p->m_pPng);
197 if (setjmp(png_jmpbuf(p->m_pPng)))
200 png_set_progressive_read_fn(p->m_pPng, p.get(), _png_get_header_func,
201 _png_get_row_func, _png_get_end_func);
202 png_set_error_fn(p->m_pPng, p->m_szLastError, _png_error_data,
210 CFX_DIBAttribute* pAttribute) {
211 auto* ctx =
static_cast<CPngContext*>(pContext);
212 if (setjmp(png_jmpbuf(ctx->m_pPng))) {
215 _png_load_bmp_attribute(ctx->m_pPng, ctx->m_pInfo, pAttribute);
219 pdfium::span<uint8_t> src_buf = codec_memory->GetUnconsumedSpan();
220 png_process_data(ctx->m_pPng, ctx->m_pInfo, src_buf.data(), src_buf.size());
CPngContext(PngDecoder::Delegate *pDelegate)
char m_szLastError[PNG_ERROR_SIZE]
UnownedPtr< PngDecoder::Delegate > const m_pDelegate