The plain-file ext/src/mcde of the Makronix tree carried dtphoto (layers, PSD,
clipboard shape, JPEG/GIF/XPM writers), dtbar, dtsystemsettings (Startup Disk,
dock), dtwm and icon changes that this fork did not have. Resolved by hand:
dtphoto.c, McdeThumb.c, Thumb.h, dtsystemsettings, dtphoto.msg, AGENTS.md take
the Makronix side (a strict continuation of what the fork mirrored); the fork's
own changes are kept (M_PI guard and the front[] fix of 4e51d6dd, 'No
dttoolchest menu', DeskLowerBackdrops, distinfo until the next ext-dist).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
98 lines
4.3 KiB
C
98 lines
4.3 KiB
C
/*
|
|
* Mcde/Thumb.h -- MCDE: miniature pictures for dtfile and other programs
|
|
* (libDtSvc, DtUtil2/McdeThumb.c)
|
|
*
|
|
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
*
|
|
* The picture itself instead of the type icon: PNG, JPEG, GIF, BMP and XPM
|
|
* are read here and scaled down to the size the caller has room for. The
|
|
* decoders are libpng and libjpeg (both already part of the build) and C99
|
|
* for the rest -- no GTK, no gdk-pixbuf, no ImageMagick, no external program
|
|
* per picture (ext/src/mcde/AGENTS.md, "The philosophy").
|
|
*
|
|
* McdeThumbRead() is the part without X: a file in, 8-bit RGB out, so a test
|
|
* runs without a display. The result is kept in
|
|
* $HOME/.dt/thumbs/<size>/<sha1>.ppm; the second visit of a folder reads a
|
|
* PPM instead of the picture, and the same picture requested again costs no
|
|
* decoder. McdeThumbLoad() turns the RGB into a pixmap of the screen, and
|
|
* McdeThumbRequest() does the work in the application's idle time: one
|
|
* picture per Xt work proc, no thread, no timer, no polling
|
|
* (GOAL.md, "frugal").
|
|
*/
|
|
#ifndef _Mcde_Thumb_h
|
|
#define _Mcde_Thumb_h
|
|
|
|
#include <X11/Intrinsic.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* a decoded picture, 8 bits per channel, three channels, rows tight */
|
|
typedef struct {
|
|
int width;
|
|
int height;
|
|
unsigned char *rgb; /* width * height * 3 bytes */
|
|
} McdeThumbImage;
|
|
|
|
/* PATH into IMAGE, scaled down to fit MAXW x MAXH (0 = no limit in that
|
|
* direction), at its own size when it is smaller. The cache is consulted
|
|
* and filled. 0 on success, -1 when the file is not a picture this module
|
|
* reads, is damaged, or is larger than the limits (8192 x 8192, 64 MB). */
|
|
int McdeThumbRead(const char *path, int maxw, int maxh,
|
|
McdeThumbImage *image);
|
|
/* the RGB of an IMAGE, from McdeThumbRead() */
|
|
void McdeThumbFree(McdeThumbImage *image);
|
|
|
|
/* SRC (SW x SH, 8-bit RGB) scaled down to fit MAXW x MAXH into a new
|
|
* buffer; the aspect is kept and a picture that fits is copied. 0 on
|
|
* success, -1 on bad arguments or no memory. This is the part of the module
|
|
* without X, so the test reaches it without a display. */
|
|
int McdeThumbScale(const unsigned char *src, int sw, int sh, int maxw,
|
|
int maxh, unsigned char **dst, int *w, int *h);
|
|
|
|
/* IMAGE (8-bit RGB) written to PATH. The format comes from the name's
|
|
* ending: .png, .bmp, .jpg/.jpeg, .gif and .xpm are written, anything else
|
|
* is refused. PNG, BMP and XPM come back exactly; JPEG is lossy by its own
|
|
* nature. GIF carries at most 256 colours, so a picture with more than that
|
|
* goes through a 6x5x6 cube (largest deviation 25 of 255, measured
|
|
* 2026-11-22), while one that fits keeps its own colours exactly. A picture
|
|
* written here is read back by McdeThumbRead() pixel for pixel, which is
|
|
* what the test checks. 0 on success, -1 on a bad argument, an unknown
|
|
* ending or a write error. */
|
|
int McdeThumbWrite(const char *path, const unsigned char *rgb, int w,
|
|
int h);
|
|
|
|
/* IMAGE on SCREEN as a pixmap of the screen's depth; the size is the
|
|
* picture's, in pixels. 0 on success, -1 when the picture cannot be read or
|
|
* the visual is not one this module writes (PseudoColor is not). */
|
|
int McdeThumbPixmap(Screen *screen, const McdeThumbImage *image,
|
|
Pixmap *pixmap);
|
|
/* McdeThumbRead() and McdeThumbPixmap() in one, for a caller in the middle
|
|
* of drawing. 0 on success. */
|
|
int McdeThumbLoad(Screen *screen, const char *path, int maxw, int maxh,
|
|
Pixmap *pixmap, int *w, int *h);
|
|
/* gives back a pixmap of McdeThumbLoad() */
|
|
void McdeThumbFreePixmap(Screen *screen, Pixmap pixmap);
|
|
|
|
/* a picture read in the idle time of the application */
|
|
typedef void (*McdeThumbCallback)(void *client_data, Pixmap pixmap, int w,
|
|
int h);
|
|
|
|
/* Read PATH for W's screen and call CALLBACK with the pixmap when it is
|
|
* ready (or with XmUNSPECIFIED_PIXMAP when it is not a picture). The work
|
|
* is one Xt work proc per picture, so a folder of a hundred pictures does
|
|
* not stop the program. Returns a handle for McdeThumbCancel(). */
|
|
void *McdeThumbRequest(Widget w, const char *path, int maxw, int maxh,
|
|
McdeThumbCallback callback, void *client_data);
|
|
/* drop a request; a picture already read is freed, CALLBACK is not called */
|
|
void McdeThumbCancel(void *request);
|
|
/* drop every request (a folder was left) */
|
|
void McdeThumbCancelAll(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _Mcde_Thumb_h */
|