/* * Copyright (c) 1998 by Tsuyoshi Iguchi (zinnia@risky-safety.org) * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id$ */ /* * downsample.c -- downsampling */ #include #include #include #include #include #include #define DOWNSAMPLE 4 typedef unsigned long dword; typedef unsigned short word; typedef unsigned char byte; int filesize(char* filename) { struct stat filestat; stat(filename, &filestat); return filestat.st_size; } int main(int argc, char** argv) { FILE* fpin; char** p; char* filename; unsigned char* rusterx; char* datap; char* data; int i, r, j; int srcx, srcy; fpin = NULL; for(p = argv + 1; *p;){ if(fpin == NULL){ fpin = fopen(*p, "r"); if(fpin == NULL){ fprintf(stderr, "%s: open error.\n", *p); return -1; } filename = strdup(*p); } p++; } if(fpin == NULL){ fprintf(stderr, "No input files.\n"); return 1; } srcx = srcy = sqrt(filesize(filename)); data = (char*)calloc(srcx * srcy, 1); if(data == NULL){ fprintf(stderr, "Memory allocation error.\n"); return -1; } rusterx = (unsigned char*)calloc(srcx, 1); if(rusterx == NULL){ fprintf(stderr, "Memory allocation error.\n"); return -1; } datap = data; while(!feof(fpin)){ for(j = 0; j < DOWNSAMPLE; j++){ fread(rusterx, 1, srcx, fpin); } for(j = 0; j < srcx; j+=DOWNSAMPLE){ fprintf(stdout, "%c", rusterx[j]); } } return 0; }