Beispiel #1
0
static int preinit(struct vo *vo, const char *arg)
{
    if (arg) {
        mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: Unknown subdevice: %s\n", arg);
        return ENOSYS;
    }

    canvas = caca_create_canvas(0, 0);
    if (canvas == NULL) {
        mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: failed to create canvas\n");
        return ENOSYS;
    }

    display = caca_create_display(canvas);

    if (display == NULL) {
        mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: failed to create display\n");
        caca_free_canvas(canvas);
        return ENOSYS;
    }

    caca_set_display_title(display, "MPlayer");

    return 0;
}
Beispiel #2
0
static VALUE set_title(VALUE self, VALUE t)
{
    if(caca_set_display_title(_SELF, StringValuePtr(t))<0)
    {
        rb_raise(rb_eRuntimeError, "%s", strerror(errno));
    }
    return t;
}
Beispiel #3
0
int main(void)
{
    //                   R G B A
    uint32_t pattern = 0xFFFF00FF;

#ifdef __APPLE__
    memset_pattern4(gfx, &pattern, sizeof(gfx));
#else
    wmemset(gfx, pattern, (64*32) * sizeof(char));
#endif

    gfx[0] =    0xFF0000FF; // R
    gfx[1] =    0x00FF00FF; // G
    gfx[2] =    0x0000FFFF; // B
    gfx[63] =   0xFF0000FF; // R
    gfx[64*31] =0x00FF00FF; // G
    int x = 64, y = 32;
    gfx[(y-1)*64+(x-1)] = 0x0000FFFF; // B

    caca_canvas_t *cv; caca_display_t *dp; caca_event_t ev;
    dp = caca_create_display(NULL);
    if(!dp)
        return 1;
    /*
    printf("Current driver: %s\n", caca_get_display_driver(dp));
    char **drivers = caca_get_display_driver_list();
    caca_free_display(dp);
    while(*drivers != NULL) {
        printf("%s\n", *drivers);
        drivers++;
    }
    exit(0);*/
    cv = caca_get_canvas(dp);
    caca_dither_t *dither = caca_create_dither(32, 64, 32, 4*64,
        0xFF000000,
        0x00FF0000,
        0x0000FF00,
        0x000000FF);
    int cw = caca_get_canvas_width(cv);
    int ch = caca_get_canvas_height(cv);
    caca_set_display_title(dp, "Hello!");
    //caca_set_color_ansi(cv, CACA_BLUE, CACA_WHITE);
    //caca_put_str(cv, 0, 0, "This is a message");
    caca_dither_bitmap(cv, 0,0,cw,ch, dither, gfx);
    caca_refresh_display(dp);

    caca_free_dither(dither);
    //caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
    caca_free_display(dp);
    return 0;
}
Beispiel #4
0
void gui_console_init(int argc, char *argv[], int w, int h, int bpp)
{
        c_ui.dp = caca_create_display(NULL);
        c_ui.cv = caca_get_canvas(c_ui.dp);
        c_ui.ww = caca_get_canvas_width(c_ui.cv);
        c_ui.wh = caca_get_canvas_height(c_ui.cv);

	    caca_set_display_title(c_ui.dp, PACKAGE_NAME);
        c_ui.im = caca_create_dither(
                    bpp,
                    w, h,
                    3 * w /*stride*/,
                    0xff0000, 0x00ff00, 0x0000ff, 0);
}
Beispiel #5
0
static int preinit(struct vo *vo)
{
    canvas = caca_create_canvas(0, 0);
    if (canvas == NULL) {
        mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: failed to create canvas\n");
        return ENOSYS;
    }

    display = caca_create_display(canvas);

    if (display == NULL) {
        mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: failed to create display\n");
        caca_free_canvas(canvas);
        return ENOSYS;
    }

    caca_set_display_title(display, "mpv");

    return 0;
}
Beispiel #6
0
/**
 * This function initializes libcaca vout method.
 */
static int Open(vlc_object_t *object)
{
    vout_display_t *vd = (vout_display_t *)object;
    vout_display_sys_t *sys;

    if (vout_display_IsWindowed(vd))
        return VLC_EGENERIC;
#if !defined(__APPLE__) && !defined(_WIN32)
# ifndef X_DISPLAY_MISSING
    if (!vlc_xlib_init(object))
        return VLC_EGENERIC;
# endif
#endif

#if defined(_WIN32)
    CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
    SMALL_RECT rect;
    COORD coord;
    HANDLE hstdout;

    if (!AllocConsole()) {
        msg_Err(vd, "cannot create console");
        return VLC_EGENERIC;
    }

    hstdout =
        CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
                                  FILE_SHARE_READ | FILE_SHARE_WRITE,
                                  NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
    if (!hstdout || hstdout == INVALID_HANDLE_VALUE) {
        msg_Err(vd, "cannot create screen buffer");
        FreeConsole();
        return VLC_EGENERIC;
    }

    if (!SetConsoleActiveScreenBuffer(hstdout)) {
        msg_Err(vd, "cannot set active screen buffer");
        FreeConsole();
        return VLC_EGENERIC;
    }

    coord = GetLargestConsoleWindowSize(hstdout);
    msg_Dbg(vd, "SetConsoleWindowInfo: %ix%i", coord.X, coord.Y);

    /* Force size for now */
    coord.X = 100;
    coord.Y = 40;

    if (!SetConsoleScreenBufferSize(hstdout, coord))
        msg_Warn(vd, "SetConsoleScreenBufferSize %i %i",
                  coord.X, coord.Y);

    /* Get the current screen buffer size and window position. */
    if (GetConsoleScreenBufferInfo(hstdout, &csbiInfo)) {
        rect.Top = 0; rect.Left = 0;
        rect.Right = csbiInfo.dwMaximumWindowSize.X - 1;
        rect.Bottom = csbiInfo.dwMaximumWindowSize.Y - 1;
        if (!SetConsoleWindowInfo(hstdout, TRUE, &rect))
            msg_Dbg(vd, "SetConsoleWindowInfo failed: %ix%i",
                     rect.Right, rect.Bottom);
    }
#endif

    /* Allocate structure */
    vd->sys = sys = calloc(1, sizeof(*sys));
    if (!sys)
        goto error;

    sys->cv = cucul_create_canvas(0, 0);
    if (!sys->cv) {
        msg_Err(vd, "cannot initialize libcucul");
        goto error;
    }

    const char *driver = NULL;
#ifdef __APPLE__
    // Make sure we don't try to open a window.
    driver = "ncurses";
#endif

    sys->dp = caca_create_display_with_driver(sys->cv, driver);
    if (!sys->dp) {
        msg_Err(vd, "cannot initialize libcaca");
        goto error;
    }

    if (vd->cfg->display.title)
        caca_set_display_title(sys->dp,
                               vd->cfg->display.title);
    else
        caca_set_display_title(sys->dp,
                               VOUT_TITLE "(Colour AsCii Art)");

    /* Fix format */
    video_format_t fmt = vd->fmt;
    if (fmt.i_chroma != VLC_CODEC_RGB32) {
        fmt.i_chroma = VLC_CODEC_RGB32;
        fmt.i_rmask = 0x00ff0000;
        fmt.i_gmask = 0x0000ff00;
        fmt.i_bmask = 0x000000ff;
    }

    /* TODO */
    vout_display_info_t info = vd->info;

    /* Setup vout_display now that everything is fine */
    vd->fmt = fmt;
    vd->info = info;

    vd->pool    = Pool;
    vd->prepare = Prepare;
    vd->display = PictureDisplay;
    vd->control = Control;
    vd->manage  = Manage;

    /* Fix initial state */
    vout_display_SendEventFullscreen(vd, false);
    Refresh(vd);

    return VLC_SUCCESS;

error:
    if (sys) {
        if (sys->pool)
            picture_pool_Release(sys->pool);
        if (sys->dither)
            cucul_free_dither(sys->dither);
        if (sys->dp)
            caca_free_display(sys->dp);
        if (sys->cv)
            cucul_free_canvas(sys->cv);

        free(sys);
    }
#if defined(_WIN32)
    FreeConsole();
#endif
    return VLC_EGENERIC;
}
Beispiel #7
0
CacaWrapperGui::CacaWrapperGui() {
    _dp = caca_create_display(NULL);
    _cv = caca_get_canvas(_dp);
    caca_set_display_title(_dp, "THE GAME!");
    initEventType();
}
Beispiel #8
0
int main(int argc, char **argv)
{
    int refresh = 1, file = 1;
    unsigned int iw = 0, ih = 0;

    if(argc < 2)
    {
        fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
        return 1;
    }

    cv = caca_create_canvas(0, 0);
    if(!cv)
        return 1;
    dp = caca_create_display(cv);
    if(!dp)
        return 1;

    for(;;)
    {
        caca_event_t ev;
        unsigned int w, h;
        int dx = 0, dy = 0;

        if(!image)
        {
            image = caca_create_canvas(0, 0);
            if(caca_import_canvas_from_file(image, argv[file], "ansi") < 0)
            {
                fprintf(stderr, "%s: invalid file `%s'.\n", argv[0], argv[1]);
                return 1;
            }

            ih = caca_get_canvas_height(image);
            iw = caca_get_canvas_width(image);
            x = y = 0;

            caca_set_display_title(dp, argv[file]);

            refresh = 1;
        }

        if(refresh)
        {
            refresh_screen();
            refresh = 0;
        }

        while(caca_get_event(dp, CACA_EVENT_ANY, &ev, -1))
        {
            switch(caca_get_event_type(&ev))
            {
                case CACA_EVENT_QUIT:
                    goto quit;
                case CACA_EVENT_KEY_PRESS:
                    switch(caca_get_event_key_ch(&ev))
                    {
                    case CACA_KEY_LEFT: dx -= 2; break;
                    case CACA_KEY_RIGHT: dx += 2; break;
                    case CACA_KEY_UP: dy--; break;
                    case CACA_KEY_DOWN: dy++; break;
                    case CACA_KEY_PAGEUP: dy -= 12; break;
                    case CACA_KEY_PAGEDOWN: dy += 12; break;
                    case CACA_KEY_ESCAPE:
                    case 'q':
                        goto quit;
                    case 'n':
                        file = file + 1 < argc ? file + 1 : 1;
                        caca_free_canvas(image);
                        image = NULL;
                        goto stopevents;
                    case 'p':
                        file = file > 1 ? file - 1 : argc - 1;
                        caca_free_canvas(image);
                        image = NULL;
                        goto stopevents;
                    default:
                        break;
                    }
                case CACA_EVENT_RESIZE:
                    refresh = 1;
                    goto stopevents;
                default:
                    break;
            }
        }
stopevents:

        w = caca_get_canvas_width(cv);
        h = caca_get_canvas_height(cv);

        if(dx | dy)
        {
            refresh = 1;
            x += dx;
            y += dy;

            if(x < 0) x = 0; else if(x + w > iw) x = iw > w ? iw - w : 0;
            if(y < 0) y = 0; else if(y + h > ih) y = ih > h ? ih - h : 0;
        }
    }
quit:

    /* Clean up */
    caca_free_display(dp);
    caca_free_canvas(image);
    caca_free_canvas(cv);

    return 0;
}
Beispiel #9
0
int main(void)
{
  caca_canvas_t *cv;
  caca_display_t *dp;
  caca_event_t ev;

  // Create canvas and display
  cv = caca_create_canvas(100,80);
  if(!cv) return 1;

  dp = caca_create_display_with_driver(cv, "ncurses");
  if(!dp) return 1;

  caca_set_display_title(dp, "WPC 66");
  caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK);

  // Tree stump
  caca_fill_box (cv, 47, 50, 6, 4, '|');

  // Tree body
  caca_draw_thin_triangle (cv,50,10,10,50,90,50);

  // Pot
  caca_fill_triangle(cv, 35, 53, 40, 60, 40, 53, '@');
  caca_fill_box(cv, 40, 53, 19, 8, '@');
  caca_fill_triangle(cv, 59, 60, 64, 53, 59, 53, '@');

  // Balls
  int balls[] = {50, 25, 35, 35, 25, 43, 58, 32, 68, 41, 50, 46};
  for (int i = 0; i <= 10; i += 2)
      caca_draw_thin_ellipse(cv, balls[i], balls[i+1], 2, 2);

  // Sparkly stuff
  int sparks[] = {54, 20, 42, 30, 40, 45, 46, 38, 60, 43, 75, 48};
  for (int i = 0; i <= 10; i += 2)
  {
    caca_put_char(cv, sparks[i], sparks[i+1], '*');
    caca_put_char(cv, sparks[i]-1, sparks[i+1], '<');
    caca_put_char(cv, sparks[i]+1, sparks[i+1], '>');
    caca_put_char(cv, sparks[i], sparks[i+1]-1, '^');
    caca_put_char(cv, sparks[i], sparks[i+1]+1, 'v');
  }

  // Guirlandes
  caca_draw_thin_line(cv, 32, 44, 70, 35);
  caca_draw_thin_line(cv, 17, 49, 30, 46);
  caca_draw_thin_line(cv, 60, 47, 80, 43);
  caca_draw_thin_line(cv, 43, 35, 52, 33);
  caca_draw_thin_line(cv, 55, 28, 60, 27);
  caca_draw_thin_line(cv, 40, 25, 45, 24);

  // Star outline
  caca_fill_triangle(cv, 50, 16, 40, 10, 60, 10, ' ');
  int star_x[] = {50, 45, 40, 45, 40, 45, 50, 55, 60, 55, 60, 55, 50};
  int star_y[] = { 4,  7,  7, 10, 13, 13, 16, 13, 13, 10,  7,  7,  4};
  caca_draw_thin_polyline(cv, star_x, star_y, 12);

  // Inside of star
  int star[] = {50,8,50,9,50,10,50,11,50,12,49,9,48,9,51,9,52,9,49,10,51,10,49,11,48,11,51,11,52,11};
  for (int i = 0; i <= 29; i += 2)
      caca_put_char(cv, star[i], star[i+1], '*');

  // Display and wait for key press
  caca_refresh_display(dp);
  caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
  caca_free_display(dp);
  return 0;
}
Beispiel #10
0
/*****************************************************************************
 * Create: allocates libcaca video output thread
 *****************************************************************************
 * This function initializes libcaca vout method.
 *****************************************************************************/
static int Create( vlc_object_t *p_this )
{
    vout_thread_t *p_vout = (vout_thread_t *)p_this;

#if defined( WIN32 ) && !defined( UNDER_CE )
    CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
    SMALL_RECT rect;
    COORD coord;
    HANDLE hstdout;

    if( !AllocConsole() )
    {
        msg_Err( p_vout, "cannot create console" );
        return VLC_EGENERIC;
    }

    hstdout =
        CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE,
                                   FILE_SHARE_READ | FILE_SHARE_WRITE,
                                   NULL, CONSOLE_TEXTMODE_BUFFER, NULL );
    if( !hstdout || hstdout == INVALID_HANDLE_VALUE )
    {
        msg_Err( p_vout, "cannot create screen buffer" );
        FreeConsole();
        return VLC_EGENERIC;
    }

    if( !SetConsoleActiveScreenBuffer( hstdout) )
    {
        msg_Err( p_vout, "cannot set active screen buffer" );
        FreeConsole();
        return VLC_EGENERIC;
    }

    coord = GetLargestConsoleWindowSize( hstdout );
    msg_Dbg( p_vout, "SetConsoleWindowInfo: %ix%i", coord.X, coord.Y );

    /* Force size for now */
    coord.X = 100;
    coord.Y = 40;

    if( !SetConsoleScreenBufferSize( hstdout, coord ) )
        msg_Warn( p_vout, "SetConsoleScreenBufferSize %i %i",
                  coord.X, coord.Y );

    /* Get the current screen buffer size and window position. */
    if( GetConsoleScreenBufferInfo( hstdout, &csbiInfo ) )
    {
        rect.Top = 0; rect.Left = 0;
        rect.Right = csbiInfo.dwMaximumWindowSize.X - 1;
        rect.Bottom = csbiInfo.dwMaximumWindowSize.Y - 1;
        if( !SetConsoleWindowInfo( hstdout, TRUE, &rect ) )
            msg_Dbg( p_vout, "SetConsoleWindowInfo failed: %ix%i",
                     rect.Right, rect.Bottom );
    }
#endif

    /* Allocate structure */
    p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
    if( p_vout->p_sys == NULL )
    {
        msg_Err( p_vout, "out of memory" );
        return VLC_ENOMEM;
    }

    p_vout->p_sys->p_cv = cucul_create_canvas(0, 0);
    if( !p_vout->p_sys->p_cv )
    {
        msg_Err( p_vout, "cannot initialize libcucul" );
        free( p_vout->p_sys );
        return VLC_EGENERIC;
    }

    p_vout->p_sys->p_dp = caca_create_display( p_vout->p_sys->p_cv );
    if( !p_vout->p_sys->p_dp )
    {
        msg_Err( p_vout, "cannot initialize libcaca" );
        cucul_free_canvas( p_vout->p_sys->p_cv );
        free( p_vout->p_sys );
        return VLC_EGENERIC;
    }

    caca_set_display_title( p_vout->p_sys->p_dp,
                            VOUT_TITLE " - Colour AsCii Art (caca)" );

    p_vout->pf_init = Init;
    p_vout->pf_end = End;
    p_vout->pf_manage = Manage;
    p_vout->pf_render = Render;
    p_vout->pf_display = Display;

    return VLC_SUCCESS;
}
Beispiel #11
0
int main(int argc, char *argv[])
{

    /* libcaca/libcaca contexts */
    caca_canvas_t *cv;
    caca_display_t *dp;
    caca_canvas_t *tex;

    /* cached canvas size */
    int ww, wh, tw, th;

    /* logic */
    int quit = 0;
    int update = 1;
    int px, py;
    float angle = 0;


    float square[6][2] = {
        {-SQUARE_SIZE, -SQUARE_SIZE},
        {SQUARE_SIZE, -SQUARE_SIZE},
        {SQUARE_SIZE, SQUARE_SIZE},
        {-SQUARE_SIZE, SQUARE_SIZE},
    };
    float uv1[6] = {
        0, 0,
        1, 0,
        1, 1
    };
    float uv2[6] = {
        0, 0,
        1, 1,
        0, 1
    };


    float rotated[4][2];
    int coords1[6], coords2[6];

    /* Create displayed canvas */
    cv = caca_create_canvas(0, 0);
    if (!cv)
    {
        fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]);
        return 1;
    }

    /* Create texture holding canvas */
    tex = caca_create_canvas(16, 16);
    if (!tex)
    {
        fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]);
        return 1;
    }

    /* Open window */
    dp = caca_create_display(cv);
    if (!dp)
    {
        fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]);
        return 1;
    }



    /* Set the window title */
    caca_set_display_title(dp, "trifiller");

    /* Frame duration */
    caca_set_display_time(dp, 10000);

    /* Get displayed canvas size */
    ww = caca_get_canvas_width(cv);
    wh = caca_get_canvas_height(cv);

    /* Texture size */
    tw = caca_get_canvas_width(tex);
    th = caca_get_canvas_height(tex);

    /* Load texture if any */
    if (argc == 2)
    {
        struct image *im = load_image(argv[1]);
        if (!im)
        {
            fprintf(stderr, "%s: unable to load image '%s'\n", argv[0],
                    argv[1]);
            return 1;
        }

        caca_set_dither_algorithm(im->dither,
                                  caca_get_dither_algorithm_list(NULL)[4]);
        caca_dither_bitmap(tex, 0, 0, tw, th, im->dither, im->pixels);
        unload_image(im);
    }
    /* or generate one */
    else
    {

        int i;
        for (i = 0; i < 16; i++)
        {
            caca_set_color_ansi(tex, (i + 1) % 0xF, i % 0xF);
            caca_put_str(tex, 0, i, "0123456789ABCDEF");
        }
    }


    px = 0;
    py = 0;

    while (!quit)
    {
        caca_event_t ev;
        unsigned int const event_mask = CACA_EVENT_KEY_PRESS
            | CACA_EVENT_RESIZE | CACA_EVENT_QUIT;
        int event;

        if (update)
            event = caca_get_event(dp, event_mask, &ev, 0);
        else
            event = caca_get_event(dp, event_mask, &ev, -1);

        while (event)
        {
            if (caca_get_event_type(&ev) & CACA_EVENT_KEY_PRESS)
                switch (caca_get_event_key_ch(&ev))
                {
                case 'q':
                case 'Q':
                case CACA_KEY_ESCAPE:
                    quit = 1;
                    break;
                case CACA_KEY_UP:
                    py--;
                    break;
                case CACA_KEY_DOWN:
                    py++;
                    break;
                case CACA_KEY_LEFT:
                    px--;
                    break;
                case CACA_KEY_RIGHT:
                    px++;
                    break;
                case 'a':
                    angle += 1.0f;
                    break;
                case 's':
                    angle -= 1.0f;
                    break;
                }
            else if (caca_get_event_type(&ev) == CACA_EVENT_RESIZE)
            {
                caca_refresh_display(dp);
                ww = caca_get_event_resize_width(&ev);
                wh = caca_get_event_resize_height(&ev);
                update = 1;
            }
            else if (caca_get_event_type(&ev) & CACA_EVENT_QUIT)
                quit = 1;

            event = caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0);
        }



        /* 2D Rotation around screen center */
        int p;
        for (p = 0; p < 4; p++)
        {
            rotated[p][0] =
                square[p][0] * cos(angle * M_PI / 180.0f) -
                square[p][1] * sin(angle * M_PI / 180.0f);
            rotated[p][1] =
                square[p][0] * sin(angle * M_PI / 180.0f) +
                square[p][1] * cos(angle * M_PI / 180.0f);

            rotated[p][0] += ww / 2 + px;
            rotated[p][1] += wh / 2 + py;
        }

        angle += 1.0f;


        /* Reaarange coordinates to fit libcaca's format */
        coords1[0] = rotated[0][0];
        coords1[1] = rotated[0][1];
        coords1[2] = rotated[1][0];
        coords1[3] = rotated[1][1];
        coords1[4] = rotated[2][0];
        coords1[5] = rotated[2][1];

        coords2[0] = rotated[0][0];
        coords2[1] = rotated[0][1];
        coords2[2] = rotated[2][0];
        coords2[3] = rotated[2][1];
        coords2[4] = rotated[3][0];
        coords2[5] = rotated[3][1];

        /* Display two triangles */
        caca_fill_triangle_textured(cv, /* canvas */
                                    coords1,    /* triangle coordinates */
                                    tex,        /* texture canvas */
                                    uv1);       /* texture coordinates */
        caca_fill_triangle_textured(cv, coords2, tex, uv2);

        /* Refresh display and clear for next frame */
        caca_refresh_display(dp);
        caca_clear_canvas(cv);

    }

    caca_free_display(dp);
    caca_free_canvas(cv);
    caca_free_canvas(tex);

    return 0;
}