<div dir="auto">Hello Rafał,<div dir="auto"><br></div><div dir="auto">I believe you can use cairo_image_surface_create_for_data(), however you have to export the image data from GIMP as ARGB32 instead of RGBA32. If that's not possible then you must swap the color channels using a loop.</div><div dir="auto"><br></div><div dir="auto">Finally, for best results I'd make sure that the GIMP_IMAGE_pixel_data array is properly aligned to at least 4 bytes. The syntax depend on the compiler, see <a href="https://gcc.gnu.org/onlinedocs/gcc-3.3/gcc/Type-Attributes.html">https://gcc.gnu.org/onlinedocs/gcc-3.3/gcc/Type-Attributes.html</a> for GCC.</div><div dir="auto"><br></div><div dir="auto">cairo_surface_t *surface;</div><div dir="auto"><br></div><div dir="auto">cairo_format_t format = CAIRO_FORMAT_ARGB32;</div><div dir="auto">int stride = GIMP_IMAGE_WIDTH * GIMP_IMAGE_BYTES_PER_PIXEL;</div><div dir="auto"><br></div><div dir="auto">assert(cairo_format_stride_for_width (format, width) == stride);</div><div dir="auto"><br></div><div dir="auto">surface = cairo_image_surface_create_for_data(GIMP_IMAGE_pixel_data, format, GIMP_IMAGE_WIDTH, GIMP_IMAGE_HEIGHT,<br></div><div dir="auto">stride);</div><div dir="auto"><br></div><div dir="auto"><a href="https://www.cairographics.org/manual/cairo-Image-Surfaces.html#cairo-image-surface-create-for-data">https://www.cairographics.org/manual/cairo-Image-Surfaces.html#cairo-image-surface-create-for-data</a></div><div dir="auto"><br></div><div dir="auto">Luca</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il gio 13 ott 2022, 11:44 Rafał Jopek <<a href="mailto:rafaljopek@hotmail.com" target="_blank" rel="noreferrer">rafaljopek@hotmail.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Hi,</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Below is a sample image code generated in GIMP<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
What will the function in Cairo that allows drawing directly onto a surface generated source code in C.<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
 </div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
```</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<div style="color:#d4d4d4;background-color:#1e1e1e;font-family:'RobotoMono-Regular','Droid Sans Mono','monospace',monospace;font-weight:normal;line-height:22px">
<span><span style="color:#c586c0">#define</span><span style="color:#569cd6"> </span><span style="color:#569cd6">GIMP_IMAGE_WIDTH</span><span style="color:#569cd6"> (</span><span style="color:#b5cea8">4</span><span style="color:#569cd6">)</span></span></div>
<div style="color:#d4d4d4;background-color:#1e1e1e;font-family:'RobotoMono-Regular','Droid Sans Mono','monospace',monospace;font-weight:normal;line-height:22px">
<div><span style="color:#c586c0">#define</span><span style="color:#569cd6"> </span><span style="color:#569cd6">GIMP_IMAGE_HEIGHT</span><span style="color:#569cd6"> (</span><span style="color:#b5cea8">4</span><span style="color:#569cd6">)</span></div>
<div><span style="color:#c586c0">#define</span><span style="color:#569cd6"> </span><span style="color:#569cd6">GIMP_IMAGE_BYTES_PER_PIXEL</span><span style="color:#569cd6"> (</span><span style="color:#b5cea8">4</span><span style="color:#569cd6">)</span><span style="color:#6a9955"> /*
 2:RGB16, 3:RGB, 4:RGBA */</span></div>
<div><span style="color:#c586c0">#define</span><span style="color:#569cd6"> </span><span style="color:#569cd6">GIMP_IMAGE_PIXEL_DATA</span><span style="color:#569cd6"> ((unsigned
 char</span><span>*</span><span style="color:#569cd6">)
</span><span style="color:#9cdcfe">GIMP_IMAGE_pixel_data</span><span style="color:#569cd6">)</span></div>
<div><span style="color:#569cd6">static</span><span> </span><span style="color:#569cd6">const</span><span> </span><span style="color:#569cd6">unsigned</span><span> </span><span style="color:#569cd6">char</span><span> </span><span style="color:#9cdcfe">GIMP_IMAGE_pixel_data</span><span>[</span><span style="color:#b5cea8">4</span><span> *
</span><span style="color:#b5cea8">4</span><span> *
</span><span style="color:#b5cea8">4</span><span> +
</span><span style="color:#b5cea8">1</span><span>] =</span></div>
<div><span>(</span><span style="color:#ce9178">"</span><span style="color:#d7ba7d">\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\377\377\377\377\000\000\000\000\377\377\377\377\000</span><span style="color:#ce9178">"</span></div>
<div><span> </span><span style="color:#ce9178">"</span><span style="color:#d7ba7d">\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\377\377\377\377\000\000\000\000\377</span><span style="color:#ce9178">"</span></div>
<span><span> </span><span style="color:#ce9178">"</span><span style="color:#d7ba7d">\377\377\377</span><span style="color:#ce9178">"</span><span>);</span></span></div>
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
```</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Kind regards,<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
-- Rafał </div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
</div>

</blockquote></div>