Hi,<br><br>I have a problem and a couple of questions related thereto.<br><br>The problem: I am trying to convert a programmatically generated RGB Buffer to a Cairo surface. Up till now, I have used GDK to create all my graphics (since I started before Cairo came to be, and required display within a GUI), but now need to convert to Cairo since I need to generate these PDF plots in the background on a server machine without a display. All fine and good.<br>
<br>Until I try to understand how to convert my gdk_* routines to their cairo equivalents.<br><br>In GDK, once I have created and filled my RGB buffer (3-byte color, RGB), I call:<br><br><font face="arial,sans-serif"><span style="font-family: courier new,monospace;">rgbbuf = malloc(wL * hL * 3); // RGB Buffer - 3-byte color - RGB<br>
memset(rgbbuf, 240, wL * hL * 3); // make the grey background<br>
pdf(rgbbuf, wL, hL, pdfReq, &gr, perB); // make the PDF plot<br>
<br>
</span></font><span style="font-family: courier new,monospace;">gdk_draw_rgb_image (pmap, gc, sideM, topM, wL, hL, GDK_RGB_DITHER_NONE, rgbbuf, wL*3);</span><br><br><font face="arial,sans-serif">After investigating how to do this in Cairo, I came up with this replacement:<br>
<br><span style="font-family: courier new,monospace;">rgbbuf = malloc(wL * hL * 4); // RGB Buffer - 4-byte color - ARGB<br>memset(rgbbuf, 240, wL * hL * 4); // make the grey background<br>pdf(rgbbuf, wL, hL, pdfReq, &gr, perB);</span></font><font face="arial,sans-serif"><span style="font-family: courier new,monospace;"> // make the PDF plot</span></font><br>
<font face="arial,sans-serif"><span style="font-family: courier new,monospace;"><br>pdfOut = cairo_image_surface_create_for_data(rgbbuf, CAIRO_FORMAT_RGB24, wL, hL, wL*4);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">cairo_set_source_surface (cr, pdfOut, sideM, topM); </span></font><font face="arial,sans-serif"><span style="font-family: courier new,monospace;">// cr is previously created</span></font><font face="arial,sans-serif"><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">cairo_rectangle (cr, sideM, topM, wL, hL); </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">cairo_fill (cr);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">cairo_surface_destroy (pdfOut);</span><br style="font-family: courier new,monospace;"><br>I have modified the RGB buffer size to 4-byte colors (ARGB) and filled it according to the <span style="font-family: courier new,monospace;">cairo_format_t</span> definition for </font><font size="4"><span style="font-family: courier new,monospace;" class="term"><code class="literal">CAIRO_FORMAT_RGB24<font face="arial,sans-serif">. However, this does not result in a picture that is correct.<br>
<br>My suspicion is that since the row stride is being optimized by Cairo, it does not nicely align on a boundary of width*4. The documentation currently states that in order to obtain the proper stride, the routine<font size="2"> </font></font></code></span></font><font style="font-family: courier new,monospace;" size="2">cairo_format_stride_for_width() <font face="arial,sans-serif">should be used. And also says that this is available since 1.6.<br>
<br>My questions:<br></font></font><ol><li>I do not find a v1.6 of Cairo available from the download site. Is it really true? The documentation preceeds the release of the software itself? (wow...) Or am I missing something? <br>
</li><li>If v1.6 isn't yet available, how do I get the optimized stride defined internally by Cairo?<br></li><li>Anyway, assuming for the moment this routine existed, how would I use it properly? Meaning, how do I programmatically generate a RGB buffer for display?</li>
</ol>My guess at Q3 would be:<br><ol><li>obtain the row stride using the cairo routine.</li><li>fill my RGB buffer, row by row, keeping track when i've hit the stride (computed in 1) to advance to the next proper 4-byte RGB location.</li>
</ol>This is based, however, on too many assumptions:<br><ol><li>I'm assuming that to optimize, Cairo makes the stride bigger (smaller makes no sense to me) than simply width*4 bytes.</li><li>Every row is guaranteed to be the same? Including the last?<br>
</li><li>Where are the empty bytes placed? at the end of the row or at the beginning? <br></li><li>Is the stride always a multiple of 4?<br></li></ol>More generally, it seems that programmatically generating a RGB buffer for conversion to a Cairo surface is not obvious (to me, yet). Am I wrong about this? Is there a more straightforward way of doing this I haven't yet teased from the documentation? Is there a different way of accessing the individual pixels of an RGB buffer I am unaware of that would allow me to fill them up individually without having to make wrong assumptions and guesses?<br>
<br>Any information to help me out of my pickle would be greatly appreciated.<br><br>regards,<br><br>richard<br>