source: libcaca/trunk/caca/driver/raw.c @ 4148

Last change on this file since 4148 was 3495, checked in by Sam Hocevar, 12 years ago

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().

  • Property svn:keywords set to Id
File size: 2.5 KB
RevLine 
[699]1/*
2 *  libcaca       Colour ASCII-Art library
[3495]3 *  Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
[699]4 *                All Rights Reserved
5 *
[769]6 *  $Id: raw.c 3495 2009-05-21 20:55:21Z sam $
7 *
[1462]8 *  This library is free software. It comes without any warranty, to
[1452]9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
[699]12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
[769]15/*
[699]16 *  This file contains the libcaca raw input and output driver
17 */
18
19#include "config.h"
20
21#if !defined(__KERNEL__)
22
[1054]23#include <stdio.h>
[1233]24#include <stdlib.h>
[1054]25
[699]26#include "caca.h"
27#include "caca_internals.h"
28
[811]29static int raw_init_graphics(caca_display_t *dp)
[699]30{
[2821]31    int width = caca_get_canvas_width(dp->cv);
32    int height = caca_get_canvas_height(dp->cv);
[1233]33    char const *geometry;
34
35#if defined(HAVE_GETENV)
36    geometry = getenv("CACA_GEOMETRY");
37    if(geometry && *geometry)
38        sscanf(geometry, "%ux%u", &width, &height);
39#endif
40
[2055]41    dp->resize.allow = 1;
[2821]42    caca_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24);
[2055]43    dp->resize.allow = 0;
[1233]44
[699]45    return 0;
46}
47
[811]48static int raw_end_graphics(caca_display_t *dp)
[699]49{
50    return 0;
51}
52
[819]53static int raw_set_display_title(caca_display_t *dp, char const *title)
[699]54{
[1006]55    return -1;
[699]56}
57
[2305]58static int raw_get_display_width(caca_display_t const *dp)
[699]59{
60    return 0;
61}
62
[2305]63static int raw_get_display_height(caca_display_t const *dp)
[699]64{
65    return 0;
66}
67
[811]68static void raw_display(caca_display_t *dp)
[699]69{
[1306]70    void *buffer;
[2305]71    size_t len;
[699]72
[3495]73    buffer = caca_export_canvas_to_memory(dp->cv, "caca", &len);
[1306]74    if(!buffer)
75        return;
76    fwrite(buffer, len, 1, stdout);
[1353]77    fflush(stdout);
[1306]78    free(buffer);
[699]79}
80
[811]81static void raw_handle_resize(caca_display_t *dp)
[699]82{
83    ;
84}
85
[2049]86static int raw_get_event(caca_display_t *dp, caca_privevent_t *ev)
[699]87{
88    ev->type = CACA_EVENT_NONE;
89    return 0;
90}
91
92/*
93 * Driver initialisation
94 */
95
[811]96int raw_install(caca_display_t *dp)
[699]97{
[2138]98    dp->drv.id = CACA_DRIVER_RAW;
99    dp->drv.driver = "raw";
[699]100
[811]101    dp->drv.init_graphics = raw_init_graphics;
102    dp->drv.end_graphics = raw_end_graphics;
[819]103    dp->drv.set_display_title = raw_set_display_title;
104    dp->drv.get_display_width = raw_get_display_width;
105    dp->drv.get_display_height = raw_get_display_height;
[811]106    dp->drv.display = raw_display;
107    dp->drv.handle_resize = raw_handle_resize;
108    dp->drv.get_event = raw_get_event;
109    dp->drv.set_mouse = NULL;
[1430]110    dp->drv.set_cursor = NULL;
[699]111
112    return 0;
113}
114
[1054]115#endif /* !__KERNEL__ */
Note: See TracBrowser for help on using the repository browser.