graphics.h revision 01037d57
1/* $XTermId: graphics.h,v 1.20 2014/11/28 19:48:36 tom Exp $ */
2
3/*
4 * Copyright 2013,2014 by Ross Combs
5 * Copyright 2013,2014 by Thomas E. Dickey
6 *
7 *                         All Rights Reserved
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the
11 * "Software"), to deal in the Software without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 * IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
24 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
28 * Except as contained in this notice, the name(s) of the above copyright
29 * holders shall not be used in advertising or otherwise to promote the
30 * sale, use or other dealings in this Software without prior written
31 * authorization.
32 */
33
34#ifndef included_graphics_h
35#define included_graphics_h
36/* *INDENT-OFF* */
37
38#include <ptyx.h>
39
40#if OPT_GRAPHICS
41
42#define CHANNEL_MAX 100
43
44typedef struct {
45    short r, g, b;
46} ColorRegister;
47
48typedef unsigned short RegisterNum;
49
50#define MAX_COLOR_REGISTERS 1024U
51#define COLOR_HOLE ((RegisterNum)MAX_COLOR_REGISTERS)
52
53#define MAX_GRAPHICS 16U
54
55typedef struct {
56    RegisterNum *pixels;
57    ColorRegister *private_color_registers;
58    ColorRegister *color_registers;
59    char color_registers_used[MAX_COLOR_REGISTERS];
60    XtermWidget xw;
61    int max_width;              /* largest image which can be stored */
62    int max_height;             /* largest image which can be stored */
63    unsigned valid_registers;   /* for wrap-around behavior */
64    int actual_width;           /* size of image before scaling */
65    int actual_height;          /* size of image before scaling */
66    int private_colors;         /* if not using the shared color registers */
67    int charrow;                /* upper left starting point in characters */
68    int charcol;                /* upper left starting point in characters */
69    int pixw;                   /* width of graphic pixels in screen pixels */
70    int pixh;                   /* height of graphic pixels in screen pixels */
71    int bufferid;               /* which screen buffer the graphic is associated with */
72    unsigned type;              /* type of graphic 0==sixel, 1...NUM_REGIS_PAGES==ReGIS page */
73    unsigned id;                /* sequential id used for preserving layering */
74    int valid;                  /* if the graphic has been initialized */
75    int dirty;                  /* if the graphic needs to be redrawn */
76} Graphic;
77
78extern Graphic *get_new_graphic(XtermWidget xw, int charrow, int charcol, unsigned type);
79extern Graphic *get_new_or_matching_graphic(XtermWidget xw, int charrow, int charcol, int actual_width, int actual_height, unsigned type);
80extern RegisterNum read_pixel(Graphic *graphic, int x, int y);
81extern void draw_solid_pixel(Graphic *graphic, int x, int y, unsigned color);
82extern void draw_solid_rectangle(Graphic *graphic, int x1, int y1, int x2, int y2, unsigned color);
83extern void draw_solid_line(Graphic *graphic, int x1, int y1, int x2, int y2, unsigned color);
84extern void copy_overlapping_area(Graphic *graphic, int src_x, int src_y, int dst_x, int dst_y, unsigned w, unsigned h, unsigned default_color);
85extern void hls2rgb(int h, int l, int s, short *r, short *g, short *b);
86extern void dump_graphic(Graphic const *graphic);
87extern unsigned get_color_register_count(TScreen const *screen);
88extern void update_color_register(Graphic *graphic, unsigned color, int r, int g, int b);
89extern RegisterNum find_color_register(ColorRegister const *color_registers, int r, int g, int b);
90extern void chararea_clear_displayed_graphics(TScreen const *screen, int leftcol, int toprow, int ncols, int nrows);
91extern void pixelarea_clear_displayed_graphics(TScreen const *screen, int winx, int winy, int w, int h);
92extern void refresh_displayed_graphics(XtermWidget xw, int leftcol, int toprow, int ncols, int nrows);
93extern void refresh_modified_displayed_graphics(XtermWidget xw);
94extern void reset_displayed_graphics(TScreen const *screen);
95extern void scroll_displayed_graphics(XtermWidget xw, int rows);
96
97#ifdef NO_LEAKS
98extern void noleaks_graphics(void);
99#endif
100
101#else
102
103#define get_new_graphic(xw, charrow, charcol, type) /* nothing */
104#define get_new_or_matching_graphic(xw, charrow, charcol, actual_width, actual_height, type) /* nothing */
105#define read_pixel(graphic, x, y) /* nothing */
106#define draw_solid_pixel(graphic, x, y, color) /* nothing */
107#define draw_solid_rectangle(graphic, x1, y1, x2, y2, color) /* nothing */
108#define draw_solid_line(graphic, x1, y1, x2, y2, color) /* nothing */
109#define copy_overlapping_area(graphic, src_x, src_y, dst_x, dst_y, w, h, default_color) /* nothing */
110#define hls2rgb(h, l, s, r, g, b) /* nothing */
111#define dump_graphic(graphic) /* nothing */
112#define get_color_register_count(screen) /* nothing */
113#define update_color_register(graphic, color, r, g, b) /* nothing */
114#define find_color_register(color_registers, r, g, b) /* nothing */
115#define chararea_clear_displayed_graphics(screen, leftcol, toprow, ncols, nrows) /* nothing */
116#define pixelarea_clear_displayed_graphics(screen, winx, winy, w, h) /* nothing */
117#define refresh_displayed_graphics(xw, leftcol, toprow, ncols, nrows) /* nothing */
118#define refresh_modified_displayed_graphics(xw) /* nothing */
119#define reset_displayed_graphics(screen) /* nothing */
120#define scroll_displayed_graphics(xw, rows) /* nothing */
121
122#endif
123
124/* *INDENT-ON* */
125
126#endif /* included_graphics_h */
127