home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn User 10
/
AU_CD10.iso
/
Archived
/
Updates
/
Flash
/
writeflash
/
!MakeFlash
/
c
/
matrix
< prev
next >
Wrap
Text File
|
2000-04-19
|
3KB
|
96 lines
#include <stdio.h>
//
#include "proto.h"
#include "bucket.h"
#include "matrix.h"
#include "bitcount.h"
int matrix_read(MATRIX *matrix) {
U32 ok, bits;
matrix_reset(matrix);
if (read_ubits(1, &ok)) return 1;
if (ok) {
if (read_ubits(5, &bits)) return 1;
if (read_bits(bits, &matrix->scalex)) return 1;
if (read_bits(bits, &matrix->scaley)) return 1;
}
if (read_ubits(1, &ok)) return 1;
if (ok) {
if (read_ubits(5, &bits)) return 1;
if (read_bits(bits, &matrix->rotate0)) return 1;
if (read_bits(bits, &matrix->rotate1)) return 1;
}
if (read_ubits(5, &bits)) return 1;
if (read_bits(bits, &matrix->tx)) return 1;
if (read_bits(bits, &matrix->ty)) return 1;
return 0;
}
int matrix_write(MATRIX *matrix) {
int n;
if (flush_bucket()) return 1;
if ((matrix->scalex != 65536) || (matrix->scaley != 65536)) {
if (write_ubits(1, 1)) return 1;
n = bitcount_signed(matrix->scalex, matrix->scaley, 0, 0);
if (write_ubits(5, n)) return 1;
if (write_bits(n, matrix->scalex)) return 1;
if (write_bits(n, matrix->scaley)) return 1;
} else
if (write_ubits(1, 0)) return 1;
if ((matrix->rotate0 != 0) || (matrix->rotate1 != 0)) {
if (write_ubits(1, 1)) return 1;
n = bitcount_signed(matrix->rotate0, matrix->rotate1, 0, 0);
if (write_ubits(5, n)) return 1;
if (write_bits(n, matrix->rotate0)) return 1;
if (write_bits(n, matrix->rotate1)) return 1;
} else
if (write_ubits(1, 0)) return 1;
n = bitcount_signed(matrix->tx, matrix->ty, 0, 0);
if (write_ubits(5, n)) return 1;
if (write_bits(n, matrix->tx)) return 1;
if (write_bits(n, matrix->ty)) return 1;
return 0;
}
U32 matrix_count_bits(MATRIX *matrix) {
U32 bits;
bits = 1;
if ((matrix->scalex != 65536) || (matrix->scaley != 65536))
bits += 5 + 2*bitcount_signed(matrix->scalex, matrix->scaley, 0, 0);
// rotate/skew
bits += 1;
if ((matrix->rotate0 != 0) || (matrix->rotate1 != 0))
bits += 5 + 2*bitcount_signed(matrix->rotate0, matrix->rotate1, 0, 0);
// translate
bits += 5 + 2*bitcount_signed(matrix->tx, matrix->ty, 0, 0);
return bits;
}
void matrix_reset(MATRIX *matrix) {
matrix->scalex = matrix->scaley = 65536;
matrix->rotate0 = matrix->rotate1 = 0;
matrix->tx = matrix->ty = 0;
}