joeylib2/include/joey/surface.h

46 lines
1.5 KiB
C

// Surface type and allocation.
//
// All surfaces are 320x200 pixels, 4 bits per pixel packed (two pixels
// per byte, high nibble is the left pixel). Each surface carries its
// own 200-entry SCB (scanline control byte) table and a 16-by-16 $0RGB
// palette set. See docs/DESIGN.md section 6.
#ifndef JOEYLIB_SURFACE_H
#define JOEYLIB_SURFACE_H
#include "platform.h"
#include "types.h"
// ----- Fixed surface dimensions (library contract) -----
#define SURFACE_WIDTH 320
#define SURFACE_HEIGHT 200
#define SURFACE_BYTES_PER_ROW 160
#define SURFACE_PIXELS_SIZE (SURFACE_BYTES_PER_ROW * SURFACE_HEIGHT)
#define SURFACE_PALETTE_COUNT 16
#define SURFACE_COLORS_PER_PALETTE 16
#define SURFACE_PALETTE_ENTRIES (SURFACE_PALETTE_COUNT * SURFACE_COLORS_PER_PALETTE)
// ----- Opaque public type -----
typedef struct SurfaceT SurfaceT;
// Allocate a new offscreen surface. Returns NULL on failure (joeyLastError
// describes the reason).
SurfaceT *surfaceCreate(void);
// Release an offscreen surface previously returned by surfaceCreate.
// Passing NULL is a no-op. Passing the screen surface is a no-op.
void surfaceDestroy(SurfaceT *s);
// The library's pre-allocated screen surface. This is the surface the
// library presents to the display. Always valid between joeyInit and
// joeyShutdown.
SurfaceT *surfaceGetScreen(void);
// Copy pixels, SCBs, and palettes from src into dst. Both must be valid
// surfaces.
void surfaceCopy(SurfaceT *dst, const SurfaceT *src);
#endif