mirror of
https://github.com/isledecomp/SIEdit.git
synced 2024-11-23 15:48:03 -05:00
lib: implement bmp chunking
This commit is contained in:
parent
85e786924d
commit
1f453fa10e
2 changed files with 33 additions and 15 deletions
|
@ -128,6 +128,19 @@ bool Object::ReplaceWithFile(FileBase *f)
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case MxOb::STL:
|
||||||
|
{
|
||||||
|
BMP bmp;
|
||||||
|
f->ReadData(&bmp, sizeof(bmp));
|
||||||
|
|
||||||
|
bytearray info_header = f->ReadBytes(bmp.DataOffset - f->pos());
|
||||||
|
data_.push_back(info_header);
|
||||||
|
|
||||||
|
bytearray pixels = f->ReadBytes(bmp.FileSize - f->pos());
|
||||||
|
data_.push_back(pixels);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
LogWarning() << "Don't yet know how to chunk type " << RIFF::PrintU32AsString(this->filetype()) << std::endl;
|
LogWarning() << "Don't yet know how to chunk type " << RIFF::PrintU32AsString(this->filetype()) << std::endl;
|
||||||
break;
|
break;
|
||||||
|
@ -172,28 +185,23 @@ bool Object::ExtractToFile(FileBase *f) const
|
||||||
}
|
}
|
||||||
case MxOb::STL:
|
case MxOb::STL:
|
||||||
{
|
{
|
||||||
static const uint32_t BMP_HDR_SZ = 14;
|
uint32_t size = sizeof(BMP);
|
||||||
|
for (size_t i=0; i<data_.size(); i++) {
|
||||||
|
size += data_.at(i).size();
|
||||||
|
}
|
||||||
|
|
||||||
// Write BMP header
|
// Write BMP header
|
||||||
f->WriteU16(0x4D42);
|
BMP bmp;
|
||||||
|
bmp.Signature = 0x4D42; // 'BM'
|
||||||
|
bmp.FileSize = size;
|
||||||
|
bmp.Reserved = 0;
|
||||||
|
bmp.DataOffset = data_.at(0).size() + sizeof(BMP);
|
||||||
|
|
||||||
// Write placeholder for size
|
f->WriteData(&bmp, sizeof(bmp));
|
||||||
size_t sz_loc = f->pos();
|
|
||||||
f->WriteU32(0);
|
|
||||||
|
|
||||||
// Write "reserved" bytes
|
|
||||||
f->WriteU32(0);
|
|
||||||
|
|
||||||
// Write data offset
|
|
||||||
f->WriteU32(data_.at(0).size() + BMP_HDR_SZ);
|
|
||||||
|
|
||||||
for (size_t i=0; i<data_.size(); i++) {
|
for (size_t i=0; i<data_.size(); i++) {
|
||||||
f->WriteBytes(data_.at(i));
|
f->WriteBytes(data_.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t len = f->pos();
|
|
||||||
f->seek(sz_loc);
|
|
||||||
f->WriteU32(len);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MxOb::FLC:
|
case MxOb::FLC:
|
||||||
|
|
|
@ -72,6 +72,16 @@ public:
|
||||||
uint32_t Dummy;
|
uint32_t Dummy;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Analogous to BITMAPFILEHEADER, copied from http://www.ece.ualberta.ca/~elliott/ee552/studentAppNotes/2003_w/misc/bmp_file_format/bmp_file_format.htm
|
||||||
|
LIBWEAVER_PACK(class BMP
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
uint16_t Signature; // Should always be BM
|
||||||
|
uint32_t FileSize; // Size of total file including header and 'BM'
|
||||||
|
uint32_t Reserved; // Unused (always 0)
|
||||||
|
uint32_t DataOffset; // Offset of actual data after BITMAPINFOHEADER
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // OTHERTYPES_H
|
#endif // OTHERTYPES_H
|
||||||
|
|
Loading…
Reference in a new issue