Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assumeing the following API to get the image:</p> <pre><code>int ImageGet( char * pBuffer, size_t * pSize); /* returns 0 on success or any other value if no image is available or on error */ </code></pre> <p>you could do the following:</p> <pre><code>#include &lt;stdlib.h&gt; #include &lt;string.h&gt; ... #define IMAGESIZE_MAX (1024*1024) char * pBuffer = NULL; char * pBufferCurrent = pBuffer; int iResult = 0; size_t size = IMAGESIZE_MAX; size_t sizeTotal = 0; do { char * pBufferCurrent = realloc ( pBuffer, sizeTotal + sizeof(size) + size); if (!pBufferCurrent) { break; } pBuffer = pBufferCurrent; pBufferCurrent += sizeTotal; if ((iResult = ImageGet ( pBufferCurrent + sizeof(size), &amp;size)) { break; } memcpy ( pBufferCurrent, &amp;size, sizeof(size)); sizeTotal += (sizeof(size) + size); } while (1); ... </code></pre> <p>This stores your data sequentially:</p> <pre><code>[ size 1 ][ image data 1 ][ size 2 ][ image data 2 ]... &lt;-sizeof(size_t)-&gt;&lt;- size 1 -&gt;&lt;-sizeof(size_t)-&gt;&lt;- size 2 -&gt; </code></pre> <p>in the buffer pointed to by <code>pBuffer</code>.</p> <hr> <p>To retrieve a reference to the data describing image N from the buffer <code>pBuffer</code> you could use the following method:</p> <pre><code>const char * BufferImageGetByIndex( const char * pBuffer, unsigned indexImage) { for (unsigned indexImageCnt = 0; indexImageCnt &lt; indexImage; ++ indexImageCnt) { pBuffer += sizeof(size_t) + *((size_t *) pBuffer); } return pBuffer; } </code></pre> <p>Then to actually get an image you could do like so:</p> <pre><code>... /* Get a reference to the data decribing **fourth** image in the buffer filled by the example above. */ const char * pBufferImage4 = *BufferImageGetByIndex(pBuffer, 3); /* Get the size ... */ size_t sizeImage4 = *((size_t *) pBufferImage4); /* ... and a reference to the image data. */ const char * pImage4 = pBufferImage4 + sizeof(size_t); ... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload