/* SCCS-info %W% %E% */ /*--------------------------------------------------------------------*/ /* */ /* VCG : Visualization of Compiler Graphs */ /* -------------------------------------- */ /* */ /* file: pbmshift.c */ /* version: 1.00.00 */ /* creation: 15.11.93 */ /* author: G. Sander (Version 1.00.00-...) */ /* Universitaet des Saarlandes, 66041 Saarbruecken */ /* ESPRIT Project #5399 Compare */ /* description: Shift a pbm-file to the right lower */ /* status: in work */ /* */ /*--------------------------------------------------------------------*/ /* $Id: pbmshift.c,v 1.7 1995/02/08 18:51:51 sander Exp $ */ /* * Copyright (C) 1993-2005 Saarland University * * This program and documentation is free software; you can redistribute * 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. * * The software is available per anonymous ftp at ftp.cs.uni-sb.de. * Contact sander@cs.uni-sb.de for additional information. */ /* $Log: pbmshift.c,v $ * Revision 1.7 1995/02/08 18:51:51 sander * setbit renamed to mysetbit. * * Revision 1.6 1995/02/08 11:21:41 sander * Distribution Version 1.3 * * Revision 1.5 1994/03/02 14:29:05 sander * Gnu License message added. * * Revision 1.4 1994/01/21 20:05:00 sander * Signal handling adapted for Sys V. * Some portability problems solved for Silicon Graphics IRIS and IBM R6000. * * Revision 1.3 1994/01/03 17:43:24 sander * Remarks added. * * Revision 1.2 1993/12/09 13:19:43 sander * Negative shift values allowed. * * Revision 1.1 1993/12/06 11:23:59 sander * Initial revision * */ /*--------------------------------------------------------------------* * There are excellent standard utilities for pbm-Files by Jef Poskanzer. * The reason I wrote this shift utility is that this is much faster * on large files. * * This utility shifts a pbm-P4-file to the right lower corner and produces * a new pbm-P4-file. This utility can be used if the printout of the * pbm-P4-file is to much at the left upper corner. A left and a top * margin are created. Margin values are numbers of pixels. * * Synopsis: pbmshift * * THIS UTILITY DOES NOT WORK WITH THE pbm-P1-format !!! IT IS NOT A * GENERAL CONVERSION UTILITY. *--------------------------------------------------------------------*/ #include #include #include #include "../src/globals.h" /* Prototypes * ---------- */ int main _PP((int argc, char *argv[])); void readpbm _PP((void)); void writepbm _PP((void)); void shiftpbm _PP((void)); void mysetbit _PP((int x,int y,int color)); /* Global Variables * ---------------- */ FILE *f = NULL; char *infile; char *outfile; int topmargin, leftmargin; unsigned char *bitmap1=NULL; unsigned char *bitmap2=NULL; int width1, height1; int width2, height2; #define fatalerror(a,b) { PRINTF("Error: %s %s !\n",a,b); exit(-1); } /*--------------------------------------------------------------------*/ #ifdef ANSI_C int main(int argc, char *argv[]) #else int main(argc, argv) int argc; char *argv[]; #endif { if (argc != 5) { PRINTF("Usage: pbmshift \n"); return(-1); } infile = argv[1]; topmargin = atoi(argv[2]); leftmargin = atoi(argv[3]); outfile = argv[4]; PRINTF("Shift %s by [%d,%d] -> %s\n",infile,topmargin,leftmargin,outfile); readpbm(); shiftpbm(); writepbm(); return(0); } /*--------------------------------------------------------------------*/ /* Read a pbm-file */ /*--------------------------------------------------------------------*/ #ifdef ANSI_C void readpbm(void) #else void readpbm() #endif { int val,i; f = fopen(infile,"r"); if (!f) fatalerror("Cannot open",infile); if (fscanf(f,"P%d",&val)!=1) fatalerror("Format wrong",""); if (val!=4) fatalerror("Format not P4",""); if (fscanf(f,"%d %d",&width1,&height1)!=2) fatalerror("Format wrong",""); if (width1%8) fatalerror("Format wrong",""); /* Allocate bitmap 1 */ bitmap1 = (unsigned char *)malloc(width1/8*(height1+1)); if (!bitmap1) fatalerror("Memory exhausted",""); /* Allocate bitmap 2, where the rotated image comes in */ width2 = width1+leftmargin; height2 = height1+topmargin; width2 = ((width2+7)/8)*8; bitmap2 = (unsigned char *)malloc(width2/8*(height2+1)); if (!bitmap2) fatalerror("Memory exhausted",""); for (i=0; i bitmap2 with topmargin and leftmargin */ /*--------------------------------------------------------------------*/ #ifdef ANSI_C void shiftpbm(void) #else void shiftpbm() #endif { int i,j; unsigned char mbyte; for (i=0; i