acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
surface.h
1
//
2
// Created by camilo on 2024-10-01 05:36 <3ThomasBorregaardSorensen!!
3
//
4
#pragma once
5
6
7
#include "acme/graphics/image/pixmap.h"
8
#include <cairo/cairo.h>
9
10
11
inline
cairo_surface_t * cairo_surface_for_pixmap(
::pixmap
&
pixmap
)
12
{
13
14
return
cairo_image_surface_create_for_data(
15
(::u8 *)
pixmap
.m_pimage32,
// Pointer to the raw data in memory
16
CAIRO_FORMAT_ARGB32,
// Data format (ARGB32)
17
pixmap
.width(),
// Width of the surface
18
pixmap
.height(),
// Height of the surface
19
pixmap
.m_iScan
// Stride (number of bytes per row)
20
);
21
22
}
23
24
25
inline ::pixmap get_raw_data_from_cairo_surface(
::memory
& memoryHost, cairo_surface_t *surface) {
26
// Ensure the surface format is ARGB32
27
if
(cairo_image_surface_get_format(surface) != CAIRO_FORMAT_ARGB32) {
28
fprintf(stderr,
"Surface format is not ARGB32.\n"
);
29
return
{};
30
}
31
32
// Get the width, height, and stride of the surface
33
::i32 width = cairo_image_surface_get_width(surface);
34
::i32 height = cairo_image_surface_get_height(surface);
35
::i32 stride = cairo_image_surface_get_stride(surface);
36
37
// Get the raw pixel data
38
::u8 *data = cairo_image_surface_get_data(surface);
39
40
// Ensure the data is not NULL
41
if
(!data) {
42
fprintf(stderr,
"Failed to get the surface data.\n"
);
43
return
{};
44
}
45
46
memoryHost.set_size(stride * height);
47
48
::pixmap
pixmap
;
49
50
//memcpy(memoryHost.data(), data, memoryHost.size());
51
52
pixmap
.m_pimage32 = (
::image32_t
*) memoryHost.data();
53
pixmap
.m_sizeRaw.cx = width;
54
pixmap
.m_sizeRaw.cy = height;
55
pixmap
.m_size.cx = width;
56
pixmap
.m_size.cy = height;
57
pixmap
.m_iScan = stride;
58
59
pixmap
.m_pimage32->copy_swap_red_blue(width, height,stride, (
image32_t
*) data, stride);
60
61
return
pixmap
;
62
63
}
memory
Definition
memory.h:33
image32_t
Definition
image32.h:30
pixmap
Definition
pixmap.h:25
integrate
cairo
surface.h
Generated by
1.17.0