/* The GIMP -- an image manipulation program * Copyright (C) 1995 Spencer Kimball and Peter Mattis * * Plugin to load SCR (Sinclair ZX Spectrum screenshot) files. * (C) 2000 Adam D. Moss * * v1.01 - by Adam D. Moss, adam@gimp.org, adam@foxbox.org * * 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. */ /* * Changelog: * * 2000-08-07 * v1.01: I18N cruft removed, shouldn't have been there and * was causing failed compilation. [Adam] * * 2000-07-21 * v1.0: Initial release. [Adam] */ /* * TODO: * * Load SCR files with hardware-flash attributes as animated-layers. * * Should really read as an INDEXED image, not an RGB image. * * Check that file length is exactly 6912 bytes for a valid file. * * Do something about (understandably) no-one remotely agreeing on the * RGB values corresponding to the ZX Spectrum's fixed TV palette signals. * Currently using the palette from the mighty Spectemu which most pleases * my eye. * * Saving. I have a RGB->SCR saver already written and it works just fine * thankyouverymuch and no it's not release-happy yet! */ /*#include "config.h"*/ #include #include #include #include #include /*#include "libgimp/stdplugins-intl.h"*/ static void query (void); static void run (gchar *name, gint nparams, GimpParam *param, gint *nreturn_vals, GimpParam **return_vals); static gint32 load_image (char *filename); GimpPlugInInfo PLUG_IN_INFO = { NULL, /* init_proc */ NULL, /* quit_proc */ query, /* query_proc */ run, /* run_proc */ }; MAIN () static void query (void) { static GimpParamDef load_args[] = { { GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" }, { GIMP_PDB_STRING, "filename", "The name of the file to load" }, { GIMP_PDB_STRING, "raw_filename", "The name entered" } }; static GimpParamDef load_return_vals[] = { { GIMP_PDB_IMAGE, "image", "Output image" } }; static gint nload_args = sizeof (load_args) / sizeof (load_args[0]); static gint nload_return_vals = (sizeof (load_return_vals) / sizeof (load_return_vals[0])); gimp_install_procedure ("file_scr_load", "Loads Sinclair ZX Spectrum screenshot files", "This plugin loads the defacto standard Sinclair ZX Spectrum screenshot file format (SCR). This is simply a dump of Spectrum screen memory (6912 bytes worth).", "Adam D. Moss", "Adam D. Moss", "2000", "/scr", NULL, GIMP_PLUGIN, nload_args, nload_return_vals, load_args, load_return_vals); gimp_register_load_handler ("file_scr_load", "scr", ""); } static void run (gchar *name, gint nparams, GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[2]; GimpRunModeType run_mode; GimpPDBStatusType status = GIMP_PDB_SUCCESS; gint32 image_ID; run_mode = param[0].data.d_int32; *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; /* INIT_I18N(); */ if (strcmp (name, "file_scr_load") == 0) { image_ID = load_image (param[1].data.d_string); if (image_ID != -1) { *nreturn_vals = 2; values[1].type = GIMP_PDB_IMAGE; values[1].data.d_image = image_ID; } else { status = GIMP_PDB_EXECUTION_ERROR; } } else { status = GIMP_PDB_CALLING_ERROR; } values[0].data.d_status = status; } /***********************************************/ static const struct { unsigned char r; unsigned char g; unsigned char b; } SpecColourDef[16] = { /* spectemu colours */ { 0, 0, 0}, { 16, 16, 210}, {210, 16, 16}, {210, 16, 210}, { 16, 210, 16}, { 16, 210, 210}, {210, 210, 16}, {210, 210, 210}, { 0, 0, 0}, { 32, 32, 255}, {255, 32, 32}, {255, 32, 255}, { 32, 255, 32}, { 32, 255, 255}, {255, 255, 32}, {255, 255, 255} }; static const int linearize(int y) { if (y<64) return y/8 + (y%8)*8; if (y<128) { y -= 64; return (y/8 + (y%8)*8) + 64; } y -= 128; return (y/8 + (y%8)*8) + 128; } static gint32 load_image (gchar *filename) { GimpPixelRgn pixel_rgn; GimpDrawable *drawable; gint32 image_ID; gint32 layer_ID; gint x, y; FILE *fp; guchar specmem[6912]; guchar rgb[192][256][3]; gchar *layername; /* FIXME? */ fp = fopen(filename,"rb"); if (fp == NULL) { fprintf (stderr, "scr: fopen failed\n"); exit (4); } if (6912 != fread(specmem, 1, 6912, fp)) g_warning("Short read on SCR file"); fclose(fp); /* the 'hard' work. */ { for (y=0; y<192; y++) { for (x=0; x<256; x++) { int bit; int attr; int fg, bg; bit = specmem[linearize(y)*32 + x/8] & (128 >> (x&7)) ? 1 : 0; attr = specmem[32*192 + (y/8)*32 + x/8]; fg = (attr&7) | ((attr&64) >> 3); bg = ((attr&(7 << 3)) >> 3) | ((attr&64) >> 3); if (bit) { rgb[y][x][0] = SpecColourDef[fg].r; rgb[y][x][1] = SpecColourDef[fg].g; rgb[y][x][2] = SpecColourDef[fg].b; } else { rgb[y][x][0] = SpecColourDef[bg].r; rgb[y][x][1] = SpecColourDef[bg].g; rgb[y][x][2] = SpecColourDef[bg].b; } } } } image_ID = gimp_image_new (256, 192, GIMP_RGB); gimp_image_set_filename (image_ID, filename); layername = g_strdup( "screenshot" ); layer_ID = gimp_layer_new (image_ID, layername, 256, 192, GIMP_RGB_IMAGE, 100, GIMP_NORMAL_MODE); g_free(layername); 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); gimp_pixel_rgn_set_rect (&pixel_rgn, &rgb[0][0][0], 0, 0, 256, 192); gimp_drawable_flush (drawable); gimp_drawable_detach (drawable); return image_ID; }