Style changes. No functional change
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27516 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
9179339c4a
commit
6da7e6450f
|
@ -23,8 +23,8 @@
|
||||||
extern bool debug;
|
extern bool debug;
|
||||||
|
|
||||||
GIFLoad::GIFLoad(BPositionIO *input, BPositionIO *output) {
|
GIFLoad::GIFLoad(BPositionIO *input, BPositionIO *output) {
|
||||||
this->input = input;
|
fInput = input;
|
||||||
this->output = output;
|
fOutput = output;
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
if (!ReadGIFHeader()) {
|
if (!ReadGIFHeader()) {
|
||||||
|
@ -32,10 +32,10 @@ GIFLoad::GIFLoad(BPositionIO *input, BPositionIO *output) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) printf("GIFLoad::GIFLoad() - Image dimensions are %d x %d\n", width, height);
|
if (debug) printf("GIFLoad::GIFLoad() - Image dimensions are %d x %d\n", fWidth, fHeight);
|
||||||
|
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
if (input->Read(&c, 1) < 1) {
|
if (fInput->Read(&c, 1) < 1) {
|
||||||
fatalerror = true;
|
fatalerror = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,11 @@ GIFLoad::GIFLoad(BPositionIO *input, BPositionIO *output) {
|
||||||
} else {
|
} else {
|
||||||
if (debug) printf("GIFLoad::GIFLoad() - Found a single image and leaving\n");
|
if (debug) printf("GIFLoad::GIFLoad() - Found a single image and leaving\n");
|
||||||
}
|
}
|
||||||
if (scanline != NULL) free(scanline);
|
if (fScanLine != NULL) free(fScanLine);
|
||||||
return;
|
return;
|
||||||
} else if (c == 0x21) {
|
} else if (c == 0x21) {
|
||||||
unsigned char d;
|
unsigned char d;
|
||||||
if (input->Read(&d, 1) < 1) {
|
if (fInput->Read(&d, 1) < 1) {
|
||||||
fatalerror = true;
|
fatalerror = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ GIFLoad::GIFLoad(BPositionIO *input, BPositionIO *output) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (input->Read(&c, 1) < 1) {
|
if (fInput->Read(&c, 1) < 1) {
|
||||||
fatalerror = true;
|
fatalerror = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -92,55 +92,55 @@ GIFLoad::GIFLoad(BPositionIO *input, BPositionIO *output) {
|
||||||
|
|
||||||
void GIFLoad::Init() {
|
void GIFLoad::Init() {
|
||||||
fatalerror = false;
|
fatalerror = false;
|
||||||
scanline = NULL;
|
fScanLine = NULL;
|
||||||
palette = NULL;
|
fPalette = NULL;
|
||||||
input->Seek(0, SEEK_SET);
|
fInput->Seek(0, SEEK_SET);
|
||||||
head_memblock = NULL;
|
fHeadMemblock = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GIFLoad::ReadGIFHeader() {
|
bool GIFLoad::ReadGIFHeader() {
|
||||||
// Standard header
|
// Standard header
|
||||||
unsigned char header[13];
|
unsigned char header[13];
|
||||||
if (input->Read(header, 13) < 13) return false;
|
if (fInput->Read(header, 13) < 13) return false;
|
||||||
width = header[6] + (header[7] << 8);
|
fWidth = header[6] + (header[7] << 8);
|
||||||
height = header[8] + (header[9] << 8);
|
fHeight = header[8] + (header[9] << 8);
|
||||||
|
|
||||||
palette = new LoadPalette();
|
fPalette = new LoadPalette();
|
||||||
// Global palette
|
// Global palette
|
||||||
if (header[10] & 0x80) {
|
if (header[10] & 0x80) {
|
||||||
palette->size_in_bits = (header[10] & 0x07) + 1;
|
fPalette->size_in_bits = (header[10] & 0x07) + 1;
|
||||||
if (debug) printf("GIFLoad::ReadGIFHeader() - Found %d bit global palette\n", palette->size_in_bits);
|
if (debug) printf("GIFLoad::ReadGIFHeader() - Found %d bit global palette\n", fPalette->size_in_bits);
|
||||||
int s = 1 << palette->size_in_bits;
|
int s = 1 << fPalette->size_in_bits;
|
||||||
palette->size = s;
|
fPalette->size = s;
|
||||||
|
|
||||||
unsigned char gp[256 * 3];
|
unsigned char gp[256 * 3];
|
||||||
if (input->Read(gp, s * 3) < s * 3) return false;
|
if (fInput->Read(gp, s * 3) < s * 3) return false;
|
||||||
for (int x = 0; x < s; x++) {
|
for (int x = 0; x < s; x++) {
|
||||||
palette->SetColor(x, gp[x * 3], gp[x * 3 + 1], gp[x * 3 + 2]);
|
fPalette->SetColor(x, gp[x * 3], gp[x * 3 + 1], gp[x * 3 + 2]);
|
||||||
}
|
}
|
||||||
palette->backgroundindex = header[11];
|
fPalette->backgroundindex = header[11];
|
||||||
} else { // Install BeOS system palette in case local palette isn't present
|
} else { // Install BeOS system palette in case local palette isn't present
|
||||||
color_map *map = (color_map *)system_colors();
|
color_map *map = (color_map *)system_colors();
|
||||||
for (int x = 0; x < 256; x++) {
|
for (int x = 0; x < 256; x++) {
|
||||||
palette->SetColor(x, map->color_list[x].red, map->color_list[x].green,
|
fPalette->SetColor(x, map->color_list[x].red, map->color_list[x].green,
|
||||||
map->color_list[x].blue);
|
map->color_list[x].blue);
|
||||||
}
|
}
|
||||||
palette->size = 256;
|
fPalette->size = 256;
|
||||||
palette->size_in_bits = 8;
|
fPalette->size_in_bits = 8;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GIFLoad::ReadGIFLoopBlock() {
|
bool GIFLoad::ReadGIFLoopBlock() {
|
||||||
unsigned char length;
|
unsigned char length;
|
||||||
if (input->Read(&length, 1) < 1) return false;
|
if (fInput->Read(&length, 1) < 1) return false;
|
||||||
input->Seek(length, SEEK_CUR);
|
fInput->Seek(length, SEEK_CUR);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (input->Read(&length, 1) < 1) {
|
if (fInput->Read(&length, 1) < 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
input->Seek(length, SEEK_CUR);
|
fInput->Seek(length, SEEK_CUR);
|
||||||
} while (length != 0);
|
} while (length != 0);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -148,10 +148,10 @@ bool GIFLoad::ReadGIFLoopBlock() {
|
||||||
|
|
||||||
bool GIFLoad::ReadGIFControlBlock() {
|
bool GIFLoad::ReadGIFControlBlock() {
|
||||||
unsigned char data[6];
|
unsigned char data[6];
|
||||||
if (input->Read(data, 6) < 6) return false;
|
if (fInput->Read(data, 6) < 6) return false;
|
||||||
if (data[1] & 0x01) {
|
if (data[1] & 0x01) {
|
||||||
palette->usetransparent = true;
|
fPalette->usetransparent = true;
|
||||||
palette->transparentindex = data[4];
|
fPalette->transparentindex = data[4];
|
||||||
if (debug) printf("GIFLoad::ReadGIFControlBlock() - Transparency active, using palette index %d\n", data[4]);
|
if (debug) printf("GIFLoad::ReadGIFControlBlock() - Transparency active, using palette index %d\n", data[4]);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -162,8 +162,8 @@ bool GIFLoad::ReadGIFCommentBlock() {
|
||||||
unsigned char length;
|
unsigned char length;
|
||||||
char comment_data[256];
|
char comment_data[256];
|
||||||
do {
|
do {
|
||||||
if (input->Read(&length, 1) < 1) return false;
|
if (fInput->Read(&length, 1) < 1) return false;
|
||||||
if (input->Read(comment_data, length) < length) return false;
|
if (fInput->Read(comment_data, length) < length) return false;
|
||||||
comment_data[length] = 0x00;
|
comment_data[length] = 0x00;
|
||||||
if (debug) printf("%s", comment_data);
|
if (debug) printf("%s", comment_data);
|
||||||
} while (length != 0x00);
|
} while (length != 0x00);
|
||||||
|
@ -175,63 +175,63 @@ bool GIFLoad::ReadGIFUnknownBlock(unsigned char c) {
|
||||||
if (debug) printf("GIFLoad::ReadGIFUnknownBlock() - Found: %d\n", c);
|
if (debug) printf("GIFLoad::ReadGIFUnknownBlock() - Found: %d\n", c);
|
||||||
unsigned char length;
|
unsigned char length;
|
||||||
do {
|
do {
|
||||||
if (input->Read(&length, 1) < 1) return false;
|
if (fInput->Read(&length, 1) < 1) return false;
|
||||||
input->Seek(length, SEEK_CUR);
|
fInput->Seek(length, SEEK_CUR);
|
||||||
} while (length != 0x00);
|
} while (length != 0x00);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GIFLoad::ReadGIFImageHeader() {
|
bool GIFLoad::ReadGIFImageHeader() {
|
||||||
unsigned char data[9];
|
unsigned char data[9];
|
||||||
if (input->Read(data, 9) < 9) return false;
|
if (fInput->Read(data, 9) < 9) return false;
|
||||||
|
|
||||||
int local_width = data[4] + (data[5] << 8);
|
int local_width = data[4] + (data[5] << 8);
|
||||||
int local_height = data[6] + (data[7] << 8);
|
int local_height = data[6] + (data[7] << 8);
|
||||||
if (width != local_width || height != local_height) {
|
if (fWidth != local_width || fHeight != local_height) {
|
||||||
if (debug) printf("GIFLoad::ReadGIFImageHeader() - Local dimensions do not match global, setting to %d x %d\n",
|
if (debug) printf("GIFLoad::ReadGIFImageHeader() - Local dimensions do not match global, setting to %d x %d\n",
|
||||||
local_width, local_height);
|
local_width, local_height);
|
||||||
width = local_width;
|
fWidth = local_width;
|
||||||
height = local_height;
|
fHeight = local_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
scanline = (uint32 *)malloc(width * 4);
|
fScanLine = (uint32 *)malloc(fWidth * 4);
|
||||||
if (scanline == NULL) {
|
if (fScanLine == NULL) {
|
||||||
if (debug) printf("GIFLoad::ReadGIFImageHeader() - Could not allocate scanline\n");
|
if (debug) printf("GIFLoad::ReadGIFImageHeader() - Could not allocate scanline\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BRect rect(0, 0, width - 1, height - 1);
|
BRect rect(0, 0, fWidth - 1, fHeight - 1);
|
||||||
TranslatorBitmap header;
|
TranslatorBitmap header;
|
||||||
header.magic = B_HOST_TO_BENDIAN_INT32(B_TRANSLATOR_BITMAP);
|
header.magic = B_HOST_TO_BENDIAN_INT32(B_TRANSLATOR_BITMAP);
|
||||||
header.bounds.left = B_HOST_TO_BENDIAN_FLOAT(rect.left);
|
header.bounds.left = B_HOST_TO_BENDIAN_FLOAT(rect.left);
|
||||||
header.bounds.top = B_HOST_TO_BENDIAN_FLOAT(rect.top);
|
header.bounds.top = B_HOST_TO_BENDIAN_FLOAT(rect.top);
|
||||||
header.bounds.right = B_HOST_TO_BENDIAN_FLOAT(rect.right);
|
header.bounds.right = B_HOST_TO_BENDIAN_FLOAT(rect.right);
|
||||||
header.bounds.bottom = B_HOST_TO_BENDIAN_FLOAT(rect.bottom);
|
header.bounds.bottom = B_HOST_TO_BENDIAN_FLOAT(rect.bottom);
|
||||||
header.rowBytes = B_HOST_TO_BENDIAN_INT32(width * 4);
|
header.rowBytes = B_HOST_TO_BENDIAN_INT32(fWidth * 4);
|
||||||
header.colors = (color_space)B_HOST_TO_BENDIAN_INT32(B_RGBA32);
|
header.colors = (color_space)B_HOST_TO_BENDIAN_INT32(B_RGBA32);
|
||||||
header.dataSize = B_HOST_TO_BENDIAN_INT32(width * 4 * height);
|
header.dataSize = B_HOST_TO_BENDIAN_INT32(fWidth * 4 * fHeight);
|
||||||
if (output->Write(&header, 32) < 32) return false;
|
if (fOutput->Write(&header, 32) < 32) return false;
|
||||||
|
|
||||||
// Has local palette
|
// Has local palette
|
||||||
if (data[8] & 0x80) {
|
if (data[8] & 0x80) {
|
||||||
palette->size_in_bits = (data[8] & 0x07) + 1;
|
fPalette->size_in_bits = (data[8] & 0x07) + 1;
|
||||||
int s = 1 << palette->size_in_bits;
|
int s = 1 << fPalette->size_in_bits;
|
||||||
palette->size = s;
|
fPalette->size = s;
|
||||||
if (debug) printf("GIFLoad::ReadGIFImageHeader() - Found %d bit local palette\n",
|
if (debug) printf("GIFLoad::ReadGIFImageHeader() - Found %d bit local palette\n",
|
||||||
palette->size_in_bits);
|
fPalette->size_in_bits);
|
||||||
|
|
||||||
unsigned char lp[256 * 3];
|
unsigned char lp[256 * 3];
|
||||||
if (input->Read(lp, s * 3) < s * 3) return false;
|
if (fInput->Read(lp, s * 3) < s * 3) return false;
|
||||||
for (int x = 0; x < s; x++) {
|
for (int x = 0; x < s; x++) {
|
||||||
palette->SetColor(x, lp[x * 3], lp[x * 3 + 1], lp[x * 3 + 2]);
|
fPalette->SetColor(x, lp[x * 3], lp[x * 3 + 1], lp[x * 3 + 2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data[8] & 0x40) {
|
if (data[8] & 0x40) {
|
||||||
interlaced = true;
|
fInterlaced = true;
|
||||||
if (debug) printf("GIFLoad::ReadGIFImageHeader() - Image is interlaced\n");
|
if (debug) printf("GIFLoad::ReadGIFImageHeader() - Image is interlaced\n");
|
||||||
} else {
|
} else {
|
||||||
interlaced = false;
|
fInterlaced = false;
|
||||||
if (debug) printf("GIFLoad::ReadGIFImageHeader() - Image is not interlaced\n");
|
if (debug) printf("GIFLoad::ReadGIFImageHeader() - Image is not interlaced\n");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -241,87 +241,87 @@ bool GIFLoad::ReadGIFImageData() {
|
||||||
unsigned char new_entry[4096];
|
unsigned char new_entry[4096];
|
||||||
|
|
||||||
unsigned char cs;
|
unsigned char cs;
|
||||||
input->Read(&cs, 1);
|
fInput->Read(&cs, 1);
|
||||||
if (cs == palette->size_in_bits) {
|
if (cs == fPalette->size_in_bits) {
|
||||||
if (!InitFrame(palette->size_in_bits)) return false;
|
if (!InitFrame(fPalette->size_in_bits)) return false;
|
||||||
} else if (cs > palette->size_in_bits) {
|
} else if (cs > fPalette->size_in_bits) {
|
||||||
if (debug) printf("GIFLoad::ReadGIFImageData() - Code_size should be %d, not %d, allowing it\n", code_size, cs);
|
if (debug) printf("GIFLoad::ReadGIFImageData() - Code_size should be %d, not %d, allowing it\n", fCodeSize, cs);
|
||||||
if (!InitFrame(cs)) return false;
|
if (!InitFrame(cs)) return false;
|
||||||
} else if (cs < palette->size_in_bits) {
|
} else if (cs < fPalette->size_in_bits) {
|
||||||
if (debug) printf("GIFLoad::ReadGIFImageData() - Code_size should be %d, not %d\n", code_size, cs);
|
if (debug) printf("GIFLoad::ReadGIFImageData() - Code_size should be %d, not %d\n", fCodeSize, cs);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) printf("GIFLoad::ReadGIFImageData() - Starting LZW\n");
|
if (debug) printf("GIFLoad::ReadGIFImageData() - Starting LZW\n");
|
||||||
|
|
||||||
while ((new_code = NextCode()) != -1 && new_code != end_code) {
|
while ((fNewCode = NextCode()) != -1 && fNewCode != fEndCode) {
|
||||||
if (new_code == clear_code) {
|
if (fNewCode == fClearCode) {
|
||||||
ResetTable();
|
ResetTable();
|
||||||
new_code = NextCode();
|
fNewCode = NextCode();
|
||||||
old_code[0] = new_code;
|
fOldCode[0] = fNewCode;
|
||||||
old_code_length = 1;
|
fOldCodeLength = 1;
|
||||||
if (!OutputColor(old_code, 1)) goto bad_end;
|
if (!OutputColor(fOldCode, 1)) goto bad_end;
|
||||||
if (new_code == -1 || new_code == end_code) {
|
if (fNewCode == -1 || fNewCode == fEndCode) {
|
||||||
if (debug) printf("GIFLoad::ReadGIFImageData() - Premature end_code or error\n");
|
if (debug) printf("GIFLoad::ReadGIFImageData() - Premature fEndCode or error\n");
|
||||||
goto bad_end;
|
goto bad_end;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explicitly check for lack of clear code at start of file
|
// Explicitly check for lack of clear code at start of file
|
||||||
if (old_code_length == 0) {
|
if (fOldCodeLength == 0) {
|
||||||
old_code[0] = new_code;
|
fOldCode[0] = fNewCode;
|
||||||
old_code_length = 1;
|
fOldCodeLength = 1;
|
||||||
if (!OutputColor(old_code, 1)) goto bad_end;
|
if (!OutputColor(fOldCode, 1)) goto bad_end;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (table[new_code] != NULL) { // Does exist in table
|
if (fTable[fNewCode] != NULL) { // Does exist in table
|
||||||
if (!OutputColor(table[new_code], entry_size[new_code])) goto bad_end;
|
if (!OutputColor(fTable[fNewCode], fEntrySize[fNewCode])) goto bad_end;
|
||||||
|
|
||||||
//memcpy(new_entry, old_code, old_code_length);
|
//memcpy(new_entry, fOldCode, fOldCodeLength);
|
||||||
for (int x = 0; x < old_code_length; x++) {
|
for (int x = 0; x < fOldCodeLength; x++) {
|
||||||
new_entry[x] = old_code[x];
|
new_entry[x] = fOldCode[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
//memcpy(new_entry + old_code_length, table[new_code], 1);
|
//memcpy(new_entry + fOldCodeLength, fTable[fNewCode], 1);
|
||||||
new_entry[old_code_length] = *table[new_code];
|
new_entry[fOldCodeLength] = *fTable[fNewCode];
|
||||||
} else { // Does not exist in table
|
} else { // Does not exist in table
|
||||||
//memcpy(new_entry, old_code, old_code_length);
|
//memcpy(new_entry, fOldCode, fOldCodeLength);
|
||||||
for (int x = 0; x < old_code_length; x++) {
|
for (int x = 0; x < fOldCodeLength; x++) {
|
||||||
new_entry[x] = old_code[x];
|
new_entry[x] = fOldCode[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
//memcpy(new_entry + old_code_length, old_code, 1);
|
//memcpy(new_entry + fOldCodeLength, fOldCode, 1);
|
||||||
new_entry[old_code_length] = *old_code;
|
new_entry[fOldCodeLength] = *fOldCode;
|
||||||
|
|
||||||
if (!OutputColor(new_entry, old_code_length + 1)) goto bad_end;
|
if (!OutputColor(new_entry, fOldCodeLength + 1)) goto bad_end;
|
||||||
}
|
}
|
||||||
table[next_code] = MemblockAllocate(old_code_length + 1);
|
fTable[fNextCode] = MemblockAllocate(fOldCodeLength + 1);
|
||||||
|
|
||||||
//memcpy(table[next_code], new_entry, old_code_length + 1);
|
//memcpy(fTable[fNextCode], new_entry, fOldCodeLength + 1);
|
||||||
for (int x = 0; x < old_code_length + 1; x++) {
|
for (int x = 0; x < fOldCodeLength + 1; x++) {
|
||||||
table[next_code][x] = new_entry[x];
|
fTable[fNextCode][x] = new_entry[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
entry_size[next_code] = old_code_length + 1;
|
fEntrySize[fNextCode] = fOldCodeLength + 1;
|
||||||
|
|
||||||
//memcpy(old_code, table[new_code], entry_size[new_code]);
|
//memcpy(fOldCode, fTable[fNewCode], fEntrySize[fNewCode]);
|
||||||
for (int x = 0; x < entry_size[new_code]; x++) {
|
for (int x = 0; x < fEntrySize[fNewCode]; x++) {
|
||||||
old_code[x] = table[new_code][x];
|
fOldCode[x] = fTable[fNewCode][x];
|
||||||
}
|
}
|
||||||
|
|
||||||
old_code_length = entry_size[new_code];
|
fOldCodeLength = fEntrySize[fNewCode];
|
||||||
next_code++;
|
fNextCode++;
|
||||||
|
|
||||||
if (next_code > max_code && BITS != 12) {
|
if (fNextCode > fMaxCode && fBits != 12) {
|
||||||
BITS++;
|
fBits++;
|
||||||
max_code = (1 << BITS) - 1;
|
fMaxCode = (1 << fBits) - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MemblockDeleteAll();
|
MemblockDeleteAll();
|
||||||
if (new_code == -1) return false;
|
if (fNewCode == -1) return false;
|
||||||
if (debug) printf("GIFLoad::ReadGIFImageData() - Done\n");
|
if (debug) printf("GIFLoad::ReadGIFImageData() - Done\n");
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -332,57 +332,57 @@ bad_end:
|
||||||
}
|
}
|
||||||
|
|
||||||
short GIFLoad::NextCode() {
|
short GIFLoad::NextCode() {
|
||||||
while (bit_count < BITS) {
|
while (fBitCount < fBits) {
|
||||||
if (byte_count == 0) {
|
if (fByteCount == 0) {
|
||||||
if (input->Read(&byte_count, 1) < 1) return -1;
|
if (fInput->Read(&fByteCount, 1) < 1) return -1;
|
||||||
if (byte_count == 0) return end_code;
|
if (fByteCount == 0) return fEndCode;
|
||||||
if (input->Read(byte_buffer + (255 - byte_count), byte_count) < byte_count) return -1;
|
if (fInput->Read(fByteBuffer + (255 - fByteCount), fByteCount) < fByteCount) return -1;
|
||||||
}
|
}
|
||||||
bit_buffer |= (unsigned int)byte_buffer[255 - byte_count] << bit_count;
|
fBitBuffer |= (unsigned int)fByteBuffer[255 - fByteCount] << fBitCount;
|
||||||
byte_count--;
|
fByteCount--;
|
||||||
bit_count += 8;
|
fBitCount += 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
short s = bit_buffer & ((1 << BITS) - 1);
|
short s = fBitBuffer & ((1 << fBits) - 1);
|
||||||
bit_buffer >>= BITS;
|
fBitBuffer >>= fBits;
|
||||||
bit_count -= BITS;
|
fBitCount -= fBits;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GIFLoad::ResetTable() {
|
void GIFLoad::ResetTable() {
|
||||||
BITS = code_size + 1;
|
fBits = fCodeSize + 1;
|
||||||
next_code = clear_code + 2;
|
fNextCode = fClearCode + 2;
|
||||||
max_code = (1 << BITS) - 1;
|
fMaxCode = (1 << fBits) - 1;
|
||||||
|
|
||||||
MemblockDeleteAll();
|
MemblockDeleteAll();
|
||||||
for (int x = 0; x < 4096; x++) {
|
for (int x = 0; x < 4096; x++) {
|
||||||
table[x] = NULL;
|
fTable[x] = NULL;
|
||||||
if (x < (1 << code_size)) {
|
if (x < (1 << fCodeSize)) {
|
||||||
table[x] = MemblockAllocate(1);
|
fTable[x] = MemblockAllocate(1);
|
||||||
table[x][0] = x;
|
fTable[x][0] = x;
|
||||||
entry_size[x] = 1;
|
fEntrySize[x] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GIFLoad::InitFrame(int size) {
|
bool GIFLoad::InitFrame(int size) {
|
||||||
code_size = size;
|
fCodeSize = size;
|
||||||
if (code_size == 1) code_size++;
|
if (fCodeSize == 1) fCodeSize++;
|
||||||
BITS = code_size + 1;
|
fBits = fCodeSize + 1;
|
||||||
clear_code = 1 << code_size;
|
fClearCode = 1 << fCodeSize;
|
||||||
end_code = clear_code + 1;
|
fEndCode = fClearCode + 1;
|
||||||
next_code = clear_code + 2;
|
fNextCode = fClearCode + 2;
|
||||||
max_code = (1 << BITS) - 1;
|
fMaxCode = (1 << fBits) - 1;
|
||||||
pass = 0;
|
fPass = 0;
|
||||||
if (interlaced) row = gl_pass_starts_at[0];
|
if (fInterlaced) fRow = gl_pass_starts_at[0];
|
||||||
else row = 0;
|
else fRow = 0;
|
||||||
|
|
||||||
bit_count = 0;
|
fBitCount = 0;
|
||||||
bit_buffer = 0;
|
fBitBuffer = 0;
|
||||||
byte_count = 0;
|
fByteCount = 0;
|
||||||
old_code_length = 0;
|
fOldCodeLength = 0;
|
||||||
new_code = 0;
|
fNewCode = 0;
|
||||||
scanline_position = 0;
|
fScanlinePosition = 0;
|
||||||
|
|
||||||
ResetTable();
|
ResetTable();
|
||||||
return true;
|
return true;
|
||||||
|
@ -391,14 +391,14 @@ bool GIFLoad::InitFrame(int size) {
|
||||||
// Do 4k mallocs, keep them in a linked list, do a first fit across them
|
// Do 4k mallocs, keep them in a linked list, do a first fit across them
|
||||||
// when a new request comes along
|
// when a new request comes along
|
||||||
uchar *GIFLoad::MemblockAllocate(int size) {
|
uchar *GIFLoad::MemblockAllocate(int size) {
|
||||||
if (head_memblock == NULL) {
|
if (fHeadMemblock == NULL) {
|
||||||
head_memblock = new Memblock();
|
fHeadMemblock = new Memblock();
|
||||||
uchar *value = head_memblock->data;
|
uchar *value = fHeadMemblock->data;
|
||||||
head_memblock->offset = size;
|
fHeadMemblock->offset = size;
|
||||||
head_memblock->next = NULL;
|
fHeadMemblock->next = NULL;
|
||||||
return value;
|
return value;
|
||||||
} else {
|
} else {
|
||||||
Memblock *block = head_memblock;
|
Memblock *block = fHeadMemblock;
|
||||||
Memblock *last = NULL;
|
Memblock *last = NULL;
|
||||||
while (block != NULL) {
|
while (block != NULL) {
|
||||||
if (4096 - block->offset > size) {
|
if (4096 - block->offset > size) {
|
||||||
|
@ -422,14 +422,14 @@ uchar *GIFLoad::MemblockAllocate(int size) {
|
||||||
// Delete the linked list
|
// Delete the linked list
|
||||||
void GIFLoad::MemblockDeleteAll() {
|
void GIFLoad::MemblockDeleteAll() {
|
||||||
Memblock *block = NULL;
|
Memblock *block = NULL;
|
||||||
while (head_memblock != NULL) {
|
while (fHeadMemblock != NULL) {
|
||||||
block = head_memblock->next;
|
block = fHeadMemblock->next;
|
||||||
delete head_memblock;
|
delete fHeadMemblock;
|
||||||
head_memblock = block;
|
fHeadMemblock = block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GIFLoad::~GIFLoad() {
|
GIFLoad::~GIFLoad() {
|
||||||
delete palette;
|
delete fPalette;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ const int gl_increment_pass_by[] = {8, 8, 4, 2, 0};
|
||||||
|
|
||||||
class GIFLoad {
|
class GIFLoad {
|
||||||
public:
|
public:
|
||||||
GIFLoad(BPositionIO *input, BPositionIO *output);
|
GIFLoad(BPositionIO *fInput, BPositionIO *fOutput);
|
||||||
~GIFLoad();
|
~GIFLoad();
|
||||||
bool fatalerror;
|
bool fatalerror;
|
||||||
|
|
||||||
|
@ -53,50 +53,50 @@ class GIFLoad {
|
||||||
void MemblockDeleteAll();
|
void MemblockDeleteAll();
|
||||||
|
|
||||||
inline bool OutputColor(unsigned char *string, int size) {
|
inline bool OutputColor(unsigned char *string, int size) {
|
||||||
int bpr = width << 2;
|
int bpr = fWidth << 2;
|
||||||
|
|
||||||
for (int x = 0; x < size; x++) {
|
for (int x = 0; x < size; x++) {
|
||||||
scanline[scanline_position] = palette->ColorForIndex(string[x]);
|
fScanLine[fScanlinePosition] = fPalette->ColorForIndex(string[x]);
|
||||||
scanline_position++;
|
fScanlinePosition++;
|
||||||
|
|
||||||
if (scanline_position >= width) {
|
if (fScanlinePosition >= fWidth) {
|
||||||
if (output->WriteAt(32 + (row * bpr), scanline, bpr) < bpr) return false;
|
if (fOutput->WriteAt(32 + (fRow * bpr), fScanLine, bpr) < bpr) return false;
|
||||||
scanline_position = 0;
|
fScanlinePosition = 0;
|
||||||
if (interlaced) {
|
if (fInterlaced) {
|
||||||
row += gl_increment_pass_by[pass];
|
fRow += gl_increment_pass_by[fPass];
|
||||||
while (row >= height) {
|
while (fRow >= fHeight) {
|
||||||
pass++;
|
fPass++;
|
||||||
if (pass > 3) return true;
|
if (fPass > 3) return true;
|
||||||
row = gl_pass_starts_at[pass];
|
fRow = gl_pass_starts_at[fPass];
|
||||||
}
|
}
|
||||||
} else row++;
|
} else fRow++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
BPositionIO *input, *output;
|
BPositionIO *fInput, *fOutput;
|
||||||
LoadPalette *palette;
|
LoadPalette *fPalette;
|
||||||
bool interlaced;
|
bool fInterlaced;
|
||||||
int pass, row, width, height;
|
int fPass, fRow, fWidth, fHeight;
|
||||||
|
|
||||||
unsigned char old_code[4096];
|
unsigned char fOldCode[4096];
|
||||||
int old_code_length;
|
int fOldCodeLength;
|
||||||
short new_code;
|
short fNewCode;
|
||||||
int BITS, max_code, code_size;
|
int fBits, fMaxCode, fCodeSize;
|
||||||
short clear_code, end_code, next_code;
|
short fClearCode, fEndCode, fNextCode;
|
||||||
|
|
||||||
unsigned char *table[4096];
|
unsigned char *fTable[4096];
|
||||||
short entry_size[4096];
|
short fEntrySize[4096];
|
||||||
Memblock *head_memblock;
|
Memblock *fHeadMemblock;
|
||||||
|
|
||||||
int bit_count;
|
int fBitCount;
|
||||||
unsigned int bit_buffer;
|
unsigned int fBitBuffer;
|
||||||
unsigned char byte_count;
|
unsigned char fByteCount;
|
||||||
unsigned char byte_buffer[255];
|
unsigned char fByteBuffer[255];
|
||||||
|
|
||||||
uint32 *scanline;
|
uint32 *fScanLine;
|
||||||
int scanline_position;
|
int fScanlinePosition;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue