Ignore:
Timestamp:
May 21, 2009, 10:55:21 PM (11 years ago)
Author:
Sam Hocevar
Message:

Add caca_export_area_to_memory() to export only a selected part of the
current canvas. This is useful to export dirty rectangles. Accordingly,
add caca_import_area_from_memory() and caca_import_area_from_file().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/codec/export.c

    r3492 r3495  
    8181 *  \return A pointer to the exported memory area, or NULL in case of error.
    8282 */
    83 void *caca_export_memory(caca_canvas_t const *cv, char const *format,
    84                           size_t *bytes)
     83void *caca_export_canvas_to_memory(caca_canvas_t const *cv, char const *format,
     84                                   size_t *bytes)
    8585{
    8686    if(!strcasecmp("caca", format))
     
    119119    seterrno(EINVAL);
    120120    return NULL;
     121}
     122
     123/** \brief Export a canvas portion into a foreign format.
     124 *
     125 *  This function exports a portion of a \e libcaca canvas into various
     126 *  formats. For more information, see caca_export_canvas_to_memory().
     127 *
     128 *  If an error occurs, NULL is returned and \b errno is set accordingly:
     129 *  - \c EINVAL Unsupported format requested or invalid coordinates.
     130 *  - \c ENOMEM Not enough memory to allocate output buffer.
     131 *
     132 *  \param cv A libcaca canvas
     133 *  \param x The leftmost coordinate of the area to export.
     134 *  \param y The topmost coordinate of the area to export.
     135 *  \param w The width of the area to export.
     136 *  \param h The height of the area to export.
     137 *  \param format A string describing the requested output format.
     138 *  \param bytes A pointer to a size_t where the number of allocated bytes
     139 *         will be written.
     140 *  \return A pointer to the exported memory area, or NULL in case of error.
     141 */
     142void *caca_export_area_to_memory(caca_canvas_t const *cv, int x, int y, int w,
     143                                 int h, char const *format, size_t *bytes)
     144{
     145    caca_canvas_t *tmp;
     146    void *ret;
     147
     148    if(w < 0 || h < 0 || x < 0 || y < 0
     149        || x + w >= cv->width || y + h >= cv->height)
     150    {
     151        seterrno(EINVAL);
     152        return NULL;
     153    }
     154
     155    /* TODO: we need to spare the blit here by exporting the area we want. */
     156    tmp = caca_create_canvas(w, h);
     157    caca_blit(tmp, -x, -y, cv, NULL);
     158
     159    ret = caca_export_canvas_to_memory(tmp, format, bytes);
     160
     161    caca_free_canvas(tmp);
     162
     163    return ret;
    121164}
    122165
     
    938981
    939982void *cucul_export_memory(cucul_canvas_t const *, char const *,
    940                           size_t *) CACA_ALIAS(caca_export_memory);
     983                          size_t *) CACA_ALIAS(caca_export_canvas_to_memory);
     984void *caca_export_memory(caca_canvas_t const *, char const *,
     985                         size_t *) CACA_ALIAS(caca_export_canvas_to_memory);
    941986char const * const * cucul_get_export_list(void)
    942987         CACA_ALIAS(caca_get_export_list);
Note: See TracChangeset for help on using the changeset viewer.