Commit a766a5b4 authored by Manish Singh's avatar Manish Singh

How did this stay in here? Must be them there cvs ghosts.

-Yosh
parent ff23a232
......@@ -396,7 +396,6 @@ plug-ins/colorify/Makefile
plug-ins/papertile/Makefile
plug-ins/illusion/Makefile
plug-ins/fractaltrace/Makefile
plug-ins/fs/Makefile
plug-ins/flarefx/Makefile
plug-ins/webbrowser/Makefile
app/Makefile
......
Makefile.in
Makefile
.deps
_libs
.libs
fs
fs2pgm
## Process this file with automake to produce Makefile.in
pluginlibdir = $(gimpplugindir)/plug-ins
pluginlib_PROGRAMS = #STD#
#STD#_SOURCES = \
#STD#.c
INCLUDES = \
$(X_CFLAGS) \
-I$(top_srcdir) \
-I$(includedir)
LDADD = \
$(top_builddir)/libgimp/libgimpui.la \
$(top_builddir)/libgimp/libgimp.la \
$(X_LIBS) \
-lc
DEPS = \
$(top_builddir)/libgimp/libgimpui.la \
$(top_builddir)/libgimp/libgimp.la
#STD#_DEPENDENCIES = $(DEPS)
.PHONY: files
files:
@files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \
echo $$p; \
done
@for subdir in $(SUBDIRS); do \
files=`cd $$subdir; $(MAKE) files | grep -v "make\[[1-9]\]"`; \
for file in $$files; do \
echo $$subdir/$$file; \
done; \
done
CC = gcc
CFLAGS = -g -O2 -Wall
LDFLAGS = -g
LDLIBS = -L/usr/X11R6/lib -lgimp -lgtk -lgdk -lglib -lXext -lX11 -lm
fs: fs.o
install: fs
cp fs $(HOME)/.gimp/plug-ins/fs
clean:
$(RM) *.o core *~
fs2pgm: fs2pgm.o
$(CC) -g -o $@ $<
\ No newline at end of file
Add all the autoconfig/automake stuff, so that the standard build
procedures and such can be used.
Figure out why the fs executable is as large as it is, and fix it,
unless the automake fix cures this as well.
Handle non-square pixels properly. If px!=ix or py!=iy, there should
be an option to correct the display. I'm not sure whether this
correction should be on or off by default. Turning it on loses
information; leaving it off distorts the image display. Sigh,
decisions, decisions...
Save header lines on input so that they can be restored on output.
The "Image:" line will have to be special cased, depending on what
gets done about non-square pixels. All other lines can just be cached
on input and restored on output.
Write some help information.
From: lou@usenix.UUCP (Lou Katz)
Newsgroups: comp.graphics
Subject: FaceSaver format Revealed
Message-ID: <312@usenix.UUCP>
Date: 16 Jan 90 08:02:52 GMT
Reply-To: lou@usenix.UUCP (Lou Katz)
Organization: USENIX Association, Berkeley, CA
Lines: 41
Format of pictures is:
An ASCII file containing some or all of the following lines:
FirstName:
LastName:
E-mail:
Telephone:
Company:
Address1:
Address2:
CityStateZip:
Date:
PicData: Actual data: width - height - bits/pixel
Image: Should be transformed to: width - height - bits/pixel
(A REQUIRED Blank line)
Hexified picture in scanline order, in the form suitable for
printing in postscript. It is unpadded scanlines, I believe left to right.
If it is bottom to top it is due to funny transforms in going from the real
scanned image, which came from a video camera turned on its side! (to get a
portrait aspect ratio).
All the images are 8 bits per pixel, and have been intensity levelled to
use up the full dynamic range (each pixel multiplied by 256/(max - min) and
shifted so that min becomes zero).
I'm sorry about that, I should have put out untransformed data.
The original frame grabbing was off a Targa M8, and the gamma varied due
to a number of real world factors. Most pictures had a dynamic range in
the 128 - 196 vicinity.
The line labeled Image: can be used to correct for non-square pixels.
In most cases, there are 108 (non-square) pixels across in the data, but they
would have been 96 pixels across if they were square. Therefore,
Image: says 96, PicData says 108.
Lou Katz
Saver of Lost Faces
lou@usenix.org
(415) 530-8870
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
* Face saver reading and writing code Copyright 1998 by John Kodis
*
* 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.
*/
/*
* fs.c -- a facesaver/faceserver plugin for the gimp. Developed by
* John Kodis, Dec 1997. Bug reports are welcomed at kodis@jagunet.com
*
* Based on HRZ code by Albert Cahalan <acahalan at cs.uml.edu>,
* which was in turn based on PNM code by Erik Nygren (nygren@mit.edu).
*/
#include <string.h>
#include "gtk/gtk.h"
#include "libgimp/gimp.h"
static int save_okay = FALSE;
static void query()
{
static GParamDef load_args[] =
{
{ PARAM_INT32, "run_mode", "Interactive, non-interactive" },
{ PARAM_STRING, "filename", "The name of the file to load" },
{ PARAM_STRING, "raw_filename", "The name of the file to load" },
};
static int nload_args = sizeof (load_args) / sizeof (load_args[0]);
static GParamDef load_return_vals[] =
{
{ PARAM_IMAGE, "image", "Output image" },
};
static int nload_return_vals =
sizeof(load_return_vals) / sizeof(*load_return_vals);
static GParamDef save_args[] =
{
{ PARAM_INT32, "run_mode", "Interactive, non-interactive" },
{ PARAM_IMAGE, "image", "Input image" },
{ PARAM_DRAWABLE, "drawable", "Drawable to save" },
{ PARAM_STRING, "filename", "Name of the file to save the image in" },
{ PARAM_STRING, "raw_filename", "Name of the file to save the image in" }
};
static int nsave_args = sizeof (save_args) / sizeof (save_args[0]);
gimp_install_procedure(
"file_fs_load",
"loads files in face saver file format",
"FIXME: write help for file_fs_load",
"John Kodis", "John Kodis", "1997",
"<Load>/FS",
NULL, PROC_PLUG_IN,
nload_args, nload_return_vals,
load_args, load_return_vals);
gimp_install_procedure(
"file_fs_save",
"saves files in face saver file format",
"saves a grayscale image in facesaver format",
"John Kodis", "John Kodis", "1997",
"<Save>/FS",
"GRAY*", PROC_PLUG_IN,
nsave_args, 0,
save_args, NULL);
gimp_register_magic_load_handler(
"file_fs_load", "fs", "", "");
gimp_register_save_handler(
"file_fs_save", "fs", "");
}
typedef struct
{
int ix, iy, iz;
int px, py, pz;
char *emsg;
unsigned char *pixmap;
}
Fs_info;
static Fs_info *fs_alloc(void)
{
Fs_info *fs = g_malloc(sizeof(*fs));
fs->emsg = g_malloc(FILENAME_MAX + 100);
*fs->emsg = '\0';
fs->pixmap = NULL;
fs->ix = fs->iy = fs->iz = fs->px = fs->py = fs->pz = 0;
return fs;
}
static void fs_free(Fs_info *fs)
{
if (fs)
{
if (fs->emsg) g_free(fs->emsg);
if (fs->pixmap) g_free(fs->pixmap);
g_free(fs);
}
}
static int fs_ingest(char *fn, Fs_info *fs)
{
FILE *ifd = fopen(fn, "r");
if (ifd == NULL)
sprintf(fs->emsg, "can't open file \"%s\"", fn);
else
{
int body = FALSE;
char buf[1000];
while (!body && fgets(buf, sizeof(buf), ifd))
if (strncasecmp(buf, "picdata:", 8) == 0)
sscanf(buf+8, "%d %d %d", &fs->px, &fs->py, &fs->pz);
else if (strncasecmp(buf, "image:", 6) == 0)
sscanf(buf+6, "%d %d %d", &fs->ix, &fs->iy, &fs->iz);
else if (buf[strspn(buf, " \t\n")] == '\0')
body = TRUE;
if (!body)
sprintf(fs->emsg, "%s: missing body", fn);
else if (!fs->pz)
sprintf(fs->emsg, "%s: bad or missing picdata line", fn);
#ifdef REQUIRE_IMAGE_LINE
else if (!fs->iz)
sprintf(fs->emsg, "%s: bad or missing image line", fn);
#endif
else
{
char *pix_x0;
int x, y, pixval, pixno = 0, pixcnt = fs->px * fs->py;
fs->pixmap = g_malloc(pixcnt + 1);
pix_x0 = fs->pixmap + pixcnt;
for (y=0; y<fs->py; y++)
{
char *pix = (pix_x0 -= fs->px);
for (x=0; x<fs->px; x++)
if (pixno++ < pixcnt && fscanf(ifd, "%2x", &pixval) == 1)
*pix++ = pixval & 0xff;
else
{
sprintf(fs->emsg, "%s: eof at %d of %d (%dx%d) pixels",
fn, pixno, pixcnt, fs->px, fs->py);
return FALSE;
}
}
}
}
return !*fs->emsg;
}
static gint32 load_image(char *filename)
{
char *loading;
gint32 image_id, layer_id;
GDrawable *drawable;
GPixelRgn pixel_rgn;
Fs_info *fs = fs_alloc();
loading = g_malloc(strlen(filename) + 11);
sprintf(loading, "Loading %s:", filename);
gimp_progress_init(loading);
g_free(loading);
gimp_progress_update(0.25);
if (!fs_ingest(filename, fs))
{
fprintf(stderr, "fs_load: %s\n", fs->emsg);
fs_free(fs);
return -1;
}
/* Create new image of proper size and associate filename; create
and add a new layer to the image, and get a drawable; finally,
initialize the drawing region. */
gimp_progress_update(0.50);
image_id = gimp_image_new(fs->px, fs->py, GRAY);
gimp_image_set_filename(image_id, filename);
layer_id = gimp_layer_new(image_id, "Background",
fs->px, fs->py, GRAY_IMAGE, 100, NORMAL_MODE);
gimp_image_add_layer(image_id, layer_id, 0);
drawable = gimp_drawable_get(layer_id);
gimp_pixel_rgn_init(&pixel_rgn, drawable, 0, 0,
drawable->width, drawable->height, TRUE, FALSE);
/* Transfer the pixel buffer into the image layer. */
gimp_progress_update(0.75);
gimp_pixel_rgn_set_rect(&pixel_rgn, fs->pixmap, 0,0, fs->px, fs->py);
/* Lastly, display the image and return. */
gimp_progress_update(1.00);
gimp_drawable_flush(drawable);
return image_id;
}
static void save_close_callback(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}
static void save_ok_callback(GtkWidget *widget, gpointer data)
{
gtk_widget_destroy(GTK_WIDGET(data));
save_okay = TRUE;
}
static gint save_image(char *filename, gint32 image_id, gint32 drawable_id)
{
GPixelRgn pixel_rgn;
GDrawable *drawable;
FILE *fd;
int x, y, w, h;
char *saving, *pixbuf, *pix_x0;
drawable = gimp_drawable_get(drawable_id);
w = drawable->width;
h = drawable->height;
gimp_pixel_rgn_init(&pixel_rgn, drawable, 0, 0, w, h, FALSE, FALSE);
if (gimp_drawable_has_alpha(drawable_id))
{
fprintf(stderr, "fs: can't save images with alpha channels.");
return FALSE;
}
if (gimp_drawable_type(drawable_id) != GRAY_IMAGE)
{
fprintf(stderr, "fs: image must be grayscale for facesaver format\n");
return FALSE;
}
if ((fd = fopen(filename, "w")) == NULL)
{
fprintf(stderr, "fs: can't open \"%s\"\n", filename);
return FALSE;
}
saving = g_malloc(strlen(filename) + 11);
sprintf(saving, "Saving %s:", filename);
gimp_progress_init(saving);
g_free(saving);
fprintf(fd, "Picdata: %d %d %d\n", w, h, drawable->bpp * 8);
fprintf(fd, "Image: %d %d %d\n", w, h, drawable->bpp * 8);
gimp_progress_update(0.25);
pixbuf = g_malloc(w * h);
gimp_pixel_rgn_get_rect(&pixel_rgn, pixbuf, 0, 0, w, h);
gimp_progress_update(0.50);
pix_x0 = pixbuf + w*h;
for (y=0; y<h; y++)
{
unsigned char *pix = (pix_x0 -= w);
for (x=0; x<w; x++)
{
if ((x%27) == 0) fprintf(fd, "\n");
fprintf(fd, "%02x", *pix++);
}
}
fprintf(fd, "\n");
fclose(fd);
g_free(pixbuf);
gimp_drawable_detach(drawable);
return TRUE;
}
static gint save_dialog(void)
{
GtkWidget *dlg;
GtkWidget *button;
gint argc = 1;
gchar **argv = g_new(gchar*, 1);
argv[0] = g_strdup("save");
gtk_init(&argc, &argv);
gtk_rc_parse(gimp_gtkrc());
dlg = gtk_dialog_new();
gtk_window_set_title(GTK_WINDOW(dlg), "Save as facesaver file");
gtk_window_position(GTK_WINDOW(dlg), GTK_WIN_POS_MOUSE);
gtk_signal_connect(GTK_OBJECT(dlg), "destroy",
(GtkSignalFunc)save_close_callback, NULL);
button = gtk_button_new_with_label("Okay");
GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
gtk_signal_connect(GTK_OBJECT(button), "clicked",
(GtkSignalFunc)save_ok_callback, dlg);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->action_area),
button, TRUE, TRUE, 0);
gtk_widget_grab_default(button);
gtk_widget_show(button);
button = gtk_button_new_with_label("Cancel");
GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
(GtkSignalFunc)gtk_widget_destroy, GTK_OBJECT(dlg));
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->action_area),
button, TRUE, TRUE, 0);
gtk_widget_show(button);
gtk_widget_show(dlg);
gtk_main();
gdk_flush();
return save_okay; /* Initially false; true after clicking on "Okay" */
}
static void
run(char *name, int params, GParam *param, int *rvals, GParam **rval)
{
static GParam values[2];
values[0].type = PARAM_STATUS;
values[0].data.d_status = STATUS_SUCCESS;
*rvals = 1;
*rval = values;
if (strcmp(name, "file_fs_load") == 0)
{
gint32 image_id = load_image(param[1].data.d_string);
if (image_id == -1)
values[0].data.d_status = STATUS_EXECUTION_ERROR;
else
{
*rvals = 2;
values[1].type = PARAM_IMAGE;
values[1].data.d_image = image_id;
}
}
else if (strcmp(name, "file_fs_save") == 0)
{
GRunModeType mode = param[0].data.d_int32;
if (mode == RUN_NONINTERACTIVE && params != 4)
values[0].data.d_status = STATUS_CALLING_ERROR;
else if ((mode == RUN_WITH_LAST_VALS) ||
(mode == RUN_INTERACTIVE && save_dialog()) )
{
char *filename = param[3].data.d_string;
gint32 image_id = param[1].data.d_int32;
gint32 drawable_id = param[2].data.d_int32;
if (!save_image(filename, image_id, drawable_id))
values[0].data.d_status = STATUS_EXECUTION_ERROR;
}
}
else
values[0].data.d_status = STATUS_CALLING_ERROR;
}
GPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
MAIN()
/*
* fs2pgm.c -- converts a face-saver image to a portable graymap image.
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int errors;
static char *progname;
static void error(char *fmt, ...)
{
va_list ap;
fprintf(stderr, "%s: ", progname);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
errors++;
}
int main(int argc, char **argv)
{
int arg;
progname = strrchr(argv[0], '/') ? strrchr(argv[0], '/')+1 : argv[0];
for (arg=1; arg<argc; arg++)
{
FILE *ifd = fopen(argv[arg], "r");
if (ifd == NULL)
error("can't open file \"%s\"\n", argv[arg]);
else
{
char buf[1000];
int body=0, ix=0, iy=0, iz=0, px=0, py=0, pz=0;
while (!body && fgets(buf, sizeof(buf), ifd))
if (strncasecmp(buf, "picdata:", 8) == 0)
sscanf(buf+8, "%d %d %d", &px, &py, &pz);
else if (strncasecmp(buf, "image:", 6) == 0)
sscanf(buf+6, "%d %d %d", &ix, &iy, &iz);
else if (buf[strspn(buf, " \t\n")] == '\0')
body = 1;
if (!body) error("%s: missing body\n", argv[arg]);
else if (!pz) error("%s: missing or short pixdata\n", argv[arg]);
else if (!iz) error("%s: missing or short image\n", argv[arg]);
else
{
int pixval, pixno=0;
char *pixmap = malloc(px*py+1);
while (fscanf(ifd, "%2x", &pixval) == 1)
{
pixmap[pixno] = pixval & 0xff;
pixno++;
}
if (0)
fprintf(stderr, "%3d %3d %3d %3d %3d %3d %5d\n", // argv[arg],
ix, iy, iz, px, py, pz, pixno);
if (pixno != px*py)
error("%s: expected %d (%dx%d) pixels, found %d%s\n",
argv[arg], px*py, px, py, pixno,
pixno<px*py ? "." : " or more." );
else
{
FILE *ofd;
char *ofn = malloc(strlen(argv[arg])+10);
strcpy(ofn, argv[arg]);
if (strrchr(ofn, '.') > strrchr(ofn, '/'))
*strrchr(ofn, '.') = '\0';
strcat(ofn, ".pgm");
if ((ofd=fopen(ofn, "w")) == NULL)
error("%s: can't open output file \"%s\"\n",
argv[arg], ofn);
else
{
int x, y;
fprintf(ofd, "P5\n%d %d\n%d\n", px, py, 255);
for (y=0; y<py; y++)
for (x=0; x<px; x++)
fputc(pixmap[(py-y)*px + x], ofd);
}
free(ofn);
}
free(pixmap);
}
}
}
return errors ? EXIT_FAILURE : EXIT_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment