Merge branch 'main' into beta

This commit is contained in:
David Capello 2021-07-01 11:50:55 -03:00
commit 1d1982d312
5 changed files with 18 additions and 8 deletions

View File

@ -280,7 +280,7 @@ if(USE_SHARED_GIFLIB)
else()
set(GIF_LIBRARY giflib)
set(GIF_LIBRARIES ${GIF_LIBRARY})
set(GIF_INCLUDE_DIR ${GIFLIB_DIR}/lib)
set(GIF_INCLUDE_DIR ${GIFLIB_DIR})
set(GIF_INCLUDE_DIRS ${GIF_INCLUDE_DIR})
endif()
include_directories(${GIF_INCLUDE_DIRS})

View File

@ -1,4 +1,4 @@
Copyright (c) 2018-2020 Igara Studio S.A.
Copyright (c) 2018-2021 Igara Studio S.A.
Copyright (c) 2016-2018 David Capello
Permission is hereby granted, free of charge, to any person obtaining

View File

@ -1,4 +1,5 @@
// Aseprite Document IO Library
// Copyright (c) 2021 Igara Studio S.A.
// Copyright (c) 2017 David Capello
//
// This file is released under the terms of the MIT license.
@ -22,8 +23,8 @@ bool decode_file(DecodeDelegate* delegate,
assert(delegate);
assert(f);
std::vector<uint8_t> buf(8, 0);
size_t n = f->readBytes(&buf[0], 8);
uint8_t buf[12];
size_t n = f->readBytes(&buf[0], 12);
FileFormat format = detect_format_by_file_content_bytes(&buf[0], n);
f->seek(0); // Rewind

View File

@ -1,4 +1,5 @@
// Aseprite Document IO Library
// Copyright (c) 2021 Igara Studio S.A.
// Copyright (c) 2016-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -20,6 +21,8 @@
#define GIF_89_STAMP "GIF89a"
#define PNG_MAGIC_DWORD1 0x474E5089
#define PNG_MAGIC_DWORD2 0x0A1A0A0D
#define WEBP_STAMP_1 "RIFF" // "RIFFnnnnWEBP"
#define WEBP_STAMP_2 "WEBP"
namespace dio {
@ -47,6 +50,12 @@ FileFormat detect_format_by_file_content_bytes(const uint8_t* buf,
if (n >= 2) {
if (n >= 6) {
if (n >= 8) {
if (n >= 12) {
if (std::strncmp((const char*)buf, WEBP_STAMP_1, 4) == 0 ||
std::strncmp((const char*)buf+8, WEBP_STAMP_2, 4) == 0)
return FileFormat::WEBP_ANIMATION;
}
if (IS_MAGIC_DWORD(0, PNG_MAGIC_DWORD1) &&
IS_MAGIC_DWORD(4, PNG_MAGIC_DWORD2))
return FileFormat::PNG_IMAGE;
@ -81,8 +90,8 @@ FileFormat detect_format_by_file_content(const std::string& filename)
return FileFormat::ERROR;
FILE* f = handle.get();
uint8_t buf[8];
int n = (int)fread(buf, 1, 8, f);
uint8_t buf[12];
int n = (int)fread(buf, 1, 12, f);
return detect_format_by_file_content_bytes(buf, n);
}
@ -134,7 +143,7 @@ FileFormat detect_format_by_file_extension(const std::string& filename)
if (ext == "png")
return FileFormat::PNG_IMAGE;
if (ext == "svg")
return FileFormat::SVG_IMAGE;

2
third_party/giflib vendored

@ -1 +1 @@
Subproject commit be93703149d1098df66e78e7b75e908c8481990a
Subproject commit d213f633ea7a38cc84cb60eada04d56ba8fa8779