From 7336b064653026171a715dfaf803693b638c67a5 Mon Sep 17 00:00:00 2001 From: Gerard Klaver Date: Wed, 30 Apr 2008 10:12:21 +0000 Subject: [PATCH] For Gray mode added time stamp option, remove compiler warning --- src/xcam.c | 77 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 21 deletions(-) diff --git a/src/xcam.c b/src/xcam.c index 61a44e5..796ffad 100644 --- a/src/xcam.c +++ b/src/xcam.c @@ -6,6 +6,8 @@ The add_text routine and font_6x11.h file are taken from the (GPLed) webcam.c file, part of xawtv, (c) 1998-2002 Gerd Knorr. add_text was modified for this program (xcam_add_text). + Update 2008 Gerard Klaver + Added add_text routine to gray images. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -339,6 +341,8 @@ xcam_add_text (SANE_Byte * image, int width, int height, char *txt) int i, x, y, f, len; char fmtstring[25] = " %Y-%m-%d %H:%M:%S"; char fmttxt[46]; + char buf[100]; + DBG (DBG_debug, "xcam_add_text: enter\n"); time (&t); @@ -351,26 +355,56 @@ xcam_add_text (SANE_Byte * image, int width, int height, char *txt) len = strftime (line, MSG_MAXLEN, fmttxt, tm); - for (y = 0; y < CHAR_HEIGHT; y++) + switch (win.params.format) { - ptr = image + 3 * width * (height - CHAR_HEIGHT - 2 + y) + 12; + case SANE_FRAME_RGB: - for (x = 0; x < len; x++) + for (y = 0; y < CHAR_HEIGHT; y++) { - f = fontdata[line[x] * CHAR_HEIGHT + y]; - for (i = CHAR_WIDTH - 1; i >= 0; i--) - { - if (f & (CHAR_START << i)) - { - ptr[0] = 255; - ptr[1] = 255; - ptr[2] = 255; - } - ptr += 3; - } /* for i */ - } /* for x */ - } /* for y */ + ptr = image + 3 * width * (height - CHAR_HEIGHT - 2 + y) + 12; + for (x = 0; x < len; x++) + { + f = fontdata[line[x] * CHAR_HEIGHT + y]; + for (i = CHAR_WIDTH - 1; i >= 0; i--) + { + if (f & (CHAR_START << i)) + { + ptr[0] = 255; + ptr[1] = 255; + ptr[2] = 255; + } + ptr += 3; + } /* for i */ + } /* for x */ + } /* for y */ + break; + case SANE_FRAME_GRAY: + + for (y = 0; y < CHAR_HEIGHT; y++) + { + ptr = image + width * (height - CHAR_HEIGHT - 2 + y) + 12; + + for (x = 0; x < len; x++) + { + f = fontdata[line[x] * CHAR_HEIGHT + y]; + for (i = CHAR_WIDTH - 1; i >= 0; i--) + { + if (f & (CHAR_START << i)) + { + ptr[0] = 255; + } + ptr += 1; + } /* for i */ + } /* for x */ + } /* for y */ + case SANE_FRAME_RED: + case SANE_FRAME_GREEN: + case SANE_FRAME_BLUE: + snprintf (buf, sizeof (buf), + "Time stamp for separate channel transfers are not supported"); + break; + } DBG (DBG_debug, "xcam_add_text: exit vw=%d, vh=%d\n", width, height); status = (SANE_STATUS_GOOD); return status; @@ -572,7 +606,7 @@ prompt_for_device_name (GtkWidget * widget, gpointer data) { GtkWidget *vbox, *hbox, *label, *text; GtkWidget *button, *dialog; - + DBG (DBG_debug, "xcam: prompt_for_device_name: enter\n"); dialog = gtk_window_new (GTK_WINDOW_TOPLEVEL); @@ -700,7 +734,7 @@ static GtkWidget * build_files_menu (void) { GtkWidget *menu, *item; - + DBG (DBG_debug, "xcam: build_files_menu: enter\n"); menu = gtk_menu_new (); @@ -1107,7 +1141,7 @@ input_available (gpointer ignore, gint source, GdkInputCondition cond) (win.fps_old3 + win.fps_old2 + win.fps_old1 + win.fps) / 4; DBG (DBG_debug, - "xcam: input_available fps count=%d, frame_time * 30 = %2.3f, fps=%2.3f, fps_av=%2.3f\n", + "xcam: input_available fps count=%ld, frame_time * 30 = %2.3f, fps=%2.3f, fps_av=%2.3f\n", win.f_count, frame_time, win.fps, win.fps_av); win.i_time = 0; @@ -1287,7 +1321,7 @@ save_frame_button (GtkWidget * widget, gpointer client_data, /* test for pnm formats */ strncpy (testfilename, preferences.filename, sizeof (testfilename)); - testfilename[sizeof (testfilename)] = 0; + testfilename[sizeof (testfilename) - 1] = 0; g_strreverse (testfilename); if (!((!strncmp (testfilename, "mnp.", 4)) || (!strncmp (testfilename, "mgp.", 4)) || @@ -1597,7 +1631,8 @@ main (int argc, char **argv) } } - DBG (DBG_debug, "xcam.main: buf_backend_size 0x%x\n", win.buf_backend_size); + DBG (DBG_debug, "xcam.main: buf_backend_size 0x%x\n", + (unsigned) win.buf_backend_size); win.buf = malloc (win.buf_backend_size);