comparison srf2fastq/io_lib-1.12.2/io_lib/ztr.h @ 0:d901c9f41a6a default tip

Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
author dawe
date Tue, 07 Jun 2011 17:48:05 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d901c9f41a6a
1 #ifndef _ZTR_H
2 #define _ZTR_H
3
4 #include "io_lib/Read.h"
5 #include "io_lib/deflate_interlaced.h"
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 /* The header */
12 typedef struct {
13 unsigned char magic[8]; /* 0xae5a54520d0a1a0a (be) */
14 unsigned char version_major; /* ZTR_VERSION_MAJOR */
15 unsigned char version_minor; /* ZTR_VERSION_MINOR */
16 } ztr_header_t;
17
18 /* The ZTR magic numbers */
19 #define ZTR_MAGIC "\256ZTR\r\n\032\n"
20 #define ZTR_VERSION_MAJOR 1
21 #define ZTR_VERSION_MINOR 2
22
23 /*
24 * CHUNKS
25 *
26 * Chunks consist of a block length followed by the type, format and data.
27 */
28
29 typedef struct {
30 uint4 type; /* chunk type (be) */
31 uint4 mdlength; /* length of meta data field (be) */
32 char *mdata; /* meta data */
33 uint4 dlength; /* length of data field (be) */
34 char *data; /* a format byte and the data itself */
35 int ztr_owns; /* boolean: true if we can free (meta)data */
36 } ztr_chunk_t;
37
38 /* Format types */
39 #define ZTR_FORM_RAW 0
40 #define ZTR_FORM_RLE 1
41 #define ZTR_FORM_ZLIB 2
42 #define ZTR_FORM_XRLE 3
43 #define ZTR_FORM_XRLE2 4
44 #define ZTR_FORM_DELTA1 64
45 #define ZTR_FORM_DELTA2 65
46 #define ZTR_FORM_DELTA4 66
47 #define ZTR_FORM_DDELTA1 67
48 #define ZTR_FORM_DDELTA2 68
49 #define ZTR_FORM_DDELTA4 69
50 #define ZTR_FORM_16TO8 70
51 #define ZTR_FORM_32TO8 71
52 #define ZTR_FORM_FOLLOW1 72
53 #define ZTR_FORM_CHEB445 73
54 #define ZTR_FORM_ICHEB 74
55 #define ZTR_FORM_LOG2 75
56 #define ZTR_FORM_STHUFF 77
57 #define ZTR_FORM_QSHIFT 79
58 #define ZTR_FORM_TSHIFT 80
59
60 /* Converts a C string to a big-endian 4-byte int */
61 #define ZTR_STR2BE(str) (((str)[0] << 24) + \
62 ((str)[1] << 16) + \
63 ((str)[2] << 8) + \
64 ((str)[3] << 0))
65
66 /* Converts a big-endian 4-byte int to a C string */
67 #define ZTR_BE2STR(i,str) (((str)[0]=((i)>>24)&0xff),\
68 ((str)[1]=((i)>>16)&0xff),\
69 ((str)[2]=((i)>> 8)&0xff),\
70 ((str)[3]=((i)>> 0)&0xff),\
71 (str)[4]='\0',str)\
72
73 #define ZTR_TYPE_HEADER 0xae5a5452 /* M-. Z T R */
74
75 #define ZTR_TYPE_SAMP 0x53414d50
76 #define ZTR_TYPE_SMP4 0x534d5034
77 #define ZTR_TYPE_BASE 0x42415345
78 #define ZTR_TYPE_BPOS 0x42504f53
79 #define ZTR_TYPE_CNF4 0x434e4634
80 #define ZTR_TYPE_CNF1 0x434e4631
81 #define ZTR_TYPE_CSID 0x43534944
82 #define ZTR_TYPE_TEXT 0x54455854
83 #define ZTR_TYPE_CLIP 0x434c4950
84 #define ZTR_TYPE_COMM 0x434f4d4d
85 #define ZTR_TYPE_CR32 0x43523332
86 #define ZTR_TYPE_FLWO 0x464c574f
87 #define ZTR_TYPE_FLWC 0x464c5743
88 #define ZTR_TYPE_HUFF 0x48554646
89 #define ZTR_TYPE_REGN 0x5245474e
90
91 /* A text segment consists of identifier and value */
92 typedef struct {
93 char *ident; /* Pointer to identifier */
94 char *value; /* Pointer to value */
95 } ztr_text_t;
96
97 typedef struct {
98 int ztr_owns; /* true is ZTR is to free the data later */
99 huffman_codeset_t *codes;
100 } ztr_hcode_t;
101
102 /* The main ZTR structure, which holds the entire file contents */
103 typedef struct {
104 /* General bits to do with the ZTR file format */
105 ztr_header_t header; /* File Header */
106 ztr_chunk_t *chunk; /* Array of chunks */
107 int nchunks; /* Number of chunks */
108
109 /* Specifics to do with the standard chunk types */
110 ztr_text_t *text_segments;
111 int ntext_segments;
112
113 /* 'Hint' for delta of SAMP and SMP4 */
114 int delta_level;
115
116 /* Cached huffman encoding/decoding tables for STHUFF format */
117 ztr_hcode_t *hcodes;
118 int nhcodes;
119 int hcodes_checked;
120 } ztr_t;
121
122 int ztr_read_header(mFILE *fp, ztr_header_t *h);
123 ztr_chunk_t *ztr_read_chunk_hdr(mFILE *fp);
124
125 int fwrite_ztr(FILE *fp, ztr_t *ztr);
126 int mfwrite_ztr(mFILE *fp, ztr_t *ztr);
127 ztr_t *fread_ztr(FILE *fp);
128 ztr_t *mfread_ztr(mFILE *fp);
129 Read *ztr2read(ztr_t *ztr);
130 ztr_t *read2ztr(Read *r);
131 int compress_ztr(ztr_t *ztr, int level);
132 int uncompress_ztr(ztr_t *ztr);
133 ztr_t *new_ztr(void);
134 void delete_ztr(ztr_t *ztr);
135 ztr_chunk_t **ztr_find_chunks(ztr_t *ztr, uint4 type, int *nchunks_p);
136 void ztr_process_text(ztr_t *ztr);
137 int compress_chunk(ztr_t *ztr, ztr_chunk_t *chunk, int format,
138 int option, int option2);
139 int uncompress_chunk(ztr_t *ztr, ztr_chunk_t *chunk);
140 ztr_hcode_t *ztr_add_hcode(ztr_t *ztr, huffman_codeset_t *codes, int ztr_owns);
141 int ztr_store_hcodes(ztr_t *ztr);
142 ztr_hcode_t *ztr_find_hcode(ztr_t *ztr, int code_set);
143 ztr_chunk_t *ztr_find_hcode_chunk(ztr_t *ztr, int code_set);
144 char *ztr_lookup_mdata_value(ztr_t *z, ztr_chunk_t *chunk, char *key);
145 ztr_chunk_t *ztr_new_chunk(ztr_t *ztr, uint4 type,
146 char *data, uint4 dlength,
147 char *mdata, uint4 mdlength);
148 ztr_chunk_t *ztr_add_text(ztr_t *z, ztr_chunk_t *ch,
149 const char *key, const char *value);
150
151 #ifdef __cplusplus
152 }
153 #endif
154
155 #endif /* _ZTR_H */