mirror of
https://github.com/NoelFB/blah.git
synced 2025-07-18 19:41:52 +08:00
replaced log.h with common.h, added easier shorthand for int types
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
#include <blah/images/aseprite.h>
|
||||
#include <blah/streams/filestream.h>
|
||||
#include <blah/core/filesystem.h>
|
||||
#include <blah/core/log.h>
|
||||
#include <blah/core/common.h>
|
||||
|
||||
#define STBI_NO_STDIO
|
||||
#define STBI_ONLY_ZLIB
|
||||
@ -10,7 +10,7 @@
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define MUL_UN8(a, b, t) \
|
||||
((t) = (a) * (uint16_t)(b) + 0x80, ((((t) >> 8) + (t) ) >> 8))
|
||||
((t) = (a) * (u16)(b) + 0x80, ((((t) >> 8) + (t) ) >> 8))
|
||||
|
||||
using namespace Blah;
|
||||
|
||||
@ -98,10 +98,10 @@ void Aseprite::parse(Stream& stream)
|
||||
// header
|
||||
{
|
||||
// filesize
|
||||
stream.read<uint32_t>(Endian::Little);
|
||||
stream.read<u32>(Endian::Little);
|
||||
|
||||
// magic number
|
||||
auto magic = stream.read<uint16_t>(Endian::Little);
|
||||
auto magic = stream.read<u16>(Endian::Little);
|
||||
if (magic != 0xA5E0)
|
||||
{
|
||||
BLAH_ERROR("File is not a valid Aseprite file");
|
||||
@ -109,21 +109,21 @@ void Aseprite::parse(Stream& stream)
|
||||
}
|
||||
|
||||
// main info
|
||||
frame_count = stream.read<uint16_t>(Endian::Little);
|
||||
width = stream.read<uint16_t>(Endian::Little);
|
||||
height = stream.read<uint16_t>(Endian::Little);
|
||||
mode = static_cast<Aseprite::Modes>(stream.read<uint16_t>(Endian::Little) / 8);
|
||||
frame_count = stream.read<u16>(Endian::Little);
|
||||
width = stream.read<u16>(Endian::Little);
|
||||
height = stream.read<u16>(Endian::Little);
|
||||
mode = static_cast<Aseprite::Modes>(stream.read<u16>(Endian::Little) / 8);
|
||||
|
||||
// don't care about other info
|
||||
stream.read<uint32_t>(Endian::Little); // Flags
|
||||
stream.read<uint16_t>(Endian::Little); // Speed (deprecated)
|
||||
stream.read<uint32_t>(Endian::Little); // Should be 0
|
||||
stream.read<uint32_t>(Endian::Little); // Should be 0
|
||||
stream.read<uint8_t>(Endian::Little); // Palette entry
|
||||
stream.read<u32>(Endian::Little); // Flags
|
||||
stream.read<u16>(Endian::Little); // Speed (deprecated)
|
||||
stream.read<u32>(Endian::Little); // Should be 0
|
||||
stream.read<u32>(Endian::Little); // Should be 0
|
||||
stream.read<u8>(Endian::Little); // Palette entry
|
||||
stream.seek(stream.position() + 3); // Ignore these bytes
|
||||
stream.read<uint16_t>(Endian::Little); // Number of colors (0 means 256 for old sprites)
|
||||
stream.read<int8_t>(Endian::Little); // Pixel width
|
||||
stream.read<int8_t>(Endian::Little); // Pixel height
|
||||
stream.read<u16>(Endian::Little); // Number of colors (0 means 256 for old sprites)
|
||||
stream.read<i8>(Endian::Little); // Pixel width
|
||||
stream.read<i8>(Endian::Little); // Pixel height
|
||||
stream.seek(stream.position() + 92); // For Future
|
||||
}
|
||||
|
||||
@ -133,22 +133,22 @@ void Aseprite::parse(Stream& stream)
|
||||
for (int i = 0; i < frame_count; i++)
|
||||
{
|
||||
auto frameStart = stream.position();
|
||||
auto frameEnd = frameStart + stream.read<uint32_t>(Endian::Little);
|
||||
auto frameEnd = frameStart + stream.read<u32>(Endian::Little);
|
||||
unsigned int chunks = 0;
|
||||
|
||||
// frame header
|
||||
{
|
||||
auto magic = stream.read<uint16_t>(Endian::Little); // magic number
|
||||
auto magic = stream.read<u16>(Endian::Little); // magic number
|
||||
if (magic != 0xF1FA)
|
||||
{
|
||||
BLAH_ERROR("File is not a valid Aseprite file");
|
||||
return;
|
||||
}
|
||||
|
||||
auto old_chunk_count = stream.read<uint16_t>(Endian::Little);
|
||||
frames[i].duration = stream.read<uint16_t>(Endian::Little);
|
||||
auto old_chunk_count = stream.read<u16>(Endian::Little);
|
||||
frames[i].duration = stream.read<u16>(Endian::Little);
|
||||
stream.seek(stream.position() + 2); // for future
|
||||
auto new_chunk_count = stream.read<uint32_t>(Endian::Little);
|
||||
auto new_chunk_count = stream.read<u32>(Endian::Little);
|
||||
|
||||
if (old_chunk_count == 0xFFFF)
|
||||
chunks = new_chunk_count;
|
||||
@ -163,8 +163,8 @@ void Aseprite::parse(Stream& stream)
|
||||
for (unsigned int j = 0; j < chunks; j++)
|
||||
{
|
||||
auto chunkStart = stream.position();
|
||||
auto chunkEnd = chunkStart + stream.read<uint32_t>(Endian::Little);
|
||||
auto chunkType = static_cast<Chunks>(stream.read<uint16_t>(Endian::Little));
|
||||
auto chunkEnd = chunkStart + stream.read<u32>(Endian::Little);
|
||||
auto chunkType = static_cast<Chunks>(stream.read<u16>(Endian::Little));
|
||||
|
||||
switch (chunkType)
|
||||
{
|
||||
@ -189,17 +189,17 @@ void Aseprite::parse_layer(Stream& stream, int frame)
|
||||
layers.emplace_back();
|
||||
|
||||
auto& layer = layers.back();
|
||||
layer.flag = static_cast<LayerFlags>(stream.read<uint16_t>(Endian::Little));
|
||||
layer.flag = static_cast<LayerFlags>(stream.read<u16>(Endian::Little));
|
||||
layer.visible = ((int)layer.flag & (int)LayerFlags::Visible) == (int)LayerFlags::Visible;
|
||||
layer.type = static_cast<LayerTypes>(stream.read<uint16_t>(Endian::Little));
|
||||
layer.child_level = stream.read<uint16_t>(Endian::Little);
|
||||
stream.read<uint16_t>(Endian::Little); // width
|
||||
stream.read<uint16_t>(Endian::Little); // height
|
||||
layer.blendmode = stream.read<uint16_t>(Endian::Little);
|
||||
layer.alpha = stream.read<uint8_t>(Endian::Little);
|
||||
layer.type = static_cast<LayerTypes>(stream.read<u16>(Endian::Little));
|
||||
layer.child_level = stream.read<u16>(Endian::Little);
|
||||
stream.read<u16>(Endian::Little); // width
|
||||
stream.read<u16>(Endian::Little); // height
|
||||
layer.blendmode = stream.read<u16>(Endian::Little);
|
||||
layer.alpha = stream.read<u8>(Endian::Little);
|
||||
stream.seek(stream.position() + 3); // for future
|
||||
|
||||
layer.name.set_length(stream.read<uint16_t>(Endian::Little));
|
||||
layer.name.set_length(stream.read<u16>(Endian::Little));
|
||||
stream.read(layer.name.cstr(), layer.name.length());
|
||||
|
||||
layer.userdata.color = 0xffffff;
|
||||
@ -213,20 +213,20 @@ void Aseprite::parse_cel(Stream& stream, int frameIndex, size_t maxPosition)
|
||||
|
||||
frame.cels.emplace_back();
|
||||
auto& cel = frame.cels.back();
|
||||
cel.layer_index = stream.read<uint16_t>(Endian::Little);
|
||||
cel.x = stream.read<uint16_t>(Endian::Little);
|
||||
cel.y = stream.read<uint16_t>(Endian::Little);
|
||||
cel.alpha = stream.read<uint8_t>(Endian::Little);
|
||||
cel.layer_index = stream.read<u16>(Endian::Little);
|
||||
cel.x = stream.read<u16>(Endian::Little);
|
||||
cel.y = stream.read<u16>(Endian::Little);
|
||||
cel.alpha = stream.read<u8>(Endian::Little);
|
||||
cel.linked_frame_index = -1;
|
||||
|
||||
auto celType = stream.read<uint16_t>(Endian::Little);
|
||||
auto celType = stream.read<u16>(Endian::Little);
|
||||
stream.seek(stream.position() + 7);
|
||||
|
||||
// RAW or DEFLATE
|
||||
if (celType == 0 || celType == 2)
|
||||
{
|
||||
auto width = stream.read<uint16_t>(Endian::Little);
|
||||
auto height = stream.read<uint16_t>(Endian::Little);
|
||||
auto width = stream.read<u16>(Endian::Little);
|
||||
auto height = stream.read<u16>(Endian::Little);
|
||||
auto count = width * height * (int)mode;
|
||||
|
||||
cel.image = Image(width, height);
|
||||
@ -282,7 +282,7 @@ void Aseprite::parse_cel(Stream& stream, int frameIndex, size_t maxPosition)
|
||||
// this cel directly references a previous cel
|
||||
else if (celType == 1)
|
||||
{
|
||||
cel.linked_frame_index = stream.read<uint16_t>(Endian::Little);
|
||||
cel.linked_frame_index = stream.read<u16>(Endian::Little);
|
||||
}
|
||||
|
||||
// draw to frame if visible
|
||||
@ -298,21 +298,21 @@ void Aseprite::parse_cel(Stream& stream, int frameIndex, size_t maxPosition)
|
||||
|
||||
void Aseprite::parse_palette(Stream& stream, int frame)
|
||||
{
|
||||
/* size */ stream.read<uint32_t>(Endian::Little);
|
||||
auto start = stream.read<uint32_t>(Endian::Little);
|
||||
auto end = stream.read<uint32_t>(Endian::Little);
|
||||
/* size */ stream.read<u32>(Endian::Little);
|
||||
auto start = stream.read<u32>(Endian::Little);
|
||||
auto end = stream.read<u32>(Endian::Little);
|
||||
stream.seek(stream.position() + 8);
|
||||
|
||||
palette.resize(palette.size() + (end - start + 1));
|
||||
|
||||
for (int p = 0, len = static_cast<int>(end - start) + 1; p < len; p++)
|
||||
{
|
||||
auto hasName = stream.read<uint16_t>(Endian::Little);
|
||||
palette[start + p] = stream.read<uint32_t>(Endian::Little);
|
||||
auto hasName = stream.read<u16>(Endian::Little);
|
||||
palette[start + p] = stream.read<u32>(Endian::Little);
|
||||
|
||||
if (hasName & 0xF000)
|
||||
{
|
||||
int len = stream.read<uint16_t>(Endian::Little);
|
||||
int len = stream.read<u16>(Endian::Little);
|
||||
stream.seek(stream.position() + len);
|
||||
}
|
||||
}
|
||||
@ -322,38 +322,38 @@ void Aseprite::parse_user_data(Stream& stream, int frame)
|
||||
{
|
||||
if (m_last_userdata != nullptr)
|
||||
{
|
||||
auto flags = stream.read<uint32_t>(Endian::Little);
|
||||
auto flags = stream.read<u32>(Endian::Little);
|
||||
|
||||
// has text
|
||||
if (flags & (1 << 0))
|
||||
{
|
||||
m_last_userdata->text.set_length(stream.read<uint16_t>(Endian::Little));
|
||||
m_last_userdata->text.set_length(stream.read<u16>(Endian::Little));
|
||||
stream.read(m_last_userdata->text.cstr(), m_last_userdata->text.length());
|
||||
}
|
||||
|
||||
// has color
|
||||
if (flags & (1 << 1))
|
||||
m_last_userdata->color = stream.read<uint32_t>(Endian::Little);
|
||||
m_last_userdata->color = stream.read<u32>(Endian::Little);
|
||||
}
|
||||
}
|
||||
|
||||
void Aseprite::parse_tag(Stream& stream, int frame)
|
||||
{
|
||||
auto count = stream.read<uint16_t>(Endian::Little);
|
||||
auto count = stream.read<u16>(Endian::Little);
|
||||
stream.seek(stream.position() + 8);
|
||||
|
||||
for (int t = 0; t < count; t++)
|
||||
{
|
||||
Tag tag;
|
||||
tag.from = stream.read<uint16_t>(Endian::Little);
|
||||
tag.to = stream.read<uint16_t>(Endian::Little);
|
||||
tag.loops = static_cast<LoopDirections>(stream.read<int8_t>(Endian::Little));
|
||||
tag.from = stream.read<u16>(Endian::Little);
|
||||
tag.to = stream.read<u16>(Endian::Little);
|
||||
tag.loops = static_cast<LoopDirections>(stream.read<i8>(Endian::Little));
|
||||
|
||||
stream.seek(stream.position() + 8);
|
||||
tag.color = Color(stream.read<int8_t>(), stream.read<int8_t>(), stream.read<int8_t>(Endian::Little), 255);
|
||||
tag.color = Color(stream.read<i8>(), stream.read<i8>(), stream.read<i8>(Endian::Little), 255);
|
||||
stream.seek(stream.position() + 1);
|
||||
|
||||
tag.name.set_length(stream.read<uint16_t>(Endian::Little));
|
||||
tag.name.set_length(stream.read<u16>(Endian::Little));
|
||||
stream.read(tag.name.cstr(), tag.name.length());
|
||||
|
||||
tags.push_back(tag);
|
||||
@ -362,12 +362,12 @@ void Aseprite::parse_tag(Stream& stream, int frame)
|
||||
|
||||
void Aseprite::parse_slice(Stream& stream, int frame)
|
||||
{
|
||||
int count = stream.read<uint32_t>(Endian::Little);
|
||||
int flags = stream.read<uint32_t>(Endian::Little);
|
||||
stream.read<uint32_t>(Endian::Little); // reserved
|
||||
int count = stream.read<u32>(Endian::Little);
|
||||
int flags = stream.read<u32>(Endian::Little);
|
||||
stream.read<u32>(Endian::Little); // reserved
|
||||
|
||||
String name;
|
||||
name.set_length(stream.read<uint16_t>(Endian::Little));
|
||||
name.set_length(stream.read<u16>(Endian::Little));
|
||||
stream.read(name.cstr(), name.length());
|
||||
|
||||
for (int s = 0; s < count; s++)
|
||||
@ -376,19 +376,19 @@ void Aseprite::parse_slice(Stream& stream, int frame)
|
||||
|
||||
auto& slice = slices.back();
|
||||
slice.name = name;
|
||||
slice.frame = stream.read<uint32_t>(Endian::Little);
|
||||
slice.origin.x = stream.read<int32_t>(Endian::Little);
|
||||
slice.origin.y = stream.read<int32_t>(Endian::Little);
|
||||
slice.width = stream.read<uint32_t>(Endian::Little);
|
||||
slice.height = stream.read<uint32_t>(Endian::Little);
|
||||
slice.frame = stream.read<u32>(Endian::Little);
|
||||
slice.origin.x = stream.read<i32>(Endian::Little);
|
||||
slice.origin.y = stream.read<i32>(Endian::Little);
|
||||
slice.width = stream.read<u32>(Endian::Little);
|
||||
slice.height = stream.read<u32>(Endian::Little);
|
||||
|
||||
// 9 slice (ignored atm)
|
||||
if (flags & (1 << 0))
|
||||
{
|
||||
stream.read<int32_t>(Endian::Little);
|
||||
stream.read<int32_t>(Endian::Little);
|
||||
stream.read<uint32_t>(Endian::Little);
|
||||
stream.read<uint32_t>(Endian::Little);
|
||||
stream.read<i32>(Endian::Little);
|
||||
stream.read<i32>(Endian::Little);
|
||||
stream.read<u32>(Endian::Little);
|
||||
stream.read<u32>(Endian::Little);
|
||||
}
|
||||
|
||||
// pivot point
|
||||
@ -396,8 +396,8 @@ void Aseprite::parse_slice(Stream& stream, int frame)
|
||||
if (flags & (1 << 1))
|
||||
{
|
||||
slice.has_pivot = true;
|
||||
slice.pivot.x = stream.read<uint32_t>(Endian::Little);
|
||||
slice.pivot.y = stream.read<uint32_t>(Endian::Little);
|
||||
slice.pivot.x = stream.read<u32>(Endian::Little);
|
||||
slice.pivot.y = stream.read<u32>(Endian::Little);
|
||||
}
|
||||
|
||||
slice.userdata.color = 0xffffff;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <blah/images/font.h>
|
||||
#include <blah/streams/filestream.h>
|
||||
#include <blah/math/calc.h>
|
||||
#include <blah/core/log.h>
|
||||
#include <blah/core/common.h>
|
||||
|
||||
using namespace Blah;
|
||||
|
||||
@ -14,7 +14,7 @@ String GetName(stbtt_fontinfo* font, int nameId)
|
||||
int length = 0;
|
||||
|
||||
// get the name
|
||||
const uint16_t* ptr = (const uint16_t*)stbtt_GetFontNameStr(font, &length,
|
||||
const u16* ptr = (const u16*)stbtt_GetFontNameStr(font, &length,
|
||||
STBTT_PLATFORM_ID_MICROSOFT,
|
||||
STBTT_MS_EID_UNICODE_BMP,
|
||||
STBTT_MS_LANG_ENGLISH,
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <blah/images/image.h>
|
||||
#include <blah/streams/stream.h>
|
||||
#include <blah/streams/filestream.h>
|
||||
#include <blah/core/log.h>
|
||||
#include <blah/core/common.h>
|
||||
|
||||
using namespace Blah;
|
||||
|
||||
@ -18,7 +18,7 @@ namespace
|
||||
{
|
||||
int Blah_STBI_Read(void* user, char* data, int size)
|
||||
{
|
||||
int64_t read = ((Stream*)user)->read(data, size);
|
||||
i64 read = ((Stream*)user)->read(data, size);
|
||||
return (int)read;
|
||||
}
|
||||
|
||||
@ -29,8 +29,8 @@ namespace
|
||||
|
||||
int Blah_STBI_Eof(void* user)
|
||||
{
|
||||
int64_t position = ((Stream*)user)->position();
|
||||
int64_t length = ((Stream*)user)->length();
|
||||
i64 position = ((Stream*)user)->position();
|
||||
i64 length = ((Stream*)user)->length();
|
||||
|
||||
if (position >= length)
|
||||
return 1;
|
||||
@ -155,7 +155,7 @@ void Image::from_stream(Stream& stream)
|
||||
callbacks.skip = Blah_STBI_Skip;
|
||||
|
||||
int x, y, comps;
|
||||
uint8_t* data = stbi_load_from_callbacks(&callbacks, &stream, &x, &y, &comps, 4);
|
||||
u8* data = stbi_load_from_callbacks(&callbacks, &stream, &x, &y, &comps, 4);
|
||||
|
||||
if (data == nullptr)
|
||||
{
|
||||
@ -186,9 +186,9 @@ void Image::premultiply()
|
||||
{
|
||||
for (int n = 0; n < width * height; n ++)
|
||||
{
|
||||
pixels[n].r = (uint8_t)(pixels[n].r * pixels[n].a / 255);
|
||||
pixels[n].g = (uint8_t)(pixels[n].g * pixels[n].a / 255);
|
||||
pixels[n].b = (uint8_t)(pixels[n].b * pixels[n].a / 255);
|
||||
pixels[n].r = (u8)(pixels[n].r * pixels[n].a / 255);
|
||||
pixels[n].g = (u8)(pixels[n].g * pixels[n].a / 255);
|
||||
pixels[n].b = (u8)(pixels[n].b * pixels[n].a / 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <blah/images/packer.h>
|
||||
#include <blah/core/log.h>
|
||||
#include <blah/core/common.h>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
@ -41,22 +41,22 @@ Packer::~Packer()
|
||||
dispose();
|
||||
}
|
||||
|
||||
void Packer::add(uint64_t id, int width, int height, const Color* pixels)
|
||||
void Packer::add(u64 id, int width, int height, const Color* pixels)
|
||||
{
|
||||
add_entry(id, width, height, pixels);
|
||||
}
|
||||
|
||||
void Packer::add(uint64_t id, const Image& image)
|
||||
void Packer::add(u64 id, const Image& image)
|
||||
{
|
||||
add_entry(id, image.width, image.height, image.pixels);
|
||||
}
|
||||
|
||||
void Packer::add(uint64_t id, const String& path)
|
||||
void Packer::add(u64 id, const String& path)
|
||||
{
|
||||
add(id, Image(path.cstr()));
|
||||
}
|
||||
|
||||
void Packer::add_entry(uint64_t id, int w, int h, const Color* pixels)
|
||||
void Packer::add_entry(u64 id, int w, int h, const Color* pixels)
|
||||
{
|
||||
m_dirty = true;
|
||||
|
||||
|
Reference in New Issue
Block a user