/* $Id: widget_image.c,v 1.9 2006/06/21 05:12:43 reinelt Exp $ * * image widget handling * * Copyright (C) 2006 Michael Reinelt * Copyright (C) 2006 The LCD4Linux Team * * 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, 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. * * * $Log: widget_image.c,v $ * Revision 1.9 2006/06/21 05:12:43 reinelt * added checks for libgd version 2 (thanks to Sam) * * Revision 1.8 2006/06/20 08:50:59 reinelt * widget_image linker error hopefully finally fixed * * Revision 1.7 2006/04/15 05:22:52 reinelt * mpd plugin from Stefan Kuhne * * Revision 1.6 2006/04/09 14:17:50 reinelt * autoconf/library fixes, image and graphic display inversion * * Revision 1.5 2006/02/25 13:36:33 geronet * updated indent.sh, applied coding style * * Revision 1.4 2006/02/19 07:20:54 reinelt * image support nearly finished * * Revision 1.3 2006/02/08 04:55:05 reinelt * moved widget registration to drv_generic_graphic * * Revision 1.2 2006/01/23 06:17:18 reinelt * timer widget added * * Revision 1.1 2006/01/22 09:16:11 reinelt * Image Widget framework added * */ /* * exported functions: * * WIDGET_CLASS Widget_Image * the image widget * */ #include "config.h" #include #include #include #include #include #include "debug.h" #include "cfg.h" #include "qprintf.h" #include "evaluator.h" #include "timer.h" #include "widget.h" #include "widget_image.h" #include "rgb.h" #ifdef HAVE_GD_GD_H #include #else #ifdef HAVE_GD_H #include #else #error "gd.h not found!" #error "cannot compile image widget" #endif #endif #if GD2_VERS != 2 #error "lcd4linux requires libgd version 2" #error "cannot compile image widget" #endif #ifdef WITH_DMALLOC #include #endif static void widget_image_render(const char *Name, WIDGET_IMAGE * Image) { int x, y; FILE *fd; gdImagePtr gdImage = NULL; /* clear bitmap */ if (Image->bitmap) { int i; for (i = 0; i < Image->height * Image->width; i++) { RGBA empty = { R: 0x00, G: 0x00, B: 0x00, A:0x00 }; Image->bitmap[i] = empty; } } if (Image->file == NULL || Image->file[0] == '\0') { error("Warning: Image %s has no file", Name); return; } fd = fopen(Image->file, "rb"); if (fd == NULL) { error("Warning: Image %s: fopen(%s) failed: %s", Name, Image->file, strerror(errno)); return; } gdImage = gdImageCreateFromPng(fd); fclose(fd); if (fd == NULL) { error("Warning: Image %s: CreateFromPng(%s) failed!", Name, Image->file); return; } /* maybe resize bitmap */ if (gdImage->sx > Image->width) { Image->width = gdImage->sx; if (Image->bitmap) free(Image->bitmap); Image->bitmap = NULL; } if (gdImage->sy > Image->height) { Image->height = gdImage->sy; if (Image->bitmap) free(Image->bitmap); Image->bitmap = NULL; } if (Image->bitmap == NULL && Image->width > 0 && Image->height > 0) { int i = Image->width * Image->height * sizeof(Image->bitmap[0]); Image->bitmap = malloc(i); if (Image->bitmap == NULL) { error("Warning: Image %s: malloc(%d) failed!", Name, i, strerror(errno)); return; } for (i = 0; i < Image->height * Image->width; i++) { RGBA empty = { R: 0x00, G: 0x00, B: 0x00, A:0x00 }; Image->bitmap[i] = empty; } } /* finally really render it */ if (Image->visible) { for (x = 0; x < gdImage->sx; x++) { for (y = 0; y < gdImage->sy; y++) { int p = gdImageGetTrueColorPixel(gdImage, x, y); int a = gdTrueColorGetAlpha(p); int i = y * Image->width + x; Image->bitmap[i].R = gdTrueColorGetRed(p); Image->bitmap[i].G = gdTrueColorGetGreen(p); Image->bitmap[i].B = gdTrueColorGetBlue(p); /* GD's alpha is 0 (opaque) to 127 (tranparanet) */ /* our alpha is 0 (transparent) to 255 (opaque) */ Image->bitmap[i].A = (a == 127) ? 0 : 255 - 2 * a; if (Image->inverted) { Image->bitmap[i].R = 255 - Image->bitmap[i].R; Image->bitmap[i].G = 255 - Image->bitmap[i].G; Image->bitmap[i].B = 255 - Image->bitmap[i].B; } } } } } static void widget_image_update(void *Self) { WIDGET *W = (WIDGET *) Self; WIDGET_IMAGE *Image = W->data; RESULT result = { 0, 0, 0, NULL }; /* process the parent only */ if (W->parent == NULL) { /* evaluate expressions */ if (Image->file) { free(Image->file); Image->file = NULL; } if (Image->file_tree != NULL) { Eval(Image->file_tree, &result); Image->file = strdup(R2S(&result)); DelResult(&result); } Image->update = 0; if (Image->update_tree != NULL) { Eval(Image->update_tree, &result); Image->update = R2N(&result); if (Image->update < 0) Image->update = 0; DelResult(&result); } Image->visible = 1; if (Image->visible_tree != NULL) { Eval(Image->visible_tree, &result); Image->visible = R2N(&result); Image->visible = Image->visible > 0; DelResult(&result); } Image->inverted = 0; if (Image->inverted_tree != NULL) { Eval(Image->inverted_tree, &result); Image->inverted = R2N(&result); Image->inverted = Image->inverted > 0; DelResult(&result); } /* render image into bitmap */ wid
/* $Id$
 * $URL$
 *
 * plugin for statfs() syscall
 *
 * Copyright (C) 2005 Michael Reinelt <michael@reinelt.co.at>
 * Copyright (C) 2005 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
 *
 * This file is part of LCD4Linux.
 *
 * LCD4Linux 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, or (at your option)
 * any later version.
 *
 * LCD4Linux 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.
 *
 */

/* 
 * exported functions:
 *
 * int plugin_init_statfs (void)
 *  adds statfs() functions
 *
 */


#include "config.h"

#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/vfs.h>

#include "debug.h"
#include "plugin.h"



static void my_statfs(RESULT * result, RESULT * arg1, RESULT * arg2)
{
    struct statfs buf;
    char *path, *key;
    double value;

    path = R2S(arg1);
    key = R2S(arg2);

    if (statfs(path, &buf) != 0) {
	error("statfs(%s) failed: %s", path, strerror(errno));
	SetResult(&result, R_STRING, "");
	return;
    }

    if (strcasecmp(key, "type") == 0) {
	value = buf.f_type;
    } else if (strcasecmp(key, "bsize") == 0) {
	value = buf.f_bsize;
    } else if (strcasecmp(key, "blocks") == 0) {
	value = buf.f_blocks;
    } else if (strcasecmp(key, "bfree") == 0) {
	value = buf.f_bfree;
    } else if (strcasecmp(key, "bavail") == 0) {
	value = buf.f_bavail;
    } else if (strcasecmp(key, "files") == 0) {
	value = buf.f_files;
    } else if (strcasecmp(key, "ffree") == 0) {
	value = buf.f_ffree;
#if 0
    } else if (strcasecmp(key, "fsid") == 0) {
	value = buf.f_fsid;
#endif
    } else if (strcasecmp(key, "namelen") == 0) {
	value = buf.f_namelen;
    } else {
	error("statfs: unknown field '%s'", key);
	value = -1;
    }

    SetResult(&result, R_NUMBER, &value);
}


int plugin_init_statfs(void)
{
    AddFunction("statfs", 2, my_statfs);
    return 0;
}

void plugin_exit_statfs(void)
{
}