gpp4
1.3.1
|
00001 /* 00002 pack_c.h: (de)compress diffraction image files 00003 Copyright (C) 1995 Jan P Abrahams 00004 00005 This library is free software: you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation, either 00008 version 3 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with This library. If not, see 00017 <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 00021 00022 /* Some general defines: */ 00023 00024 00025 #define PACKIDENTIFIER "\nCCP4 packed image, X: %04d, Y: %04d\n" 00026 /* This string defines the start of a packed image. An image file is scanned 00027 until this string is encountered, the size of the unpacked image is 00028 determined from the values of X and Y (which are written out as formatted 00029 ascii numbers), and the packed image is expected to start immediately after 00030 the null-character ending the string. */ 00031 00032 #define V2IDENTIFIER "\nCCP4 packed image V2, X: %04d, Y: %04d\n" 00033 /* This string defines the start of a packed image. An image file is scanned 00034 until this string is encountered, the size of the unpacked image is 00035 determined from the values of X and Y (which are written out as formatted 00036 ascii numbers), and the packed image is expected to start immediately after 00037 the null-character ending the string. */ 00038 00039 #define PACKBUFSIZ BUFSIZ 00040 /* Size of internal buffer in which the packed array is stored during transit 00041 form an unpacked image to a packed image on disk. It is set to the size 00042 used by the buffered io-routines given in <stdio.h>, but it could be 00043 anything. */ 00044 00045 #define DIFFBUFSIZ 16384L 00046 /* Size of the internal buffer in which the differences between neighbouring 00047 pixels are stored prior to compression. The image is therefore compressed 00048 in DIFFBUFSIZ chunks. Decompression does not need to know what DIFFBUFSIZ 00049 was when the image was compressed. By increasing this value, the image 00050 can be compressed into a packed image which is a few bytes smaller. Do 00051 not decrease the value of DIFFBUFSIZ below 128L. */ 00052 00053 #define BYTE char 00054 /* BYTE is a one byte integer. */ 00055 00056 #define WORD short int 00057 /* WORD is a two-byte integer. */ 00058 00059 #define LONG int 00060 /* LONG is a four byte integer. */ 00061 /* Dave Love 5/7/94: using `int' gets you 4 bytes on the 32-bit Unix 00062 (and VAX) systems I know of and also on (64-bit) OSF/1 Alphas which 00063 have 64-bit longs. (This definition previously used `long'.) */ 00064 00065 00066 00067 /******************************************************************************/ 00068 00069 /* Some usefull macros used in the code of this sourcefile: */ 00070 00071 00072 #define max(x, y) (((x) > (y)) ? (x) : (y)) 00073 /* Returns maximum of x and y. */ 00074 00075 #define min(x, y) (((x) < (y)) ? (x) : (y)) 00076 /* Returns minimum of x and y. */ 00077 00078 #undef abs /* avoid complaint from DEC C, at least */ 00079 #define abs(x) (((x) < 0) ? (-(x)) : (x)) 00080 /* Returns the absolute value of x. */ 00081 00082 /* Used to be 'static const LONG' but const declaration gives trouble on HPs */ 00083 #ifndef SKIP_SETBITS 00084 static LONG setbits[33] = 00085 {0x00000000L, 0x00000001L, 0x00000003L, 0x00000007L, 00086 0x0000000FL, 0x0000001FL, 0x0000003FL, 0x0000007FL, 00087 0x000000FFL, 0x000001FFL, 0x000003FFL, 0x000007FFL, 00088 0x00000FFFL, 0x00001FFFL, 0x00003FFFL, 0x00007FFFL, 00089 0x0000FFFFL, 0x0001FFFFL, 0x0003FFFFL, 0x0007FFFFL, 00090 0x000FFFFFL, 0x001FFFFFL, 0x003FFFFFL, 0x007FFFFFL, 00091 0x00FFFFFFL, 0x01FFFFFFL, 0x03FFFFFFL, 0x07FFFFFFL, 00092 0x0FFFFFFFL, 0x1FFFFFFFL, 0x3FFFFFFFL, 0x7FFFFFFFL, 00093 0xFFFFFFFFL}; 00094 /* This is not a macro really, but I've included it here anyway. Upon indexing, 00095 it returns a LONG with the lower (index) number of bits set. It is equivalent 00096 to the following macro: 00097 #define setbits(n) (((n) == 32) : ((1L << (n)) - 1) : (-1L)) 00098 Indexing the const array should usually be slightly faster. */ 00099 #endif 00100 00101 #define shift_left(x, n) (((x) & setbits[32 - (n)]) << (n)) 00102 /* This macro is included because the C standard does not properly define a 00103 left shift: on some machines the bits which are pushed out at the left are 00104 popped back in at the right. By masking, the macro prevents this behaviour. 00105 If you are sure that your machine does not pops bits back in, you can speed 00106 up the code insignificantly by taking out the masking. */ 00107 00108 #define shift_right(x, n) (((x) >> (n)) & setbits[32 - (n)]) 00109 /* See comment on left shift. */ 00110 00111 00112 00113 /******************************************************************************/ 00114 00115 00116 00117 00118 /* Functions required for packing: */ 00119 00120 #if defined (PROTOTYPE) 00121 void v2pack_wordimage_c(WORD *img, int x, int y, char *filename); 00122 /* Pack image 'img', containing 'x * y' WORD-sized pixels into 'filename'. 00123 This function generates Version 2 images! */ 00124 00125 void v2pack_longimage_c(LONG *img, int x, int y, char *filename); 00126 /* Pack image 'img', containing 'x * y' LONG-sized pixels into 'filename'. 00127 This function generates Version 2 images! */ 00128 00129 00130 /* Functions required for unpacking: */ 00131 00132 00133 void readpack_word_c(WORD *img, char *filename); 00134 /* Unpacks packed image from 'filename' into the WORD-array 'img'. Scans the 00135 file defined by 'filename' until the PACKIDENTIFIER is found, then unpacks 00136 starting from there. */ 00137 00138 void readpack_long_c(LONG *img, char *filename); 00139 /* Unpacks packed image from 'filename' into the LONG-array 'img'. Scans the 00140 file defined by 'filename' until the PACKIDENTIFIER is found, then unpacks 00141 starting from there. */ 00142 00143 void imsiz_c(char *filename, LONG *x, LONG *y); 00144 /* Determines the size of the the packed image "filename" after unpacking. The 00145 dimensions are returned in x and y. */ 00146 00147 #endif /* (PROTOTYPE) */ 00148