Release 0.1.4

Seems to introduce PNG support. From original change log:

0.1.4:
    New option: -n, --nice
    New option: --dir
    Load images from a directory

0.1.3:
    Bugfixes and optimisation release (use much less cpu).
    Nothing new here.
This commit is contained in:
Eirik Øverby 2025-02-09 17:54:26 +01:00
parent b813abbbd4
commit 19b9d73eba
19 changed files with 261 additions and 60408 deletions

View file

@ -2,3 +2,4 @@ Pascal Terjan <pascal.terjan@free.fr>: -N, --noNice option
Gilles Cuesta <gcuesta@netimedias.com>: bug report Gilles Cuesta <gcuesta@netimedias.com>: bug report
Olivier Perron <olivier.perron@gadz.org>: debian package Olivier Perron <olivier.perron@gadz.org>: debian package
Guillaume Rousse <rousse@ccr.jussieu.fr>: rpm package Guillaume Rousse <rousse@ccr.jussieu.fr>: rpm package
Cyprien Laplace <cyprien33@laposte.net>: new developper

View file

@ -1,3 +1,14 @@
2004-08-25 Cypou <cyprien33@laposte.net>
* loader.c: Used to load images from a directory
* hot-babe.c: Use of loader.c, added small optimisations, added a -n
(--nice) option to automatically nice the hot-babe. Added
--dir option to specify another images directory.
2004-08-22 DindinX <david@dindinx.org>
* hot-babe.c: Don't divide by zero (reported by different people),
some small optimisations, too.
2002-09-21 DindinX <david@dindinx.org> 2002-09-21 DindinX <david@dindinx.org>
* hot-babe.c: applied a patch by Pascal Terjan <pascal.terjan@free.fr> * hot-babe.c: applied a patch by Pascal Terjan <pascal.terjan@free.fr>

View file

@ -3,9 +3,9 @@ PREFIX = /usr/local
DESTDIR = ${PREFIX} DESTDIR = ${PREFIX}
# optimization cflags # optimization cflags
CFLAGS = -O2 -Wall -g `gtk-config --cflags` `gdk-pixbuf-config --cflags` CFLAGS = -O2 -Wall -g `gtk-config --cflags` `gdk-pixbuf-config --cflags` -DDESTDIR=\"$(DESTDIR)\"
OBJS = hot-babe.o OBJS = hot-babe.o loader.o
CC = gcc CC = gcc
LIBS = `gtk-config --libs | sed "s/-lgtk//g"` `gdk-pixbuf-config --libs` LIBS = `gtk-config --libs | sed "s/-lgtk//g"` `gdk-pixbuf-config --libs`
INSTALL = -m 755 INSTALL = -m 755
@ -21,3 +21,6 @@ clean:
install: install:
install -d $(DESTDIR)/bin install -d $(DESTDIR)/bin
install $(INSTALL) hot-babe $(DESTDIR)/bin install $(INSTALL) hot-babe $(DESTDIR)/bin
install -d $(DESTDIR)/share/hot-babe
install -d $(DESTDIR)/share/hot-babe/hb01
install $(INSTALL) hb01/* $(DESTDIR)/share/hot-babe/hb01

8
NEWS
View file

@ -1,3 +1,11 @@
0.1.4:
- New option: -n, --nice
- New option: --dir
- Load images from a directory
0.1.3:
- bugfixes and optimisation release. Nothing new here.
0.1.2: 0.1.2:
-New option: -N, --noNice -New option: -N, --noNice
With this option, the reniced processes aren't counted. This is usefull With this option, the reniced processes aren't counted. This is usefull

6
hb01/descr Normal file
View file

@ -0,0 +1,6 @@
5
hb01_4.png
hb01_3.png
hb01_2.png
hb01_1.png
hb01_0.png

BIN
hb01/hb01_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

File diff suppressed because it is too large Load diff

BIN
hb01/hb01_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

File diff suppressed because it is too large Load diff

BIN
hb01/hb01_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

File diff suppressed because it is too large Load diff

BIN
hb01/hb01_3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

File diff suppressed because it is too large Load diff

BIN
hb01/hb01_4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

File diff suppressed because it is too large Load diff

View file

@ -48,6 +48,8 @@ ponder every sample with time, the result is a somewhat smoother animation, and
.TP .TP
.B \-N, \-\-noNice .B \-N, \-\-noNice
Don't consider reniced processes. This is usefull if you use seti@home or distributed.net, which always eat almost all the CPU. Don't consider reniced processes. This is usefull if you use seti@home or distributed.net, which always eat almost all the CPU.
.B \-n, \-\-nice
n Put the hot-babe process in nice n.
.SH SEE ALSO .SH SEE ALSO
.br .br
.SH AUTHOR .SH AUTHOR

View file

@ -32,11 +32,7 @@
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf.h>
#include "hb01/hb01_0.xpm" #include "loader.h"
#include "hb01/hb01_1.xpm"
#include "hb01/hb01_2.xpm"
#include "hb01/hb01_3.xpm"
#include "hb01/hb01_4.xpm"
static int system_cpu(void); static int system_cpu(void);
static void hotbabe_setup_samples(void); static void hotbabe_setup_samples(void);
@ -49,10 +45,10 @@ static void print_usage(void);
typedef struct typedef struct
{ {
/* X11 stuff */ /* X11 stuff */
gint height, width;
GdkWindow *win; /* main window */ GdkWindow *win; /* main window */
GdkPixbuf *current_pixbuf; HotBabeAnim anim;
GdkPixbuf *pixbuf[10]; guchar **pixels;
guchar *dest;
int samples; int samples;
@ -67,8 +63,6 @@ typedef struct
guint delay; guint delay;
} HotBabeData; } HotBabeData;
int nb_xpm;
HotBabeData bm; HotBabeData bm;
/* returns current CPU load in percent, 0 to 256 */ /* returns current CPU load in percent, 0 to 256 */
@ -105,7 +99,7 @@ static int system_cpu(void)
* is calculated as the extra amount of work that has been performed * is calculated as the extra amount of work that has been performed
* since the last sample. yah, right, what the fuck does that mean? * since the last sample. yah, right, what the fuck does that mean?
*/ */
if (ototal == 0) /* ototal == 0 means that this is the first time we get here */ if (ototal == 0 || total==ototal) /* ototal == 0 means that this is the first time we get here */
cpuload = 0; cpuload = 0;
else else
cpuload = (256 * (load - oload)) / (total - ototal); cpuload = (256 * (load - oload)) / (total - ototal);
@ -113,28 +107,21 @@ static int system_cpu(void)
return cpuload; return cpuload;
} }
GdkPixmap *pixmap;
GdkGC *gc;
/* This is the function that actually creates the display widgets */ /* This is the function that actually creates the display widgets */
static void create_hotbabe_window(void) static void create_hotbabe_window(void)
{ {
#define MASK GDK_BUTTON_PRESS_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK #define MASK GDK_BUTTON_PRESS_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK
GdkWindowAttr attr; GdkWindowAttr attr;
GdkPixmap *pixmap;
GdkBitmap *mask; GdkBitmap *mask;
bm.current_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)hb01_4_xpm); bm.anim.width = gdk_pixbuf_get_width(bm.anim.pixbuf[0]);
bm.pixbuf[0] = gdk_pixbuf_new_from_xpm_data((const char **)hb01_4_xpm); bm.anim.height = gdk_pixbuf_get_height(bm.anim.pixbuf[0]);
bm.pixbuf[1] = gdk_pixbuf_new_from_xpm_data((const char **)hb01_3_xpm);
bm.pixbuf[2] = gdk_pixbuf_new_from_xpm_data((const char **)hb01_2_xpm);
bm.pixbuf[3] = gdk_pixbuf_new_from_xpm_data((const char **)hb01_1_xpm);
bm.pixbuf[4] = gdk_pixbuf_new_from_xpm_data((const char **)hb01_0_xpm);
nb_xpm = 5;
bm.width = gdk_pixbuf_get_width(bm.pixbuf[0]);
bm.height = gdk_pixbuf_get_height(bm.pixbuf[0]);
attr.width = bm.width; attr.width = bm.anim.width;
attr.height = bm.height; attr.height = bm.anim.height;
attr.title = "hot-babe"; attr.title = "hot-babe";
attr.event_mask = MASK; attr.event_mask = MASK;
attr.wclass = GDK_INPUT_OUTPUT; attr.wclass = GDK_INPUT_OUTPUT;
@ -154,28 +141,25 @@ static void create_hotbabe_window(void)
} }
gdk_window_set_decorations(bm.win, 0); gdk_window_set_decorations(bm.win, 0);
pixmap = gdk_pixbuf_render_pixmap_and_mask( bm.anim.pixbuf[4], &pixmap, &mask, 127 );
gdk_pixmap_create_from_xpm_d(bm.win, &mask, NULL, hb01_4_xpm);
gdk_window_shape_combine_mask(bm.win, mask, 0, 0); gdk_window_shape_combine_mask(bm.win, mask, 0, 0);
gdk_pixbuf_render_pixmap_and_mask( bm.anim.pixbuf[0], &pixmap, &mask, 127 );
gdk_window_set_back_pixmap(bm.win, pixmap, False); gdk_window_set_back_pixmap(bm.win, pixmap, False);
gdk_window_show(bm.win); gdk_window_show(bm.win);
hotbabe_setup_samples(); gc = gdk_gc_new (pixmap);
#undef MASK #undef MASK
} }
static void hotbabe_update(void) static void hotbabe_update(void)
{ {
unsigned int loadPercentage; guint loadPercentage;
static unsigned int old_percentage = 0; static guint old_percentage = 0;
GdkPixmap *pixmap; guint i;
GdkBitmap *mask; guchar *pixels1, *pixels2, *src1, *src2, *dest;
guint i; static gint robinet = 0;
guchar *pixels, *pixels1, *pixels2;
GdkPixbuf *bla;
static gint robinet = 0;
/* Find out the CPU load */ /* Find out the CPU load */
loadPercentage = system_cpu(); loadPercentage = system_cpu();
@ -197,47 +181,42 @@ static void hotbabe_update(void)
if (loadPercentage != old_percentage) if (loadPercentage != old_percentage)
{ {
gint range = 256 / (nb_xpm-1); gint range = 256 / (bm.anim.samples-1);
gint index = loadPercentage/range; gint index = loadPercentage/range;
old_percentage = loadPercentage; old_percentage = loadPercentage;
if (index>nb_xpm-1) index = nb_xpm-1; if (index>bm.anim.samples-1) index = bm.anim.samples-1;
pixels = gdk_pixbuf_get_pixels(bm.current_pixbuf); pixels1 = bm.pixels[index];
pixels1 = gdk_pixbuf_get_pixels(bm.pixbuf[index]); if (index == bm.anim.samples-1)
if (index == nb_xpm-1) pixels2 = bm.pixels[index];
pixels2 = gdk_pixbuf_get_pixels(bm.pixbuf[index]);
else else
pixels2 = gdk_pixbuf_get_pixels(bm.pixbuf[index+1]); pixels2 = bm.pixels[index+1];
loadPercentage = loadPercentage % range; loadPercentage = loadPercentage % range;
for (i=0 ; i<bm.height*bm.width ; i++) dest = bm.dest; src1 = pixels1; src2 = pixels2;
for (i=0 ; i<bm.anim.height*bm.anim.width ; i++)
{ {
guint val; guint val, j;
val = ((guint)pixels2[i*4+0])*loadPercentage+((guint)pixels1[i*4+0])*(range-loadPercentage);
val /= range; if (src1[3])
pixels[i*4+0] = val; {
val = ((guint)pixels2[i*4+1])*loadPercentage+((guint)pixels1[i*4+1])*(range-loadPercentage); for (j=0;j<3;j++)
val /= range; {
pixels[i*4+1] = val; val = ((guint)*(src2++))*loadPercentage+((guint)*(src1++))*(range-loadPercentage);
val = ((guint)pixels2[i*4+2])*loadPercentage+((guint)pixels1[i*4+2])*(range-loadPercentage); //val /= range;
val /= range; *(dest++) = (val >> 6); // bad hack!
pixels[i*4+2] = val; }
val = ((guint)pixels2[i*4+3])*loadPercentage+((guint)pixels1[i*4+3])*(range-loadPercentage); src1++;
val /= range; src2++;
pixels[i*4+3] = val; } else
{
src1+=4;src2+=4;dest+=3;
}
} }
bla = gdk_pixbuf_new_from_data(pixels, GDK_COLORSPACE_RGB,
gdk_pixbuf_get_has_alpha(bm.pixbuf[0]), gdk_draw_rgb_image(pixmap, gc, 0, 0, bm.anim.width, bm.anim.height, GDK_RGB_DITHER_NONE,
gdk_pixbuf_get_bits_per_sample(bm.pixbuf[0]), bm.dest, 3 * bm.anim.width);
gdk_pixbuf_get_width(bm.pixbuf[0]),
gdk_pixbuf_get_height(bm.pixbuf[0]),
gdk_pixbuf_get_rowstride(bm.pixbuf[0]), NULL, NULL);
gdk_pixbuf_render_pixmap_and_mask(bla, &pixmap, &mask, 127);
gdk_pixbuf_unref(bla);
gdk_window_set_back_pixmap(bm.win, pixmap, False); gdk_window_set_back_pixmap(bm.win, pixmap, False);
gdk_pixmap_unref(pixmap);
gdk_bitmap_unref(mask);
gdk_window_clear(bm.win); gdk_window_clear(bm.win);
} }
} }
@ -267,12 +246,15 @@ static void print_usage(void)
g_print(" -d, --delay n update every n millisecondes.\n"); g_print(" -d, --delay n update every n millisecondes.\n");
g_print(" -h, --help show this message and exit.\n"); g_print(" -h, --help show this message and exit.\n");
g_print(" -N, --noNice don't count nice time in usage.\n"); g_print(" -N, --noNice don't count nice time in usage.\n");
g_print(" -n, --nice n set self-nice to n.\n");
g_print(" --dir directory use images from directory.\n");
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
GdkEvent *event; GdkEvent *event;
gint i; gint i;
gchar *dir;
/* initialize GDK */ /* initialize GDK */
if (!gdk_init_check(&argc, &argv)) if (!gdk_init_check(&argc, &argv))
@ -290,6 +272,8 @@ int main(int argc, char **argv)
bm.incremental = FALSE; bm.incremental = FALSE;
bm.delay = 15000; bm.delay = 15000;
bm.noNice = FALSE; bm.noNice = FALSE;
dir = NULL;
for (i=1 ; i<argc ; i++) for (i=1 ; i<argc ; i++)
{ {
@ -299,6 +283,7 @@ int main(int argc, char **argv)
if (i<argc) if (i<argc)
{ {
bm.threshold = atoi(argv[i])*256/100; bm.threshold = atoi(argv[i])*256/100;
bm.threshold = MIN (255, bm.threshold);
} }
} else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) } else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h"))
{ {
@ -310,6 +295,13 @@ int main(int argc, char **argv)
} else if (!strcmp(argv[i], "--noNice") || !strcmp(argv[i], "-N")) } else if (!strcmp(argv[i], "--noNice") || !strcmp(argv[i], "-N"))
{ {
bm.noNice = TRUE; bm.noNice = TRUE;
} else if (!strcmp(argv[i], "--nice") || !strcmp(argv[i], "-n"))
{
i++;
if (i<argc)
{
nice( atoi(argv[i]) );
}
} else if (!strcmp(argv[i], "--delay") || !strcmp(argv[i], "-d")) } else if (!strcmp(argv[i], "--delay") || !strcmp(argv[i], "-d"))
{ {
i++; i++;
@ -317,11 +309,37 @@ int main(int argc, char **argv)
{ {
bm.delay = atoi(argv[i])*1000; bm.delay = atoi(argv[i])*1000;
} }
} else if (!strcmp(argv[i], "--dir"))
{
printf( "argv = %s\n", argv[i] );
printf( "argv = %s\n", argv[i+1] );
i++;
if (i<argc)
{
dir = argv[i];
}
} }
} }
if( dir != NULL ) {
if( load_anim( &bm.anim, dir ) ) {
fprintf( stderr, "Can't find pictures\n" );
return 1;
}
} else if( load_anim( &bm.anim, DESTDIR "/share/hot-babe/hb01" ) &&
load_anim( &bm.anim, "hb01" ) ) {
fprintf( stderr, "Can't find pictures\n" );
return 1;
}
create_hotbabe_window(); create_hotbabe_window();
bm.pixels = malloc( sizeof(guchar*) * bm.anim.samples );
for( i = 0 ; i < bm.anim.samples ; i++ )
bm.pixels[i] = gdk_pixbuf_get_pixels( bm.anim.pixbuf[i] );
bm.dest = malloc( bm.anim.width * bm.anim.height * 3 );
hotbabe_setup_samples();
while (1) while (1)
{ {
while (gdk_events_pending()) while (gdk_events_pending())

109
loader.c Normal file
View file

@ -0,0 +1,109 @@
/* Hot-babe
* Copyright (C) 2002 DindinX <David@dindinx.org>
* Copyright (C) 2002 Bruno Bellamy.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Please note that part of this code is from wmbubble, and such should be
* copyrighted by <timecop@japan.co.jp>
*
*/
/* general includes */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
/* filesystem includes */
#include <sys/types.h>
#include <sys/stat.h>
/* x11 includes */
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "loader.h"
/* Animation loader from a directory */
int load_anim( HotBabeAnim *anim, gchar *dirname )
{
struct stat buf;
int ret;
FILE *fd;
char filename[1024];
char line[1024];
int i;
anim->samples = 0;
anim->current_sample = 0;
/* dirname must be a valid directory */
if( dirname == NULL ) return 1;
if( (ret = stat( dirname, &buf )) < 0 ) {
return 1;
}
if( !S_ISDIR(buf.st_mode) ) {
return 2;
}
/* description file */
strncpy( filename, dirname, 512 );
strcat( filename, "/descr" );
if( (fd = fopen( filename, "r" )) == NULL ) {
perror( filename );
return 3;
}
if( fgets( line, 1023, fd ) == NULL )
{
fclose( fd );
perror( "--" );
return 4;
}
if( (anim->samples = atoi( line )) == 0 ) {
fclose( fd );
fprintf( stderr, "%s: bad file format\n", filename );
return 4;
}
/* load images */
anim->pixbuf = malloc( sizeof(GdkPixbuf*) * anim->samples );
for( i = 0 ; i < anim->samples ; i++ ) {
if( fgets( line, 512, fd ) == NULL ) {
fclose( fd );
perror( "--" );
return 5;
}
if( line[strlen(line)-1] == '\n' )
line[strlen(line)-1] = '\0';
strncpy( filename, dirname, 512 );
strcat( filename, "/" );
strcat( filename, line );
anim->pixbuf[i] = gdk_pixbuf_new_from_file( filename );
}
fclose( fd );
anim->width = gdk_pixbuf_get_width( anim->pixbuf[0]);
anim->height = gdk_pixbuf_get_height(anim->pixbuf[0]);
return 0;
}

31
loader.h Normal file
View file

@ -0,0 +1,31 @@
/* Hot-babe
* Copyright (C) 2002 DindinX <David@dindinx.org>
* Copyright (C) 2002 Bruno Bellamy.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Please note that part of this code is from wmbubble, and such should be
* copyrighted by <timecop@japan.co.jp>
*
*/
typedef struct
{
gint height, width;
gint samples, current_sample;
GdkPixbuf **pixbuf;
} HotBabeAnim;
int load_anim( HotBabeAnim *anim, gchar *dirname );