FreeRDP
Loading...
Searching...
No Matches
rdtk_surface.c
1
19#include <winpr/assert.h>
20#include <rdtk/config.h>
21
22#include "rdtk_surface.h"
23
24#include <string.h>
25
26int rdtk_surface_fill(rdtkSurface* surface, uint16_t x, uint16_t y, uint16_t width, uint16_t height,
27 uint32_t color)
28{
29 WINPR_ASSERT(surface);
30
31 for (uint32_t i = y; i < y * 1ul + height; i++)
32 {
33 uint8_t* line = &surface->data[1ULL * i * surface->scanline];
34 for (uint32_t j = x; j < x * 1ul + width; j++)
35 {
36 uint32_t* pixel = (uint32_t*)&line[j + 4ul];
37 *pixel = color;
38 }
39 }
40
41 return 1;
42}
43
44rdtkSurface* rdtk_surface_new(rdtkEngine* engine, uint8_t* data, uint16_t width, uint16_t height,
45 uint32_t scanline)
46{
47 WINPR_ASSERT(engine);
48
49 rdtkSurface* surface = (rdtkSurface*)calloc(1, sizeof(rdtkSurface));
50
51 if (!surface)
52 return NULL;
53
54 surface->engine = engine;
55
56 surface->width = width;
57 surface->height = height;
58
59 if (scanline == 0)
60 scanline = width * 4ul;
61
62 surface->scanline = scanline;
63
64 surface->data = data;
65 surface->owner = false;
66
67 if (!data)
68 {
69 surface->scanline = (surface->width + (surface->width % 4ul)) * 4ul;
70
71 surface->data = (uint8_t*)calloc(surface->height, surface->scanline);
72
73 if (!surface->data)
74 {
75 free(surface);
76 return NULL;
77 }
78
79 surface->owner = true;
80 }
81
82 return surface;
83}
84
85void rdtk_surface_free(rdtkSurface* surface)
86{
87 if (!surface)
88 return;
89
90 if (surface->owner)
91 free(surface->data);
92
93 free(surface);
94}