git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@184 92316355-f0b4-4df1-b90c-862c8a59935fmaster
@@ -15,5 +15,6 @@ libee_a_SOURCES = \ | |||||
conic.c \ | conic.c \ | ||||
triangle.c \ | triangle.c \ | ||||
sprite.c \ | sprite.c \ | ||||
blit.c \ | |||||
$(NULL) | $(NULL) | ||||
@@ -0,0 +1,102 @@ | |||||
/* | |||||
* libee ASCII-Art library | |||||
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id$ | |||||
* | |||||
* This program is free software; you can redistribute it and/or modify | |||||
* it under the terms of the GNU General Public License as published by | |||||
* the Free Software Foundation; either version 2 of the License, or | |||||
* (at your option) any later version. | |||||
* | |||||
* This program is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU General Public License | |||||
* along with this program; if not, write to the Free Software | |||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |||||
*/ | |||||
#include "config.h" | |||||
#ifdef HAVE_INTTYPES_H | |||||
# include <inttypes.h> | |||||
#else | |||||
typedef unsigned char uint8_t; | |||||
#endif | |||||
#include <stdlib.h> | |||||
#include "ee.h" | |||||
#include "ee_internals.h" | |||||
#include <stdio.h> | |||||
void ee_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h) | |||||
{ | |||||
char foo[] = { ' ', '.', ':', ';', '=', '$', '%', '@', '#', '8', 'W' }; | |||||
int x, y, pitch; | |||||
if(x1 > x2) | |||||
{ | |||||
int tmp = x2; x2 = x1; x1 = tmp; | |||||
} | |||||
if(y1 > y2) | |||||
{ | |||||
int tmp = y2; y2 = y1; y1 = tmp; | |||||
} | |||||
pitch = (3 * w + 3) / 4 * 4; | |||||
for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= ee_get_height(); y++) | |||||
for(x = x1 > 0 ? x1 : 0; x <= x2 && x <= ee_get_width(); x++) | |||||
{ | |||||
int fromx = w * (x - x1) / (x2 - x1 + 1); | |||||
int fromy = h * (y - y1) / (y2 - y1 + 1); | |||||
int r = ((unsigned char *)pixels)[3 * fromx + pitch * fromy]; | |||||
int g = ((unsigned char *)pixels)[3 * fromx + 1 + pitch * fromy]; | |||||
int b = ((unsigned char *)pixels)[3 * fromx + 2 + pitch * fromy]; | |||||
if(r == g && g == b) | |||||
{ | |||||
ee_set_color(EE_LIGHTGRAY); | |||||
} | |||||
else | |||||
{ | |||||
static int foo_colors[6] = {EE_LIGHTRED, EE_YELLOW, EE_LIGHTGREEN, EE_LIGHTCYAN, EE_LIGHTBLUE, EE_LIGHTMAGENTA}; | |||||
float min = r, max = r, delta, hue, sat; | |||||
if(min > g) min = g; if(max < g) max = g; | |||||
if(min > b) min = b; if(max < b) max = b; | |||||
delta = max - min; | |||||
sat = max / delta; | |||||
if(delta > 20) | |||||
{ | |||||
if( r == max ) | |||||
hue = (g - b) / delta; // between yellow & magenta | |||||
else if( g == max ) | |||||
hue = 2 + (b - r) / delta; // between cyan & yellow | |||||
else | |||||
hue = 4 + (r - g) / delta; // between magenta & cyan | |||||
hue *= 60; // degrees | |||||
if( hue < 0 ) | |||||
hue += 360; | |||||
ee_set_color(foo_colors[(int)(hue + 30) / 60]); | |||||
} | |||||
else | |||||
{ | |||||
ee_set_color(EE_LIGHTGRAY); | |||||
} | |||||
} | |||||
ee_putchar(x, y, foo[(r + g + b) / 3 / 25]); | |||||
} | |||||
} | |||||
@@ -107,6 +107,8 @@ int ee_get_sprite_dy(struct ee_sprite *, int); | |||||
void ee_draw_sprite(int, int, struct ee_sprite *, int); | void ee_draw_sprite(int, int, struct ee_sprite *, int); | ||||
void ee_free_sprite(struct ee_sprite *); | void ee_free_sprite(struct ee_sprite *); | ||||
void ee_blit(int, int, int, int, void *, int, int); | |||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
} | } | ||||
#endif | #endif | ||||
@@ -15,6 +15,8 @@ bin_PROGRAMS = demo spritedit | |||||
demo_SOURCES = demo.c | demo_SOURCES = demo.c | ||||
demo_LDADD = ../libee/libee.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -lm | demo_LDADD = ../libee/libee.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -lm | ||||
demo_CFLAGS = `pkg-config --cflags gtk+-2.0` | |||||
demo_LDFLAGS = `pkg-config --libs gtk+-2.0` | |||||
spritedit_SOURCES = spritedit.c | spritedit_SOURCES = spritedit.c | ||||
spritedit_LDADD = ../libee/libee.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -lm | spritedit_LDADD = ../libee/libee.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -lm | ||||
@@ -26,6 +26,9 @@ | |||||
#include <string.h> | #include <string.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <gdk/gdk.h> | |||||
#include <gdk/gdkpixbuf.h> | |||||
#include "ee.h" | #include "ee.h" | ||||
static void display_menu(void); | static void display_menu(void); | ||||
@@ -39,11 +42,16 @@ static void demo_boxes(void); | |||||
static void demo_ellipses(void); | static void demo_ellipses(void); | ||||
static void demo_triangles(void); | static void demo_triangles(void); | ||||
static void demo_sprites(void); | static void demo_sprites(void); | ||||
static void demo_blit(void); | |||||
int bounds = 0; | int bounds = 0; | ||||
int outline = 0; | int outline = 0; | ||||
struct ee_sprite *sprite = NULL; | struct ee_sprite *sprite = NULL; | ||||
GdkPixbuf *pixbuf; | |||||
char *pixels; | |||||
int bufx, bufy, bufpitch; | |||||
int main(int argc, char **argv) | int main(int argc, char **argv) | ||||
{ | { | ||||
void (*demo)(void) = NULL; | void (*demo)(void) = NULL; | ||||
@@ -59,6 +67,19 @@ int main(int argc, char **argv) | |||||
/* Initialize data */ | /* Initialize data */ | ||||
sprite = ee_load_sprite("data/barboss.txt"); | sprite = ee_load_sprite("data/barboss.txt"); | ||||
gdk_init (&argc, &argv); | |||||
//pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/gally4.jpeg", NULL); | |||||
//pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/badge1.jpeg", NULL); | |||||
//pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/union.png", NULL); | |||||
pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/pikachu.jpeg", NULL); | |||||
if(!pixbuf) return -2; | |||||
pixels = gdk_pixbuf_get_pixels(pixbuf); | |||||
bufx = gdk_pixbuf_get_width(pixbuf); | |||||
bufy = gdk_pixbuf_get_height(pixbuf); | |||||
bufpitch = gdk_pixbuf_get_rowstride(pixbuf); | |||||
fprintf(stderr, "bits: %i\n", gdk_pixbuf_get_bits_per_sample(pixbuf)); | |||||
fprintf(stderr, "w %i, h %i, stride %i\n", bufx, bufy, bufpitch); | |||||
/* Main menu */ | /* Main menu */ | ||||
display_menu(); | display_menu(); | ||||
ee_refresh(); | ee_refresh(); | ||||
@@ -120,6 +141,10 @@ int main(int argc, char **argv) | |||||
case 'S': | case 'S': | ||||
demo = demo_sprites; | demo = demo_sprites; | ||||
break; | break; | ||||
case 'i': | |||||
case 'I': | |||||
demo = demo_blit; | |||||
break; | |||||
} | } | ||||
if(demo) | if(demo) | ||||
@@ -173,11 +198,12 @@ static void display_menu(void) | |||||
ee_putstr(4, 12, "'5': ellipses"); | ee_putstr(4, 12, "'5': ellipses"); | ||||
ee_putstr(4, 13, "'s': sprites"); | ee_putstr(4, 13, "'s': sprites"); | ||||
ee_putstr(4, 14, "'c': color"); | ee_putstr(4, 14, "'c': color"); | ||||
ee_putstr(4, 15, "'i': image blit"); | |||||
ee_putstr(4, 16, "settings:"); | |||||
ee_printf(4, 17, "'o': outline: %s", | |||||
ee_putstr(4, 17, "settings:"); | |||||
ee_printf(4, 18, "'o': outline: %s", | |||||
outline == 0 ? "none" : outline == 1 ? "solid" : "thin"); | outline == 0 ? "none" : outline == 1 ? "solid" : "thin"); | ||||
ee_printf(4, 18, "'b': drawing boundaries: %s", | |||||
ee_printf(4, 19, "'b': drawing boundaries: %s", | |||||
bounds == 0 ? "screen" : "infinite"); | bounds == 0 ? "screen" : "infinite"); | ||||
ee_putstr(4, yo - 2, "'q': quit"); | ee_putstr(4, yo - 2, "'q': quit"); | ||||
@@ -428,3 +454,9 @@ static void demo_sprites(void) | |||||
ee_rand(0, ee_get_height() - 1), sprite, 0); | ee_rand(0, ee_get_height() - 1), sprite, 0); | ||||
} | } | ||||
static void demo_blit(void) | |||||
{ | |||||
ee_set_color(EE_LIGHTGRAY); | |||||
ee_blit(6, 4, ee_get_width() - 6, ee_get_height() - 4, pixels, bufx, bufy); | |||||
} | |||||