diff --git a/src/dio/LICENSE.txt b/src/dio/LICENSE.txt index a3236b421..11bc16b7b 100644 --- a/src/dio/LICENSE.txt +++ b/src/dio/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2018 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 diff --git a/src/dio/decode_file.cpp b/src/dio/decode_file.cpp index 234de9758..a440ba9e9 100644 --- a/src/dio/decode_file.cpp +++ b/src/dio/decode_file.cpp @@ -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 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 diff --git a/src/dio/detect_format.cpp b/src/dio/detect_format.cpp index 65ed992ed..e0ed3155f 100644 --- a/src/dio/detect_format.cpp +++ b/src/dio/detect_format.cpp @@ -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;