Coverage Report

Created: 2026-10-17 07:00

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
11.3k
static void do_drawing(cairo_t *cr, const uint8_t *data, size_t size) {
23
11.3k
    if (size < 4) return;
24
25
    // Use some bytes for color and basic params
26
11.2k
    double r = data[0] / 255.0;
27
11.2k
    double g = data[1] / 255.0;
28
11.2k
    double b = data[2] / 255.0;
29
11.2k
    double a = data[3] / 255.0;
30
31
11.2k
    cairo_set_source_rgba(cr, r, g, b, a);
32
11.2k
    cairo_set_line_width(cr, (size > 4 ? data[4] : 10) / 10.0);
33
34
11.2k
    size_t offset = 5;
35
3.98M
    while (offset + 16 <= size) {
36
3.97M
        uint8_t op = data[offset++] % 8;
37
3.97M
        double x1 = data[offset++];
38
3.97M
        double y1 = data[offset++];
39
3.97M
        double x2 = data[offset++];
40
3.97M
        double y2 = data[offset++];
41
3.97M
        double x3 = data[offset++];
42
3.97M
        double y3 = data[offset++];
43
        
44
3.97M
        switch (op) {
45
452k
            case 0:
46
452k
                cairo_move_to(cr, x1, y1);
47
452k
                break;
48
147k
            case 1:
49
147k
                cairo_line_to(cr, x1, y1);
50
147k
                break;
51
357k
            case 2:
52
357k
                cairo_curve_to(cr, x1, y1, x2, y2, x3, y3);
53
357k
                break;
54
762k
            case 3:
55
762k
                cairo_rectangle(cr, x1, y1, x2, y2);
56
762k
                break;
57
1.62M
            case 4:
58
1.62M
                cairo_arc(cr, x1, y1, x2 / 10.0, 0, 2 * 3.14159);
59
1.62M
                break;
60
290k
            case 5:
61
290k
                cairo_fill(cr);
62
290k
                cairo_set_source_rgba(cr, x1/255.0, y1/255.0, x2/255.0, y2/255.0);
63
290k
                break;
64
95.3k
            case 6:
65
95.3k
                cairo_stroke(cr);
66
95.3k
                break;
67
241k
            case 7:
68
241k
                cairo_clip(cr);
69
241k
                break;
70
3.97M
        }
71
3.97M
        offset += 10; // skip some bytes to use for next ops
72
3.97M
    }
73
11.2k
}
74
75
#endif