xs/image.xs

filter: Statementstmt 73.1% 30 / 41 Branchbran 50.0% 23 / 46 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 60.9% 53 / 87 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/pdfmake_content.c ↑ Summary src/pdfmake_form.c »
1 MODULE = PDF::Make PACKAGE = PDF::Make::Image
2 PROTOTYPES: ENABLE
3  
4 SV *
5 from_file(class, path)
6 char *class
7 const char *path
8 PREINIT:
9 FILE *fp;
10 long file_len;
11 uint8_t *buf;
12 size_t nread;
13 pdfmake_image_t *img;
14 CODE:
15 PERL_UNUSED_VAR(class);
16 19 fp = fopen(path, "rb");
17 19 ▶ if (!fp)
Branch: 1 branch
BranchTrueFalseTotal
if (!fp) 0 19 19
18 0 croak("PDF::Make::Image: cannot open '%s'", path);
19 19 ▶ if (fseek(fp, 0, SEEK_END) != 0) { fclose(fp); croak("PDF::Make::Image: seek failed"); }
Branch: 1 branch
BranchTrueFalseTotal
if (fseek(fp, 0, SEEK_END) != 0) { fclose(fp); croak("PDF::Make::Image: seek failed"); } 0 19 19
20 19 file_len = ftell(fp);
21 19 ▶ if (file_len < 0) { fclose(fp); croak("PDF::Make::Image: tell failed"); }
Branch: 1 branch
BranchTrueFalseTotal
if (file_len < 0) { fclose(fp); croak("PDF::Make::Image: tell failed"); } 0 19 19
22 19 rewind(fp);
23 19 buf = malloc((size_t)file_len);
24 19 ▶ if (!buf) { fclose(fp); croak("PDF::Make::Image: malloc failed"); }
Branch: 1 branch
BranchTrueFalseTotal
if (!buf) { fclose(fp); croak("PDF::Make::Image: malloc failed"); } 0 19 19
25 19 nread = fread(buf, 1, (size_t)file_len, fp);
26 19 fclose(fp);
27 19 ▶ if ((long)nread != file_len) { free(buf); croak("PDF::Make::Image: short read"); }
Branch: 1 branch
BranchTrueFalseTotal
if ((long)nread != file_len) { free(buf); croak("PDF::Make::Image: short read"); } 0 19 19
28  
29 /* Auto-detect and parse — pass NULL for doc since we don't need arena yet */
30 19 img = pdfmake_image_from_bytes(NULL, buf, (size_t)file_len);
31 19 free(buf);
32 19 ▶ if (!img)
Branch: 1 branch
BranchTrueFalseTotal
if (!img) 0 19 19
33 0 croak("PDF::Make::Image: failed to parse image '%s'", path);
34  
35 19 RETVAL = sv_newmortal();
36 19 sv_setref_pv(RETVAL, "PDF::Make::Image", (void *)img);
37 19 SvREFCNT_inc(RETVAL);
38 OUTPUT:
39 RETVAL
40  
41 SV *
42 from_bytes(class, bytes_sv)
43 char *class
44 SV *bytes_sv
45 PREINIT:
46 STRLEN len;
47 const uint8_t *buf;
48 pdfmake_image_t *img;
49 CODE:
50 PERL_UNUSED_VAR(class);
51 0 buf = (const uint8_t *)SvPV(bytes_sv, len);
52 0 img = pdfmake_image_from_bytes(NULL, buf, len);
53 0 ▶ if (!img)
Branch: 1 branch
BranchTrueFalseTotal
if (!img) 0 0 0
54 0 croak("PDF::Make::Image: failed to parse image bytes");
55 0 RETVAL = sv_newmortal();
56 0 sv_setref_pv(RETVAL, "PDF::Make::Image", (void *)img);
57 0 SvREFCNT_inc(RETVAL);
58 OUTPUT:
59 RETVAL
60  
61 UV
62 width(self)
63 pdfmake_image_t *self
64 CODE:
65 18 ▶ RETVAL = self->width;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->width; 12 6 18
66 OUTPUT:
67 RETVAL
68  
69 UV
70 height(self)
71 pdfmake_image_t *self
72 CODE:
73 18 ▶ RETVAL = self->height;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->height; 12 6 18
74 OUTPUT:
75 RETVAL
76  
77 IV
78 format(self)
79 pdfmake_image_t *self
80 CODE:
81 2 ▶ RETVAL = self->format;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->format; 0 2 2
82 OUTPUT:
83 RETVAL
84  
85 IV
86 components(self)
87 pdfmake_image_t *self
88 CODE:
89 1 ▶ RETVAL = self->components;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->components; 0 1 1
90 OUTPUT:
91 RETVAL
92  
93 int
94 has_alpha(self)
95 pdfmake_image_t *self
96 CODE:
97 0 ▶ RETVAL = self->has_alpha;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = self->has_alpha; 0 0 0
98 OUTPUT:
99 RETVAL
100  
101 UV
102 write_to_doc(self, doc)
103 pdfmake_image_t *self
104 pdfmake_doc_t *doc
105 CODE:
106 17 RETVAL = pdfmake_image_write(self, doc);
107 17 ▶ if (RETVAL == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL == 0) 0 17 17
108 0 croak("PDF::Make::Image: failed to write image to document");
109 OUTPUT:
110 RETVAL
111  
112 void
113 DESTROY(self)
114 pdfmake_image_t *self
115 CODE:
116 19 pdfmake_image_free(self);
117  
118 BOOT:
119 {
120 104 HV *stash = gv_stashpv("PDF::Make::Image", GV_ADD);
121 104 ▶ PDFMAKE_REGISTER_GETTER(stash, "width", pdfmake_image_t, width, PDFMAKE_FIELD_INT);
Branch: 2 branches
BranchTrueFalseTotal
PDFMAKE_REGISTER_GETTER(stash, "width", pdfmake_image_t, width, PDFMAKE_FIELD_INT); 104 0 104
PDFMAKE_REGISTER_GETTER(stash, "width", pdfmake_image_t, width, PDFMAKE_FIELD_INT); 104 0 104
122 104 ▶ PDFMAKE_REGISTER_GETTER(stash, "height", pdfmake_image_t, height, PDFMAKE_FIELD_INT);
Branch: 2 branches
BranchTrueFalseTotal
PDFMAKE_REGISTER_GETTER(stash, "height", pdfmake_image_t, height, PDFMAKE_FIELD_INT); 104 0 104
PDFMAKE_REGISTER_GETTER(stash, "height", pdfmake_image_t, height, PDFMAKE_FIELD_INT); 104 0 104
123 104 ▶ PDFMAKE_REGISTER_GETTER(stash, "format", pdfmake_image_t, format, PDFMAKE_FIELD_INT);
Branch: 2 branches
BranchTrueFalseTotal
PDFMAKE_REGISTER_GETTER(stash, "format", pdfmake_image_t, format, PDFMAKE_FIELD_INT); 104 0 104
PDFMAKE_REGISTER_GETTER(stash, "format", pdfmake_image_t, format, PDFMAKE_FIELD_INT); 104 0 104
124 104 ▶ PDFMAKE_REGISTER_GETTER(stash, "components", pdfmake_image_t, components, PDFMAKE_FIELD_INT);
Branch: 2 branches
BranchTrueFalseTotal
PDFMAKE_REGISTER_GETTER(stash, "components", pdfmake_image_t, components, PDFMAKE_FIELD_INT); 104 0 104
PDFMAKE_REGISTER_GETTER(stash, "components", pdfmake_image_t, components, PDFMAKE_FIELD_INT); 104 0 104
125 104 ▶ PDFMAKE_REGISTER_GETTER(stash, "has_alpha", pdfmake_image_t, has_alpha, PDFMAKE_FIELD_INT);
Branch: 2 branches
BranchTrueFalseTotal
PDFMAKE_REGISTER_GETTER(stash, "has_alpha", pdfmake_image_t, has_alpha, PDFMAKE_FIELD_INT); 104 0 104
PDFMAKE_REGISTER_GETTER(stash, "has_alpha", pdfmake_image_t, has_alpha, PDFMAKE_FIELD_INT); 104 0 104
126 }
« src/pdfmake_content.c ↑ Summary src/pdfmake_form.c »