/* * EffecTV - Realtime Digital Video Effector * Copyright (C) 2001-2003 FUKUCHI Kentaro * * DotTV: convert gray scale image into a set of dots * Copyright (C) 2001-2002 FUKUCHI Kentaro * */ #include #include #include "EffecTV.h" #include "utils.h" #include "heart.inc" static int start(void); static int stop(void); static int draw(RGB32 *src, RGB32 *dest); static int event(); #define DOTDEPTH 5 #define DOTMAX (1<>16)&0xff]; i += GtoY[(rgb>>8)&0xff]; i += BtoY[rgb&0xff]; return i; } static void init_sampxy_table() { int i, j; j = dot_hsize; for(i=0; i15)?15:c; *pat-- = c<<20 | c<<12 | c<<4; /* The upper left part of a disk is needed, but generated pattern is a bottom * right part. So I spin the pattern. */ } } } } static void makeOneHeart(int val, unsigned char *bigheart) { int x, y; int xx, yy; int f1x, f1y; int f2x, f2y; double s1x, s1y; double s2x, s2y; double d1x, d1y; double d2x, d2y; double sum, hsum; double w, h; RGB32 *pat; RGB32 c; #define SFACT 4 pat = heart_pattern + val * dot_size * dot_hsize; s2y = (double)(-dot_hsize) / dot_size * (31.9 + (double)(DOTMAX-val)/SFACT) + 31.9; f2y = (int)s2y; for(y=0; y255) c = 255; *pat++ = c<<16; } } } static void makeHeartPattern() { int i, x, y; unsigned char *bigheart; bigheart = (unsigned char *)malloc(sizeof(unsigned char) * 64 * 32); memset(bigheart, 0, 64 * 32 * sizeof(unsigned char)); for(y=0; y<32; y++) { for(x=0; x<16;x++) { bigheart[(y+16)*32+x+16] = half_heart[y*16+x]; } } for(i=0; i 0) { scale = screen_scale; } else { scale = (double)screen_width / video_width; if(scale > (double)screen_height / video_height) { scale = (double)screen_height / video_height; } } dot_size = 8 * scale; dot_size = dot_size & 0xfe; dot_hsize = dot_size / 2; dots_width = screen_width / dot_size; dots_height = screen_height / dot_size; pattern = (RGB32 *)malloc(DOTMAX * dot_hsize * dot_hsize * sizeof(RGB32)); if(pattern == NULL) { return NULL; } heart_pattern = (RGB32 *)malloc(DOTMAX * dot_hsize * dot_size * PIXEL_SIZE); if(heart_pattern == NULL) { free(pattern); return NULL; } sharedbuffer_reset(); sampx = (int *)sharedbuffer_alloc(video_width*sizeof(int)); sampy = (int *)sharedbuffer_alloc(video_height*sizeof(int)); if(sampx == NULL || sampy == NULL) { return NULL; } entry = (effect *)malloc(sizeof(effect)); if(entry == NULL) { return NULL; } entry->name = effectname; entry->start = start; entry->stop = stop; entry->draw = draw; entry->event = event; makePattern(); makeHeartPattern(); return entry; } static int start() { init_sampxy_table(); state = 1; return 0; } static int stop() { state = 0; return 0; } static void drawDot(int xx, int yy, unsigned char c, RGB32 *dest) { int x, y; RGB32 *pat; c = (c>>(8-DOTDEPTH)); pat = pattern + c * dot_hsize * dot_hsize; dest = dest + yy * dot_size * screen_width + xx * dot_size; for(y=0; y>(8-DOTDEPTH)); pat = heart_pattern + c * dot_size * dot_hsize; dest = dest + yy * dot_size * screen_width + xx * dot_size; for(y=0; ytype == SDL_KEYDOWN) { switch(event->key.keysym.sym) { case SDLK_SPACE: mode ^= 1; break; default: break; } } return 0; }