MCPcopy Create free account
hub / github.com/docling-project/docling-parse / bitmap_artifact_export_visitor

Class bitmap_artifact_export_visitor

app/pybind_parse.cpp:195–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193 };
194
195 struct bitmap_artifact_export_visitor
196 {
197 pybind11::list artifacts;
198 int bitmap_index = 0;
199
200 void set_size(pdflib::size_instruction&) {}
201 void render_text(pdflib::text_instruction&) {}
202 void render_widget(pdflib::text_widget_instruction&) {}
203 void render_shape(pdflib::shape_instruction&) {}
204
205 void render_bitmap(pdflib::bitmap_instruction& instr)
206 {
207 ++bitmap_index;
208
209 pybind11::dict row;
210 row["index"] = bitmap_index;
211 row["xobject_key"] = instr.get_key();
212 row["shape"] = instr.get_shape();
213 row["pixel_format"] = pixel_format_name(instr.get_pixel_format());
214 row["image_mask"] = instr.is_image_mask();
215 row["has_soft_mask"] = instr.has_alpha_data();
216 row["rgb_filling"] = instr.get_rgb_filling();
217 row["quad"] = make_quad_dict(
218 instr.get_r_x0(), instr.get_r_y0(),
219 instr.get_r_x1(), instr.get_r_y1(),
220 instr.get_r_x2(), instr.get_r_y2(),
221 instr.get_r_x3(), instr.get_r_y3());
222
223 std::vector<uint8_t> encoded;
224 std::string extension = ".bin";
225
226 auto const& data = instr.get_data();
227 auto const& alpha_data = instr.get_alpha_data();
228 if(data)
229 {
230 row["raw_data"] = pybind11::bytes(
231 reinterpret_cast<char const*>(data->data()),
232 data->size());
233 }
234 else
235 {
236 row["raw_data"] = pybind11::bytes();
237 }
238
239 if(instr.has_data())
240 {
241 auto const& shape = instr.get_shape();
242 const int height = shape[0];
243 const int width = shape[1];
244
245 if(instr.get_pixel_format() == pdflib::PIXEL_FORMAT_GRAY)
246 {
247 encoded = pdflib::ccitt::encode_debug_png(*data, width, height);
248 extension = ".png";
249 }
250 else if(instr.get_pixel_format() == pdflib::PIXEL_FORMAT_RGB
251 or instr.get_pixel_format() == pdflib::PIXEL_FORMAT_CMYK)
252 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected