Coverage Report

Created: 2026-10-04 06:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fuzz/common_drawing.h
Line
Count
Source
1
// Copyright 2026 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef COMMON_DRAWING_H
16
#define COMMON_DRAWING_H
17
18
#include <cairo.h>
19
#include <stdint.h>
20
#include <string.h>
21
22
9.97k
static void do_drawing(cairo_t *cr, const uint8_t *data, size_t size) {
23
9.97k
    if (size < 4) return;
24
25
    // Use some bytes for color and basic params
26
9.83k
    double r = data[0] / 255.0;
27
9.83k
    double g = data[1] / 255.0;
28
9.83k
    double b = data[2] / 255.0;
29
9.83k
    double a = data[3] / 255.0;
30
31
9.83k
    cairo_set_source_rgba(cr, r, g, b, a);
32
9.83k
    cairo_set_line_width(cr, (size > 4 ? data[4] : 10) / 10.0);
33
34
9.83k
    size_t offset = 5;
35
3.74M
    while (offset + 16 <= size) {
36
3.73M
        uint8_t op = data[offset++] % 8;
37
3.73M
        double x1 = data[offset++];
38
3.73M
        double y1 = data[offset++];
39
3.73M
        double x2 = data[offset++];
40
3.73M
        double y2 = data[offset++];
41
3.73M
        double x3 = data[offset++];
42
3.73M
        double y3 = data[offset++];
43
        
44
3.73M
        switch (op) {
45
477k
            case 0:
46
477k
                cairo_move_to(cr, x1, y1);
47
477k
                break;
48
266k
            case 1:
49
266k
                cairo_line_to(cr, x1, y1);
50
266k
                break;
51
235k
            case 2:
52
235k
                cairo_curve_to(cr, x1, y1, x2, y2, x3, y3);
53
235k
                break;
54
749k
            case 3:
55
749k
                cairo_rectangle(cr, x1, y1, x2, y2);
56
749k
                break;
57
1.27M
            case 4:
58
1.27M
                cairo_arc(cr, x1, y1, x2 / 10.0, 0, 2 * 3.14159);
59
1.27M
                break;
60
378k
            case 5:
61
378k
                cairo_fill(cr);
62
378k
                cairo_set_source_rgba(cr, x1/255.0, y1/255.0, x2/255.0, y2/255.0);
63
378k
                break;
64
129k
            case 6:
65
129k
                cairo_stroke(cr);
66
129k
                break;
67
220k
            case 7:
68
220k
                cairo_clip(cr);
69
220k
                break;
70
3.73M
        }
71
3.73M
        offset += 10; // skip some bytes to use for next ops
72
3.73M
    }
73
9.83k
}
74
75
#endif