00001 #ifndef ASSTORAGE_H_HEADER_INCLUDED
00002 #define ASSTORAGE_H_HEADER_INCLUDED
00003
00004
00005 #define AS_STORAGE_PAGE_SIZE 4096
00006
00007
00008
00009
00010
00011 #define AS_STORAGE_SLOTS_BATCH 1024
00012 #define AS_STORAGE_SLOT_ID_BITS 14
00013 #define AS_STORAGE_MAX_SLOTS_CNT (0x01<<AS_STORAGE_SLOT_ID_BITS)
00014
00015 #define AS_STORAGE_BLOCK_ID_BITS (32-AS_STORAGE_SLOT_ID_BITS)
00016 #define AS_STORAGE_MAX_BLOCK_CNT (0x01<<AS_STORAGE_BLOCK_ID_BITS)
00017
00018 #define AS_STORAGE_DEF_BLOCK_SIZE (1024*128)
00019 #define AS_STORAGE_NOUSE_THRESHOLD (1024*8)
00020
00021
00022
00023
00024 #define ASStorageSlot_SIZE 16
00025 #define ASStorageSlot_USABLE_SIZE(slot) (((slot)->size+15)&0x8FFFFFF0)
00026 #define ASStorageSlot_FULL_SIZE(slot) (ASStorageSlot_USABLE_SIZE(slot)+ASStorageSlot_SIZE)
00027
00028 #define AS_STORAGE_GetNextSlot(slot) ((slot)+1+(ASStorageSlot_USABLE_SIZE(slot)>>4))
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #define RLE_ZERO_MASK 0x0080
00048 #define RLE_ZERO_LENGTH 0x007F
00049 #define RLE_ZERO_SIG 0x0000
00050
00051 #define RLE_NOZERO_SHORT_MASK 0x00C0
00052 #define RLE_NOZERO_SHORT_LENGTH 0x003F
00053 #define RLE_NOZERO_SHORT_SIG 0x00C0
00054
00055 #define RLE_NOZERO_LONG_MASK 0x00F0
00056 #define RLE_NOZERO_LONG_LENGTH 0x000F
00057 #define RLE_NOZERO_LONG1_SIG 0x00A0
00058 #define RLE_NOZERO_LONG2_SIG 0x00B0
00059
00060 #define RLE_9BIT_SIG 0x0080
00061
00062 #define RLE_9BIT_NEG_SIG 0x0090
00063
00064
00065 #define AS_STORAGE_DEFAULT_BMAP_THRESHOLD 0x7F
00066 #define AS_STORAGE_DEFAULT_BMAP_VALUE 0xFF
00067
00068
00069 typedef struct ASStorageSlot
00070 {
00071
00072
00073
00074 #define ASStorage_ZlibCompress (0x01<<0)
00075 #define ASStorage_RLEDiffCompress (0x01<<1)
00076
00077 #define ASStorage_CompressionType (0x0F<<0)
00078 #define ASStorage_Used (0x01<<4)
00079 #define ASStorage_NotTileable (0x01<<5)
00080 #define ASStorage_Reference (0x01<<6)
00081 #define ASStorage_Bitmap (0x01<<7)
00082 #define ASStorage_32Bit (0x01<<8)
00083 #define ASStorage_BitShiftFlagPos 9
00084 #define ASStorage_BitShift (0x03<<ASStorage_BitShiftFlagPos)
00085 #define ASStorage_8BitShift (0x01<<ASStorage_BitShiftFlagPos)
00086
00087
00088 #define ASStorage_16BitShift (0x01<<(ASStorage_BitShiftFlagPos+1))
00089
00090
00091
00092 #define ASStorage_24BitShift (ASStorage_8BitShift|ASStorage_16BitShift)
00093 #define ASStorage_Flags2ShiftIdx(f) (((f)>>ASStorage_BitShiftFlagPos)&0x03)
00094 #define ASStorage_Flags2Shift(f) (ASStorage_Flags2ShiftIdx(f)*8)
00095 #define ASStorage_Masked (0x01<<11)
00096
00097
00098
00099
00100 #define ASStorage_32BitRLE (ASStorage_RLEDiffCompress|ASStorage_32Bit)
00101
00102 CARD16 flags ;
00103 CARD16 ref_count ;
00104 CARD32 size ;
00105 CARD32 uncompressed_size ;
00106 CARD16 index ;
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 CARD16 reserved ;
00120
00121
00122
00123 #define ASStorage_Data(s) ((CARD8*)((s)+1))
00124
00125 }ASStorageSlot;
00126
00127
00128
00129 typedef short ASStorageDiff;
00130
00131
00132 typedef void (*compute_diff_func_type)(ASStorageDiff*,CARD8*,int);
00133 typedef int (*copy_data32_func_type)(CARD8*,CARD32*,int);
00134 typedef int (*copy_data32_tinted_func_type)(CARD8*,CARD32*,int,CARD32);
00135
00136
00137 typedef struct ASStorageBlock
00138 {
00139 #define ASStorage_MonoliticBlock (0x01<<0)
00140 CARD32 flags ;
00141 int size ;
00142
00143 int total_free;
00144 ASStorageSlot *start, *end;
00145
00146
00147 ASStorageSlot **slots;
00148 int slots_count, unused_count ;
00149 int first_free, last_used ;
00150 int long_searches ;
00151
00152 }ASStorageBlock;
00153
00154 typedef struct ASStorage
00155 {
00156 int default_block_size ;
00157
00158
00159 ASStorageBlock **blocks ;
00160 int blocks_count;
00161
00162 ASStorageDiff *diff_buf ;
00163 CARD8 *comp_buf ;
00164 size_t comp_buf_size ;
00165
00166 }ASStorage;
00167
00168
00169 typedef CARD32 ASStorageID ;
00170
00171 ASStorageID store_data(ASStorage *storage, CARD8 *data, int size, ASFlagType flags, CARD8 bitmap_threshold);
00172 ASStorageID store_data_tinted(ASStorage *storage, CARD8 *data, int size, ASFlagType flags, CARD16 tint);
00173
00174
00175
00176
00177 int fetch_data(ASStorage *storage, ASStorageID id, CARD8 *buffer, int offset, int buf_size, CARD8 bitmap_value, int *original_size);
00178 int fetch_data32(ASStorage *storage, ASStorageID id, CARD32 *buffer, int offset, int buf_size, CARD8 bitmap_value, int *original_size);
00179 int threshold_stored_data(ASStorage *storage, ASStorageID id, unsigned int *runs, int width, unsigned int threshold);
00180
00181
00182 void forget_data(ASStorage *storage, ASStorageID id);
00183
00184 void print_storage(ASStorage *storage);
00185
00186 int print_storage_slot(ASStorage *storage, ASStorageID id);
00187 Bool query_storage_slot(ASStorage *storage, ASStorageID id, ASStorageSlot *dst );
00188
00189
00190
00191
00192
00193 ASStorageID dup_data(ASStorage *storage, ASStorageID src_id);
00194
00195
00196
00197
00198 void flush_default_asstorage();
00199 int set_asstorage_block_size( ASStorage *storage, int new_size );
00200
00201
00202 #endif