1 | // |
2 | // Util.cpp |
3 | // |
4 | // Library: PDF |
5 | // Package: PDFCore |
6 | // Module: Util |
7 | // |
8 | // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | #include "Poco/PDF/Util.h" |
15 | #include "bmpread.h" |
16 | #include "hpdf.h" |
17 | #include "hpdf_utils.h" |
18 | |
19 | |
20 | namespace Poco { |
21 | namespace PDF { |
22 | |
23 | |
24 | HPDF_Image LoadBMPImageFromFile(HPDF_Doc pdf, const char* filename) |
25 | { |
26 | HPDF_Stream imagedata; |
27 | HPDF_Image image; |
28 | |
29 | HPDF_PTRACE((" LoadBMPImageFromFile\n" )); |
30 | |
31 | if (!HPDF_HasDoc(pdf)) |
32 | return NULL; |
33 | |
34 | /* create file stream */ |
35 | imagedata = HPDF_FileReader_New(pdf->mmgr, filename); |
36 | |
37 | if (HPDF_Stream_Validate(imagedata)) |
38 | { |
39 | bmpread_t bmp; |
40 | unsigned int flags = BMPREAD_ANY_SIZE | BMPREAD_TOP_DOWN; |
41 | if (!bmpread(filename, flags, &bmp)) { |
42 | image = NULL; |
43 | } |
44 | else |
45 | { |
46 | //BMP Loaded |
47 | HPDF_UINT width = bmp.width; |
48 | HPDF_UINT height = bmp.height; |
49 | HPDF_ColorSpace color_space = HPDF_CS_DEVICE_RGB;//HPDF_CS_CAL_RGB |
50 | HPDF_UINT bits_per_component = 8; |
51 | image = HPDF_LoadRawImageFromMem(pdf, bmp.data, width, height, color_space, bits_per_component); |
52 | bmpread_free(&bmp); |
53 | } |
54 | } |
55 | else |
56 | { |
57 | image = NULL; |
58 | } |
59 | |
60 | /* destroy file stream */ |
61 | HPDF_Stream_Free(imagedata); |
62 | |
63 | if (!image) HPDF_CheckError(&pdf->error); |
64 | |
65 | return image; |
66 | } |
67 | |
68 | |
69 | } } // namespace Poco::PDF |
70 | |