Path: | icdoc!ukc!mcsun!uunet!allbery |
From: | dds@cc.ic.ac.uk (Diomidis Spinellis) |
Newsgroups: | comp.sources.misc |
Subject: | v13i048: Image compression using delta modulation |
Message-ID: | <93335@uunet.UU.NET> |
Date: | 15 Jun 90 22:59:49 GMT |
Sender: | allbery@uunet.UU.NET |
Lines: | 351 |
Approved: | allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) |
Content-Length: | 9462 |
Posting-number: Volume 13, Issue 48
Submitted-by: dds@cc.ic.ac.uk (Diomidis Spinellis)
Archive-name: deltac/part01
These programs compress and uncompress 8 bit image files using delta
modulation. The compressed file contains the difference of each byte
from the previous one, coded in a single nibble. The programs achieve
around 20% higher compression rates than /usr/ucb/compress on 8 bit
gray scale facesaver images.
--
Diomidis Spinellis Internet: dds@cc.ic.ac.uk
Department of Computing UUCP: ...!ukc!iccc!dds
Imperial College JANET: dds@uk.ac.ic.cc
London SW7 2BZ #include "/dev/tty"
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: README deltac.l deltac.c deltau.c Makefile
# Wrapped by dds@sunb on Fri Jun 8 22:18:42 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(480 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XThese programs compress and uncompress 8 bit image files using delta
Xmodulation. The compressed file contains the difference of each byte
Xfrom the previous one, coded in a single nibble. I tried the delta
Xmodulation programs, compress and pack on a 256 * 256 * 8 gray scale
Xpicture of me. The results were the following:
X
XOriginal 65536
X/bin/pack 59660
X/usr/ucb/compress 53510
Xdeltac 40489
X
XDiomidis Spinellis <dds@cc.ic.ac.uk>
XMyrsinis 1
XGR-145 62 Kifissia
XGREECE
END_OF_FILE
if test 480 -ne `wc -c <'README'`; then
echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'deltac.l' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'deltac.l'\"
else
echo shar: Extracting \"'deltac.l'\" \(1531 characters\)
sed "s/^X//" >'deltac.l' <<'END_OF_FILE'
X.\" Deltac deltau
X.\"
X.\" Permission to use, copy, and distribute this software and its
X.\" documentation for any purpose and without fee is hereby granted,
X.\" provided that the above copyright notice appear in all copies and that
X.\" both that copyright notice and this permission notice appear in
X.\" supporting documentation.
X.\"
X.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
X.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
X.\" MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X.\"
X.TH DELTAC L "7 June 1990"
X.SH NAME
Xdeltac, deltau \- compress and expand using delta modulation
X.SH SYNOPSIS
X.B deltac
X.IR no options
X.LP
X.B deltau
X.IR no options
X.SH DESCRIPTION
X.B Deltac
Xcompresses eight bit data from standard input to the standard output
Xusing delta modulation. Each byte is stored as four bits if the absolute
Xvalue of its difference from a running value is less than 8.
XThis technique has proven to be more effective than \fIcompress(1)\fP
Xor \fIpack(1)\fP for 8 bit grey level graphics images. It could also
Xwork on 24 bit colour images if each plane is stored separately. For
Xany other data the size will probably increase.
X.LP
X.B Deltau
Xreads data compressed produced by
X.B deltac
Xfrom the standard input and outputs the uncompressed data on
Xstandard output.
X.SH DIAGNOSTICS
XBoth programs will terminate with an error if they fail on writing
Xon standard output.
X.SH AUTHOR
XDiomidis Spinellis <dds@cc.ic.ac.uk>
X.SH "SEE ALSO"
X.BR compress (1)
X.BR pack (1)
END_OF_FILE
if test 1531 -ne `wc -c <'deltac.l'`; then
echo shar: \"'deltac.l'\" unpacked with wrong size!
fi
# end of 'deltac.l'
fi
if test -f 'deltac.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'deltac.c'\"
else
echo shar: Extracting \"'deltac.c'\" \(1745 characters\)
sed "s/^X//" >'deltac.c' <<'END_OF_FILE'
X/*
X * Delta modulation uncompress
X *
X * (C) Copyright 1989, 1990 Diomidis Spinellis. All rights reserved.
X *
X * $Header: deltac.c,v 1.1 90/06/08 22:13:42 dds Rel $
X *
X * Permission to use, copy, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted,
X * provided that the above copyright notice appear in all copies and that
X * both that copyright notice and this permission notice appear in
X * supporting documentation.
X *
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
X * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X *
X */
X
X
X#include <stdio.h>
X
X#ifndef lint
Xstatic char RCSid[] = "$Header: deltac.c,v 1.1 90/06/08 22:13:42 dds Rel $";
X#endif
X
Xstatic prev, stored;
X
X#ifdef SLOW
Xvoid
Xputnib(x)
X int x;
X{
X
X if (stored) {
X if (putchar(prev | (x & 0xf)) == EOF) {
X perror("<stdout>");
X exit(1);
X }
X stored = 0;
X } else {
X prev = x << 4;
X stored = 1;
X }
X}
X#else
X#define putnib(x) \
Xdo { \
X if (stored) { \
X if (putchar(prev | (x & 0xf)) == EOF) { \
X perror("<stdout>"); \
X exit(1); \
X } \
X stored = 0; \
X } else { \
X prev = (x) << 4; \
X stored = 1; \
X } \
X} while(0)
X#endif
X
Xvoid
Xflushnib()
X{
X if (stored)
X if (putchar(prev | 8) == EOF) {
X perror("<stdout>");
X exit(1);
X }
X}
X
X
Xmain(argc, argv)
X int argc;
X char *argv[];
X{
X register c, cp = 256, delta;
X
X if (argc != 1) {
X fprintf(stderr, "%s: usage %s\n", argv[1]);
X exit(1);
X }
X while((c = getchar()) != EOF) {
X delta = c - cp;
X if (delta > 7 || delta < -7) {
X putnib(8);
X putnib(c >> 4);
X putnib(c);
X } else if (delta >= 0)
X putnib(delta);
X else
X putnib(8 | -delta);
X cp = c;
X }
X flushnib();
X}
END_OF_FILE
if test 1745 -ne `wc -c <'deltac.c'`; then
echo shar: \"'deltac.c'\" unpacked with wrong size!
fi
# end of 'deltac.c'
fi
if test -f 'deltau.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'deltau.c'\"
else
echo shar: Extracting \"'deltau.c'\" \(1797 characters\)
sed "s/^X//" >'deltau.c' <<'END_OF_FILE'
X/*
X * Delta modulation uncompress
X *
X * (C) Copyright 1989, 1990 Diomidis Spinellis. All rights reserved.
X *
X * $Header: deltau.c,v 1.1 90/06/08 22:13:50 dds Rel $
X *
X * Permission to use, copy, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted,
X * provided that the above copyright notice appear in all copies and that
X * both that copyright notice and this permission notice appear in
X * supporting documentation.
X *
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
X * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X *
X */
X
X#include <stdio.h>
X
X#ifndef lint
Xstatic char RCSid[] = "$Header: deltau.c,v 1.1 90/06/08 22:13:50 dds Rel $";
X#endif
X
Xstatic prev, stored;
X
X#ifdef SLOW
Xint
Xgetnib()
X{
X if (stored) {
X stored = 0;
X return prev & 0xf;
X } else {
X if ((prev = getchar()) == EOF)
X exit(0);
X else {
X stored = 1;
X return prev >> 4;
X }
X }
X}
X#else
X#define getnib() \
X( \
X (stored) ? ( \
X stored = 0, \
X prev & 0xf \
X ) : ( \
X ((prev = getchar()) == EOF) ? \
X exit(0) \
X : ( \
X stored = 1, \
X prev >> 4 \
X ) \
X ) \
X)
X#endif
X
Xmain(argc, argv)
X int argc;
X char *argv[];
X{
X register c, cn;
X
X if (argc != 1) {
X fprintf(stderr, "%s: usage %s\n", argv[1]);
X exit(1);
X }
X for(;;) {
X switch (c = getnib()) {
X case 8:
X /* Change code */
X cn = getnib() << 4;
X cn |= getnib();
X break;
X case 0:
X /* No change */
X break;
X case 1: case 2: case 3: case 4: case 5: case 6: case 7:
X /* Delta is +ve */
X cn += c;
X break;
X case 9: case 10: case 11: case 12: case 13: case 14: case 15:
X /* Delta is -ve */
X cn -= c & 7;
X break;
X }
X if (putchar(cn) == EOF) {
X perror("<stdout>");
X exit(1);
X }
X }
X}
END_OF_FILE
if test 1797 -ne `wc -c <'deltau.c'`; then
echo shar: \"'deltau.c'\" unpacked with wrong size!
fi
# end of 'deltau.c'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(285 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
XCFLAGS=-O
X
Xall: deltac deltau
X
Xdeltac: deltac.c
X $(CC) $(CFLAGS) deltac.c -o deltac
X
Xdeltau: deltau.c
X $(CC) $(CFLAGS) deltau.c -o deltau
X
Xshar:
X shar README deltac.l deltac.c deltau.c Makefile >shar.out
X
Xtest:
X deltac <deltac.c | deltau | diff - deltac.c
X
Xclean:
X rm -f deltac deltau
END_OF_FILE
if test 285 -ne `wc -c <'Makefile'`; then
echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
echo shar: End of shell archive.
exit 0
Newsgroup comp.sources.misc contents
Newsgroup list
Diomidis Spinellis home page
Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-Share Alike 3.0 Greece License.