1/* $XTermId: graphics.h,v 1.32 2023/09/28 00:24:13 tom Exp $ */ 2 3/* 4 * Copyright 2013-2022,2023 by Ross Combs 5 * Copyright 2013-2022,2023 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 0x400 /* 1024U */ 51#define COLOR_HOLE 0x404 /* bytable above MAX_COLOR_REGISTERS */ 52 53#define MAX_GRAPHICS 16U 54 55#define ClrSpixel(graphic, cell) \ 56 do { \ 57 (graphic)->pixels[cell] = COLOR_HOLE; \ 58 } while (0) 59 60#define SetSpixel(graphic, cell, value) \ 61 do { \ 62 (graphic)->pixels[cell] = value; \ 63 } while (0) 64 65typedef struct { 66 RegisterNum *pixels; 67 ColorRegister *private_color_registers; 68 ColorRegister *color_registers; 69 Boolean color_registers_used[MAX_COLOR_REGISTERS]; 70 XtermWidget xw; 71 int max_width; /* largest image which can be stored */ 72 int max_height; /* largest image which can be stored */ 73 unsigned valid_registers; /* for wrap-around behavior */ 74 int actual_width; /* size of image before scaling */ 75 int actual_height; /* size of image before scaling */ 76 int private_colors; /* if not using the shared color registers */ 77 int charrow; /* upper left starting point in characters */ 78 int charcol; /* upper left starting point in characters */ 79 int pixw; /* width of graphic pixels in screen pixels */ 80 int pixh; /* height of graphic pixels in screen pixels */ 81 int bufferid; /* which screen buffer the graphic is associated with */ 82 unsigned type; /* type of graphic 0==sixel, 1...NUM_REGIS_PAGES==ReGIS page */ 83 unsigned id; /* sequential id used for preserving layering */ 84 Boolean valid; /* if the graphic has been initialized */ 85 Boolean dirty; /* if the graphic needs to be redrawn */ 86 Boolean hidden; /* if the graphic should not be displayed */ 87} Graphic; 88 89extern Graphic *get_new_graphic(XtermWidget /* xw */, int /* charrow */, int /* charcol */, unsigned /* type */); 90extern Graphic *get_new_or_matching_graphic(XtermWidget /* xw */, int /* charrow */, int /* charcol */, int /* actual_width */, int /* actual_height */, unsigned /* type */); 91extern RegisterNum read_pixel(Graphic */* graphic */, int /* x */, int /* y */); 92extern void draw_solid_pixel(Graphic */* graphic */, int /* x */, int /* y */, unsigned /* color */); 93extern void draw_solid_rectangle(Graphic */* graphic */, int /* x1 */, int /* y1 */, int /* x2 */, int /* y2 */, unsigned /* color */); 94extern 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 */); 95extern void hls2rgb(int /* h */, int /* l */, int /* s */, short */* r */, short */* g */, short */* b */); 96extern void rgb2hls(int /* r */, int /* g */, int /* b */, short */* h */, short */* l */, short */* s */); 97extern void dump_graphic(Graphic const */* graphic */); 98extern unsigned get_color_register_count(TScreen const */* screen */); 99extern void fetch_color_register(Graphic */* graphic */, unsigned /* color */, ColorRegister* /* reg */); 100extern void update_color_register(Graphic */* graphic */, unsigned /* color */, int /* r */, int /* g */, int /* b */); 101extern RegisterNum find_color_register(ColorRegister const */* color_registers */, int /* r */, int /* g */, int /* b */); 102extern void chararea_clear_displayed_graphics(TScreen const */* screen */, int /* leftcol */, int /* toprow */, int /* ncols */, int /* nrows */); 103extern void pixelarea_clear_displayed_graphics(TScreen const */* screen */, int /* winx */, int /* winy */, int /* w */, int /* h */); 104extern void refresh_displayed_graphics(XtermWidget /* xw */, int /* leftcol */, int /* toprow */, int /* ncols */, int /* nrows */); 105extern void refresh_modified_displayed_graphics(XtermWidget /* xw */); 106extern void reset_displayed_graphics(TScreen const */* screen */); 107extern void scroll_displayed_graphics(XtermWidget /* xw */, int /* rows */); 108 109#ifdef NO_LEAKS 110extern void noleaks_graphics(Display */* dpy */); 111#endif 112 113#else 114 115#define get_new_graphic(xw, charrow, charcol, type) /* nothing */ 116#define get_new_or_matching_graphic(xw, charrow, charcol, actual_width, actual_height, type) /* nothing */ 117#define read_pixel(graphic, x, y) /* nothing */ 118#define draw_solid_pixel(graphic, x, y, color) /* nothing */ 119#define draw_solid_rectangle(graphic, x1, y1, x2, y2, color) /* nothing */ 120#define copy_overlapping_area(graphic, src_x, src_y, dst_x, dst_y, w, h, default_color) /* nothing */ 121#define hls2rgb(h, l, s, r, g, b) /* nothing */ 122#define rgb2hls(r, g, b, h, l, s) /* nothing */ 123#define dump_graphic(graphic) /* nothing */ 124#define get_color_register_count(screen) /* nothing */ 125#define update_color_register(graphic, color, r, g, b) /* nothing */ 126#define find_color_register(color_registers, r, g, b) /* nothing */ 127#define chararea_clear_displayed_graphics(screen, leftcol, toprow, ncols, nrows) /* nothing */ 128#define pixelarea_clear_displayed_graphics(screen, winx, winy, w, h) /* nothing */ 129#define refresh_displayed_graphics(xw, leftcol, toprow, ncols, nrows) /* nothing */ 130#define refresh_modified_displayed_graphics(xw) /* nothing */ 131#define reset_displayed_graphics(screen) /* nothing */ 132#define scroll_displayed_graphics(xw, rows) /* nothing */ 133 134#endif 135 136/* *INDENT-ON* */ 137 138#endif /* included_graphics_h */ 139