Adding an API for developing Magic tools as plug-ins. (e.g., '.so'
shared objects under Linux) Ported (most of) 'Negative' magic tool to Magic tool plug-in system.
35
magic/Makefile
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# Makefile for magic plugins
|
||||
|
||||
SDL_CFLAGS=$(shell sdl-config --cflags)
|
||||
CFLAGS=-g -Wall $(SDL_CFLAGS) -DDATA_PREFIX=\"$(DATA_PREFIX)\"
|
||||
#-fPIC ?
|
||||
|
||||
all: negative.so
|
||||
|
||||
clean:
|
||||
@echo
|
||||
@echo "Cleaning up the Magic plug-ins directory ($(PWD))"
|
||||
@-rm -f *.so
|
||||
@-rm -f obj/*
|
||||
|
||||
|
||||
# Negative tool
|
||||
# ------------------------------------------------------------------------
|
||||
|
||||
negative.so: obj obj/negative.o obj/magic_helpers.o
|
||||
@echo "Linking Negative magic tool"
|
||||
@$(CC) -shared -o negative.so obj/negative.o obj/magic_helpers.o
|
||||
|
||||
obj/negative.o: src/negative.c src/magic_helpers.h
|
||||
@echo "Compiling Negative magic tool"
|
||||
@$(CC) $(CFLAGS) src/negative.c -c -o obj/negative.o
|
||||
|
||||
|
||||
|
||||
obj/magic_helpers.o: src/magic_helpers.c src/magic_helpers.h
|
||||
@echo "Compiling Magic tool helper routines"
|
||||
@$(CC) $(CFLAGS) src/magic_helpers.c -c -o obj/magic_helpers.o
|
||||
|
||||
obj:
|
||||
@-mkdir obj
|
||||
|
||||
BIN
magic/icons/blocks.png
Normal file
|
After Width: | Height: | Size: 162 B |
BIN
magic/icons/blur.png
Normal file
|
After Width: | Height: | Size: 242 B |
BIN
magic/icons/cartoon.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
magic/icons/chalk.png
Normal file
|
After Width: | Height: | Size: 713 B |
BIN
magic/icons/darken.png
Normal file
|
After Width: | Height: | Size: 791 B |
BIN
magic/icons/drip.png
Normal file
|
After Width: | Height: | Size: 498 B |
BIN
magic/icons/fade.png
Normal file
|
After Width: | Height: | Size: 579 B |
BIN
magic/icons/fill.png
Normal file
|
After Width: | Height: | Size: 679 B |
BIN
magic/icons/flip.png
Normal file
|
After Width: | Height: | Size: 186 B |
BIN
magic/icons/grass.png
Normal file
|
After Width: | Height: | Size: 457 B |
BIN
magic/icons/largebrick.png
Normal file
|
After Width: | Height: | Size: 118 B |
BIN
magic/icons/mirror.png
Normal file
|
After Width: | Height: | Size: 766 B |
BIN
magic/icons/negative.png
Normal file
|
After Width: | Height: | Size: 400 B |
BIN
magic/icons/rainbow.png
Normal file
|
After Width: | Height: | Size: 955 B |
BIN
magic/icons/smallbrick.png
Normal file
|
After Width: | Height: | Size: 118 B |
BIN
magic/icons/smudge.png
Normal file
|
After Width: | Height: | Size: 876 B |
BIN
magic/icons/sparkles.png
Normal file
|
After Width: | Height: | Size: 851 B |
BIN
magic/icons/thick.png
Normal file
|
After Width: | Height: | Size: 424 B |
BIN
magic/icons/thin.png
Normal file
|
After Width: | Height: | Size: 334 B |
BIN
magic/icons/tint.png
Normal file
|
After Width: | Height: | Size: 931 B |
238
magic/src/magic_helpers.c
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
#include "../../src/compiler.h"
|
||||
#include "magic_helpers.h"
|
||||
|
||||
int MAGIC_in_circle(int x, int y, int radius)
|
||||
{
|
||||
if ((x * x) + (y * y) - (radius * radius) < 0)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/* Draw a single pixel into the surface: */
|
||||
|
||||
void MAGIC_putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel)
|
||||
{
|
||||
Uint8 *p;
|
||||
|
||||
/* Assuming the X/Y values are within the bounds of this surface... */
|
||||
if (likely
|
||||
(likely((unsigned) x < (unsigned) surface->w)
|
||||
&& likely((unsigned) y < (unsigned) surface->h)))
|
||||
{
|
||||
// Set a pointer to the exact location in memory of the pixel
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
x); /* Go in X pixels */
|
||||
|
||||
|
||||
/* Set the (correctly-sized) piece of data in the surface's RAM
|
||||
* to the pixel value sent in: */
|
||||
|
||||
*p = pixel;
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw a single pixel into the surface: */
|
||||
void MAGIC_putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel)
|
||||
{
|
||||
Uint8 *p;
|
||||
|
||||
/* Assuming the X/Y values are within the bounds of this surface... */
|
||||
if (likely
|
||||
(likely((unsigned) x < (unsigned) surface->w)
|
||||
&& likely((unsigned) y < (unsigned) surface->h)))
|
||||
{
|
||||
// Set a pointer to the exact location in memory of the pixel
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
(x * 2)); /* Go in X pixels */
|
||||
|
||||
|
||||
/* Set the (correctly-sized) piece of data in the surface's RAM
|
||||
* to the pixel value sent in: */
|
||||
|
||||
*(Uint16 *) p = pixel;
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw a single pixel into the surface: */
|
||||
void MAGIC_putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel)
|
||||
{
|
||||
Uint8 *p;
|
||||
|
||||
/* Assuming the X/Y values are within the bounds of this surface... */
|
||||
if (likely
|
||||
(likely((unsigned) x < (unsigned) surface->w)
|
||||
&& likely((unsigned) y < (unsigned) surface->h)))
|
||||
{
|
||||
// Set a pointer to the exact location in memory of the pixel
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
(x * 3)); /* Go in X pixels */
|
||||
|
||||
|
||||
/* Set the (correctly-sized) piece of data in the surface's RAM
|
||||
* to the pixel value sent in: */
|
||||
|
||||
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||
{
|
||||
p[0] = (pixel >> 16) & 0xff;
|
||||
p[1] = (pixel >> 8) & 0xff;
|
||||
p[2] = pixel & 0xff;
|
||||
}
|
||||
else
|
||||
{
|
||||
p[0] = pixel & 0xff;
|
||||
p[1] = (pixel >> 8) & 0xff;
|
||||
p[2] = (pixel >> 16) & 0xff;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw a single pixel into the surface: */
|
||||
void MAGIC_putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel)
|
||||
{
|
||||
Uint8 *p;
|
||||
|
||||
/* Assuming the X/Y values are within the bounds of this surface... */
|
||||
if (likely
|
||||
(likely((unsigned) x < (unsigned) surface->w)
|
||||
&& likely((unsigned) y < (unsigned) surface->h)))
|
||||
{
|
||||
// Set a pointer to the exact location in memory of the pixel
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start: beginning of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
(x * 4)); /* Go in X pixels */
|
||||
|
||||
|
||||
/* Set the (correctly-sized) piece of data in the surface's RAM
|
||||
* to the pixel value sent in: */
|
||||
|
||||
*(Uint32 *) p = pixel; // 32-bit display
|
||||
}
|
||||
}
|
||||
|
||||
/* Get a pixel: */
|
||||
Uint32 MAGIC_getpixel8(SDL_Surface * surface, int x, int y)
|
||||
{
|
||||
Uint8 *p;
|
||||
|
||||
/* get the X/Y values within the bounds of this surface */
|
||||
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
|
||||
x = (x < 0) ? 0 : surface->w - 1;
|
||||
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
|
||||
y = (y < 0) ? 0 : surface->h - 1;
|
||||
|
||||
/* Set a pointer to the exact location in memory of the pixel
|
||||
in question: */
|
||||
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
x); /* Go in X pixels */
|
||||
|
||||
|
||||
/* Return the correctly-sized piece of data containing the
|
||||
* pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
|
||||
* RGB value) */
|
||||
|
||||
return (*p);
|
||||
}
|
||||
|
||||
/* Get a pixel: */
|
||||
Uint32 MAGIC_getpixel16(SDL_Surface * surface, int x, int y)
|
||||
{
|
||||
Uint8 *p;
|
||||
|
||||
/* get the X/Y values within the bounds of this surface */
|
||||
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
|
||||
x = (x < 0) ? 0 : surface->w - 1;
|
||||
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
|
||||
y = (y < 0) ? 0 : surface->h - 1;
|
||||
|
||||
/* Set a pointer to the exact location in memory of the pixel
|
||||
in question: */
|
||||
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
(x * 2)); /* Go in X pixels */
|
||||
|
||||
|
||||
/* Return the correctly-sized piece of data containing the
|
||||
* pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
|
||||
* RGB value) */
|
||||
|
||||
return (*(Uint16 *) p);
|
||||
}
|
||||
|
||||
/* Get a pixel: */
|
||||
Uint32 MAGIC_getpixel24(SDL_Surface * surface, int x, int y)
|
||||
{
|
||||
Uint8 *p;
|
||||
Uint32 pixel;
|
||||
|
||||
/* get the X/Y values within the bounds of this surface */
|
||||
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
|
||||
x = (x < 0) ? 0 : surface->w - 1;
|
||||
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
|
||||
y = (y < 0) ? 0 : surface->h - 1;
|
||||
|
||||
/* Set a pointer to the exact location in memory of the pixel
|
||||
in question: */
|
||||
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
(x * 3)); /* Go in X pixels */
|
||||
|
||||
|
||||
/* Return the correctly-sized piece of data containing the
|
||||
* pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
|
||||
* RGB value) */
|
||||
|
||||
/* Depending on the byte-order, it could be stored RGB or BGR! */
|
||||
|
||||
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||
pixel = p[0] << 16 | p[1] << 8 | p[2];
|
||||
else
|
||||
pixel = p[0] | p[1] << 8 | p[2] << 16;
|
||||
|
||||
return pixel;
|
||||
}
|
||||
|
||||
/* Get a pixel: */
|
||||
Uint32 MAGIC_getpixel32(SDL_Surface * surface, int x, int y)
|
||||
{
|
||||
Uint8 *p;
|
||||
|
||||
/* get the X/Y values within the bounds of this surface */
|
||||
if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
|
||||
x = (x < 0) ? 0 : surface->w - 1;
|
||||
if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
|
||||
y = (y < 0) ? 0 : surface->h - 1;
|
||||
|
||||
/* Set a pointer to the exact location in memory of the pixel
|
||||
in question: */
|
||||
|
||||
p = (Uint8 *) (((Uint8 *) surface->pixels) + /* Start at top of RAM */
|
||||
(y * surface->pitch) + /* Go down Y lines */
|
||||
(x * 4)); /* Go in X pixels */
|
||||
|
||||
|
||||
/* Return the correctly-sized piece of data containing the
|
||||
* pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
|
||||
* RGB value) */
|
||||
|
||||
return *(Uint32 *) p; // 32-bit display
|
||||
}
|
||||
|
||||
void (*MAGIC_putpixels[]) (SDL_Surface *, int, int, Uint32) =
|
||||
{
|
||||
MAGIC_putpixel8, MAGIC_putpixel8, MAGIC_putpixel16, MAGIC_putpixel24, MAGIC_putpixel32};
|
||||
|
||||
|
||||
Uint32(*MAGIC_getpixels[])(SDL_Surface *, int, int) =
|
||||
{
|
||||
MAGIC_getpixel8, MAGIC_getpixel8, MAGIC_getpixel16, MAGIC_getpixel24, MAGIC_getpixel32};
|
||||
|
||||
23
magic/src/magic_helpers.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef MAGIC_HELPERS_H
|
||||
#define MAGIC_HELPERS_H
|
||||
|
||||
#include "SDL.h"
|
||||
#include <libintl.h>
|
||||
|
||||
int MAGIC_in_circle(int x, int y, int radius);
|
||||
|
||||
void MAGIC_putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel);
|
||||
void MAGIC_putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel);
|
||||
void MAGIC_putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel);
|
||||
void MAGIC_putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel);
|
||||
|
||||
extern void (*MAGIC_putpixels[]) (SDL_Surface *, int, int, Uint32);
|
||||
|
||||
Uint32 MAGIC_getpixel8(SDL_Surface * surface, int x, int y);
|
||||
Uint32 MAGIC_getpixel16(SDL_Surface * surface, int x, int y);
|
||||
Uint32 MAGIC_getpixel24(SDL_Surface * surface, int x, int y);
|
||||
Uint32 MAGIC_getpixel32(SDL_Surface * surface, int x, int y);
|
||||
|
||||
extern Uint32(*MAGIC_getpixels[]) (SDL_Surface *, int, int);
|
||||
|
||||
#endif
|
||||
111
magic/src/negative.c
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "SDL_image.h"
|
||||
#include "magic_helpers.h"
|
||||
|
||||
void init()
|
||||
{
|
||||
printf("negative plugin initializing\n");
|
||||
}
|
||||
|
||||
int get_tool_count(void)
|
||||
{
|
||||
printf("negative tool reporting tool count: 1\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
SDL_Surface * get_icon(int which)
|
||||
{
|
||||
printf("Loading icon: " DATA_PREFIX "/images/magic/negative.png\n");
|
||||
return(IMG_Load(DATA_PREFIX "/images/magic/negative.png"));
|
||||
}
|
||||
|
||||
char * get_name(int which)
|
||||
{
|
||||
/* Only 1 tool; ignoring 'which' */
|
||||
|
||||
return(strdup(gettext("Negative")));
|
||||
}
|
||||
|
||||
char * get_description(int which)
|
||||
{
|
||||
/* Only 1 tool; ignoring 'which' */
|
||||
|
||||
return(strdup(gettext("Click and move the mouse around to draw a negative.")));
|
||||
}
|
||||
|
||||
void drag(int which, SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y);
|
||||
|
||||
void click(int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||
{
|
||||
/*
|
||||
SDL_Rect src, dest;
|
||||
|
||||
src.x = x - 12;
|
||||
src.y = y - 12;
|
||||
src.w = 16;
|
||||
src.h = 16;
|
||||
|
||||
dest.x = x - 8;
|
||||
dest.y = y - 8;
|
||||
dest.w = 16;
|
||||
dest.h = 16;
|
||||
|
||||
SDL_BlitSurface(last, &src, canvas, &dest);
|
||||
*/
|
||||
|
||||
drag(which, canvas, last, x, y, x, y);
|
||||
}
|
||||
|
||||
void drag(int which, SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y)
|
||||
{
|
||||
int xx, yy;
|
||||
Uint8 r, g, b;
|
||||
void (*putpixel) (SDL_Surface *, int, int, Uint32) =
|
||||
MAGIC_putpixels[canvas->format->BytesPerPixel];
|
||||
Uint32(*getpixel_last) (SDL_Surface *, int, int);
|
||||
|
||||
getpixel_last = MAGIC_getpixels[last->format->BytesPerPixel];
|
||||
|
||||
|
||||
SDL_LockSurface(last);
|
||||
SDL_LockSurface(canvas);
|
||||
|
||||
for (yy = y - 16; yy < y + 16; yy++)
|
||||
{
|
||||
for (xx = x - 16; xx < x + 16; xx++)
|
||||
{
|
||||
if (MAGIC_in_circle(xx - x, yy - y, 16))
|
||||
{
|
||||
SDL_GetRGB(getpixel_last(last, xx, yy), last->format, &r, &g, &b);
|
||||
|
||||
r = 0xFF - r;
|
||||
g = 0xFF - g;
|
||||
b = 0xFF - b;
|
||||
|
||||
putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, r, g, b));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_UnlockSurface(canvas);
|
||||
SDL_UnlockSurface(last);
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
printf("negative plugin shutting down\n");
|
||||
}
|
||||
|
||||
void set_color(Uint8 r, Uint8 g, Uint8 b)
|
||||
{
|
||||
/* Doesn't use color; ignoring */
|
||||
}
|
||||
|
||||
int requires_colors(int which)
|
||||
{
|
||||
/* (Only 1 tool; ignoring 'which') */
|
||||
|
||||
return 0; // Don't need a color palette
|
||||
}
|
||||
|
||||