MISR Toolkit  1.5.1
crle.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group. *
3  * Copyright by the Board of Trustees of the University of Illinois. *
4  * All rights reserved. *
5  * *
6  * This file is part of HDF. The full HDF copyright notice, including *
7  * terms governing use, modification, and redistribution, is contained in *
8  * the COPYING file, which can be found at the root of the source code *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF/releases/. *
10  * If you do not have access to either file, you may request a copy from *
11  * help@hdfgroup.org. *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /* $Id$ */
15 
16 /*-----------------------------------------------------------------------------
17  * File: crle.h
18  * Purpose: Header file for run-length encoding information.
19  * Dependencies: should only be included from hcompi.h
20  * Invokes: none
21  * Contents: Structures & definitions for run-length encoding. This header
22  * should only be included in hcomp.c and crle.c.
23  * Structure definitions:
24  * Constant definitions:
25  *---------------------------------------------------------------------------*/
26 
27 /* avoid re-inclusion */
28 #ifndef __CRLE_H
29 #define __CRLE_H
30 
31 #if defined c_plusplus || defined __cplusplus
32 extern "C"
33 {
34 #endif /* c_plusplus || __cplusplus */
35 
36 /*
37  ** from crle.c
38  */
39 
40  extern int32 HCPcrle_stread
41  (accrec_t * rec);
42 
43  extern int32 HCPcrle_stwrite
44  (accrec_t * rec);
45 
46  extern int32 HCPcrle_seek
47  (accrec_t * access_rec, int32 offset, int origin);
48 
49  extern int32 HCPcrle_inquire
50  (accrec_t * access_rec, int32 *pfile_id, uint16 *ptag, uint16 *pref,
51  int32 *plength, int32 *poffset, int32 *pposn, int16 *paccess,
52  int16 *pspecial);
53 
54  extern int32 HCPcrle_read
55  (accrec_t * access_rec, int32 length, void * data);
56 
57  extern int32 HCPcrle_write
58  (accrec_t * access_rec, int32 length, const void * data);
59 
60  extern intn HCPcrle_endaccess
61  (accrec_t * access_rec);
62 
63 #if defined c_plusplus || defined __cplusplus
64 }
65 #endif /* c_plusplus || __cplusplus */
66 
67 /* size of the RLE buffer */
68 #define RLE_BUF_SIZE 128
69 /* NIL code for run bytes */
70 #define RLE_NIL (-1)
71 /* minimum length of run */
72 #define RLE_MIN_RUN 3
73 /* maximum length of run */
74 #define RLE_MAX_RUN (RLE_BUF_SIZE+RLE_MIN_RUN-1)
75 /* minimum length of mix */
76 #define RLE_MIN_MIX 1
77 /*
78  * Notes on RLE_MIN_RUN and RLE_MIN_MIX:
79  * (excerpt from QAK's email to RA - see bug HDFFR-1261)
80  *
81  * These are [small] optimizations for improving the compression ratio. The
82  * algorithm won't encode a run of identical bytes unless it's at least
83  * RLE_MIN_RUN bytes long. So, we can assume that all runs are at least
84  * that many bytes, and subtract RLE_MIN_RUN from the actual run length,
85  * allowing encoding of runs that are a little bit longer than otherwise
86  * allowed (i.e. runs up to 127+RLE_MIN_RUN bytes, instead of only 127 bytes).
87  * Similarly for RLE_MIN_MIX - there must be at least RLE_MIN_MIX bytes in a
88  * "mixed" sequence of bytes, so we can encode a little bit longer sequence
89  * of mixed bytes (127+RLE_MIN_MIX bytes, instead of only 127 bytes).
90  */
91 
92 /* RLE [en|de]coding information */
93 typedef struct
94 {
95  int32 offset; /* offset in the file */
96  uint8 buffer[RLE_BUF_SIZE]; /* buffer for storing RLE bytes */
97  intn buf_length; /* number of bytes in buffer */
98  intn buf_pos; /* offset into the buffer */
99  uintn last_byte, /* the last byte stored in the buffer */
100  second_byte; /* the second to last byte stored in the buffer */
101  enum
102  {
103  RLE_INIT, /* initial state, need to read a byte to
104  determine the next state */
105  RLE_RUN, /* buffer up to the current position is a run */
106  RLE_MIX /* buffer up to the current position is a mix */
107  }
108  rle_state; /* state of the buffer storage */
109 }
111 
112 #ifndef CRLE_MASTER
113 extern funclist_t crle_funcs; /* functions to perform run-length encoding */
114 #else
115 funclist_t crle_funcs =
116 { /* functions to perform run-length encoding */
119  HCPcrle_seek,
121  HCPcrle_read,
124 };
125 #endif
126 
127 #endif /* __CRLE_H */
int32 HCPcrle_seek(accrec_t *access_rec, int32 offset, int origin)
intn HCPcrle_endaccess(accrec_t *access_rec)
funclist_t crle_funcs
int32 HCPcrle_write(accrec_t *access_rec, int32 length, const void *data)
void origin(double A)
HDFFCLIBAPI intf intf intf intf void * buffer
int32 HCPcrle_stwrite(accrec_t *rec)
#define RLE_BUF_SIZE
Definition: crle.h:68
int32 HCPcrle_read(accrec_t *access_rec, int32 length, void *data)
HDFFCLIBAPI void * data
HDFFCLIBAPI intf * offset
int32 HCPcrle_inquire(accrec_t *access_rec, int32 *pfile_id, uint16 *ptag, uint16 *pref, int32 *plength, int32 *poffset, int32 *pposn, int16 *paccess, int16 *pspecial)
int32 HCPcrle_stread(accrec_t *rec)

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:52