Hotdog

From wikiPodLinux

Hotdog is a superfast compositing graphics engine written by slowcoder. You can view a demo video here (http://yorgle.cis.rit.edu/mirror/hotdog1.mp4) (MP4 format).

Table of contents

Downloads

Hotdog is available in the Subversion repository.

Compiling

You need to compile the iPod version and the X11 version separately. So if you want to compile both (as may be necessary for use with TTK), from the appropriate directory, execute both of these:

make
make IPOD=1

API

Right now, there is a dearth of formal documentation for Hotdog. Your best bet is to figure it out on your own from the source comments. Here are some prototypes as a primer; we could eventually convert this wiki page to LaTeX with WikiPDF (http://sourceforge.net/projects/wikipdf/).

Objects

typedef struct hd_object {
    int32 x, y, w, h, z;
    int32 natw, nath; /* natural width and height */
    uint8 opacity;
    uint32 type;
    int animating;
    /* private */ int dirty;
    
    hd_surface   canvas;
    hd_primitive *primitive;
    void       *data;
    
    struct hd_engine *eng;
    
    void (*render)(struct hd_engine *eng, struct hd_object *obj, int x, int y, int w, int h);
    void (*destroy)(struct hd_object *obj);
    
    void (*animate)(struct hd_object *obj);
    void *animdata;

#define HD_SPEED_NOALPHA   1   /* every pixel is opaque, alpha ignored - major speedup */
#define HD_SPEED_BINALPHA  2   /* any nonzero alpha is like 0xFF - medium speedup */
#define HD_SPEED_NOSCALE   4   /* it's always a 1:1 scale - minor speedup */
#define HD_SPEED_CSPRITE   8   /* compile the sprite - ignored currently, would be major speedup if it was impl */
    int speed;

    /* private */ hd_rect last;
} hd_object;

Fonts

typedef struct hd_font {
    // Pixel data:
    int     bitstype; // PITCHED or CLUMPED
    int32   pitch, h; // h = height of font; pitch = length of a scanline in bytes
    int32   pixbytes; // number of bytes in `pixels'
    void   *pixels;
    int     bpp; // 1 or 8 or 32

    // Char info:
    int     firstchar, nchars;
    uint32 *offset; // offset[N-firstchar] = X-coord of char N in pixels
    uint8  *width;  // width[N-firstchar]  = width   "    "  "  "    "
    int     defaultchar; // Char to use if req'd char doesn't exist
} hd_font;

hd_font *HD_Font_LoadHDF (const char *filename);
int      HD_Font_SaveHDF (hd_font *font, const char *filename);
hd_font *HD_Font_LoadFNT (const char *filename);
hd_font *HD_Font_LoadPCF (const char *filename);
hd_font *HD_Font_LoadFFF (const char *filename);
hd_font *HD_Font_LoadSFont (const char *filename);

int HD_Font_TextWidth (hd_font *font, const char *str);
/* TextHeight is just font->h */

/** Draws with the TOP LEFT CORNER at (x,y) */
void HD_Font_Draw (hd_surface srf, hd_font *font, int x, int y, uint32 color, const char *str);
/* Fast = no blending. May have unpredictable results for AA fonts on non-white surfaces. */
void HD_Font_DrawFast (hd_surface srf, hd_font *font, int x, int y, uint32 color, const char *str);

struct hd_object *HD_Font_MakeObject (hd_font *font, const char *str);

Surfaces

/* Surfaces are just things for drawing graphics.
 * However, the actual pixels don't start until (h+2)*4
 * bytes in. The first uint32 is the width, and the second
 * is the height. After that come <h> uint32's, each giving the
 * offset (in 4-byte blocks from the beginning of the surface)
 * of the beginning of the respective row. All pixels are stored
 * in ARGB8888 format. For instance, a 4x4 surface would look like
 * this.
 *
 * [ofs] value
 *   [0] 4
 *   [1] 4
 *   [2] 6   (beginning of row 0)
 *   [3] 10  (beginning of row 1)
 *   [4] 14  (beginning of row 2)
 *   [5] 18  (beginning of row 3)
 *   [6] pixel at (0, 0)
 *   [7] pixel at (0, 1)
 *   [8] pixel at (0, 2)
 *   [9] pixel at (0, 3)
 *  [10] pixel at (1, 0)
 *   ..
 *  [13] pixel at (1, 3)
 *  [14] pixel at (2, 0)
 *   ..
 *  [18] pixel at (3, 0)
 *   ..
 *  [21] pixel at (3, 3)
 */
typedef uint32 *hd_surface;

/* HD_SurfaceFrom* will _copy_ the pixels, not just reference them.
 * Thus, you still need to free argb or pixels.
 */
hd_surface HD_SurfaceFromARGB (uint32 *argb, int32 width, int32 height);

/* If [pixels] contains an alpha channel and is not premultiplied,
 * it's YOUR RESPONSIBILITY to call PremultiplyAlpha on the returned
 * surface.
 */
hd_surface HD_SurfaceFromPixels (void *pixels, int32 width, int32 height, int bpp,
                                 uint32 Rmask, uint32 Gmask, uint32 Bmask, uint32 Amask);

/* NewSurface fills the surface with black. */
hd_surface HD_NewSurface (int32 width, int32 height);

void HD_FreeSurface (hd_surface srf); // you can just use free if you want

/* Premultiplies the alpha in [srf]. You must be careful to only call this once. */
void HD_PremultiplyAlpha (hd_surface srf);

/* macros for hd_surface handling */
/* "F" variants are (F)ast and need to be pre-clipped. */
#define HD_SRF_WIDTH(srf) ((srf)[0])
#define HD_SRF_HEIGHT(srf) ((srf)[1])
#define HD_SRF_ROW(srf,y) (((y)<((srf)[1]))?((srf) + ((srf)[2 + (y)])):0)
#define HD_SRF_ROWF(srf,y) ((srf) + ((srf)[2 + (y)]))
#define HD_SRF_PIXF(srf,x,y) ((srf)[((srf)[2 + (y)]) + (x)])
#define HD_SRF_SETPIX(srf,x,y,pix) (((x)<((srf)[0]))&&((y)<((srf)[1]))? (HD_SRF_PIXF(srf,x,y) = (pix)) : (pix))
#define HD_SRF_GETPIX(srf,x,y) (((x)<((srf)[0]))&&((y)<((srf)[1]))? HD_SRF_PIXF(srf,x,y) : 0)
#define HD_SRF_PIXPTR(srf,x,y) (((x)<((srf)[0]))&&((y)<((srf)[1]))? &HD_SRF_PIXF(srf,x,y) : 0)
#define HD_SRF_PIXELS(srf) ((srf) + 2 + ((srf)[1]))
#define HD_SRF_END(srf) ((srf) + 2 + ((srf)[1]) + (((srf)[0]) * ((srf)[1])))

Animation

void HD_AnimateLinear (hd_object *obj, int sx, int sy, int sw, int sh,
                       int dx, int dy, int dw, int dh, int frames, void (*done)(hd_object *));
void HD_AnimateCircle (hd_object *obj, int x, int y, int r, int32 fbot, int32 ftop,
                       int astart, int adist, int frames);
void HD_XAnimateCircle (hd_object *obj, int x, int y, int xr, int yr, int32 fbot, int32 ftop,
                        int astart, int adist, int frames);
void HD_StopAnimation (hd_object *obj);
int32 fsin (int32 angle); // angle is in units of 1024 per pi/2 radians - that is, rad*2048/pi
                          // ret is a 16.16 fixpt - 0x10000 is 1, 0x0000 is 0
int32 fcos (int32 angle); // same

Primitives

#define HD_CLEAR  0x00FFFFFF // magic value that says "clear this part to 0x00000000, no blending"
typedef struct _hd_point {
        int x, y;
} hd_point;
void HD_Pixel(hd_surface srf, int x, int y, uint32 col);
void HD_Line(hd_surface srf, int x0, int y0, int x1, int y1, uint32 col);
void HD_AALine(hd_surface srf, int x0, int y0, int x1, int y1, uint32 col);
void HD_Lines(hd_surface srf, hd_point *points, int n, uint32 col);
void HD_AALines(hd_surface srf, hd_point *points, int n, uint32 col);
void HD_Poly(hd_surface srf, hd_point *points, int n, uint32 col);
void HD_AAPoly(hd_surface srf, hd_point *points, int n, uint32 col);
void HD_FillPoly(hd_surface srf, hd_point *points, int n, uint32 col);
void HD_Bitmap(hd_surface srf, int x, int y, int w, int h,
                const unsigned short *bits, uint32 col);
void HD_FillRect(hd_surface srf, int x1, int y1, int x2, int y2, uint32 col);
void HD_Rect(hd_surface srf, int x1, int y1, int x2, int y2, uint32 col);
void HD_Circle(hd_surface srf, int x, int y, int r, uint32 col);
void HD_AACircle(hd_surface srf, int xc, int yc, int r, uint32 col);
void HD_FillCircle(hd_surface srf, int x, int y, int r, uint32 col);
void HD_AAFillCircle(hd_surface srf, int xc, int yc, int r, uint32 col);
void HD_AAEllipse(hd_surface srf, int xc, int yc, int rx, int ry, uint32 col);
void HD_Ellipse(hd_surface srf, int x, int y, int rx, int ry, uint32 col);
void HD_FillEllipse(hd_surface srf, int x, int y, int rx, int ry, uint32 col);
void HD_AAFillEllipse(hd_surface srf, int x, int y, int rx, int ry, uint32 col);
void HD_Bezier(hd_surface srf, int order, hd_point *points,
               int resolution, uint32 col);
void HD_AABezier(hd_surface srf, int order, hd_point *points,
                 int resolution, uint32 col);
void HD_Blur(hd_surface srf, int x, int y, int w, int h, int rad);
void HD_Chrome(hd_surface srf, int x, int y, int w, int h);
Retrieved from "http://ipodlinux.org/Hotdog"