diff --git a/README.md b/README.md index 2b76138..ed563a4 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,9 @@ imageinfo has been restructured, if you are using old version, please check `v1` * [x] heic (heif) * [x] icns * [x] ico -* [x] j2k -* [x] jp2 +* [x] jpeg2000 code stream (j2k, j2c, jpc, jhc) +* [x] jpeg2000 (jp2, jpx, jph) * [x] jpeg (jpg) -* [x] jpx * [x] ktx * [x] png * [x] psd diff --git a/README_CN.md b/README_CN.md index a6c417a..f5d9e12 100644 --- a/README_CN.md +++ b/README_CN.md @@ -25,10 +25,9 @@ imageinfo 已经重构,如果你使用的是旧版本,请查看 `v1` 分支 * [x] heic (heif) * [x] icns * [x] ico -* [x] j2k -* [x] jp2 +* [x] jpeg2000 code stream (j2k, j2c, jpc, jhc) +* [x] jpeg2000 (jp2, jpx, jph) * [x] jpeg (jpg) -* [x] jpx * [x] ktx * [x] png * [x] psd diff --git a/images/valid/jph/byte.jph b/images/valid/jph/byte.jph new file mode 100644 index 0000000..fb1580e Binary files /dev/null and b/images/valid/jph/byte.jph differ diff --git a/include/imageinfo.hpp b/include/imageinfo.hpp index bd40a5e..4f3a47b 100644 --- a/include/imageinfo.hpp +++ b/include/imageinfo.hpp @@ -88,8 +88,9 @@ enum Format { kFormatIco, kFormatJ2k, kFormatJp2, - kFormatJpeg, + kFormatJph, kFormatJpx, + kFormatJpeg, kFormatKtx, kFormatPng, kFormatPsd, @@ -924,7 +925,7 @@ inline bool try_icns(ReadInterface &ri, size_t length, ImageInfo &info) { // https://docs.fileformat.com/image/jp2/ // https://docs.fileformat.com/image/jpx/ -inline bool try_j2k(ReadInterface &ri, size_t length, ImageInfo &info) { +inline bool try_jpeg2000_code_stream(ReadInterface &ri, size_t length, ImageInfo &info) { if (length < 16) { return false; } @@ -951,7 +952,7 @@ inline bool try_j2k(ReadInterface &ri, size_t length, ImageInfo &info) { // https://docs.fileformat.com/image/jp2/ // https://docs.fileformat.com/image/jpx/ -inline bool try_jp2_jpx(ReadInterface &ri, size_t length, ImageInfo &info) { +inline bool try_jpeg2000(ReadInterface &ri, size_t length, ImageInfo &info) { if (length < 8) { return false; } @@ -982,6 +983,11 @@ inline bool try_jp2_jpx(ReadInterface &ri, size_t length, ImageInfo &info) { ext = "jp2"; full_ext = "jp2"; mimetype = "image/jp2"; + } else if (buffer.cmp(8, 4, "jph ")) { + format = kFormatJph; + ext = "jph"; + full_ext = "jph"; + mimetype = "image/jph"; } else if (buffer.cmp(8, 4, "jpx ")) { format = kFormatJpx; ext = "jpx"; @@ -1352,8 +1358,8 @@ enum DetectorIndex { kDetectorIndexGif, kDetectorIndexHdr, kDetectorIndexIcns, - kDetectorIndexJ2k, - kDetectorIndexJp2Jpx, + kDetectorIndexJpeg2000CodeStream, + kDetectorIndexJpeg2000, kDetectorIndexJpg, kDetectorIndexKtx, kDetectorIndexPng, @@ -1403,26 +1409,27 @@ inline ImageInfo parse(ReadInterface &ri, // size_t length = ri.length(); constexpr DetectorInfo dl[] = { - {kFormatAvif, kDetectorIndexAvifHeic, try_avif_heic}, - { kFormatBmp, kDetectorIndexBmp, try_bmp}, - { kFormatCur, kDetectorIndexCurIco, try_cur_ico}, - { kFormatDds, kDetectorIndexDds, try_dds}, - { kFormatGif, kDetectorIndexGif, try_gif}, - { kFormatHdr, kDetectorIndexHdr, try_hdr}, - {kFormatHeic, kDetectorIndexAvifHeic, try_avif_heic}, - {kFormatIcns, kDetectorIndexIcns, try_icns}, - { kFormatIco, kDetectorIndexCurIco, try_cur_ico}, - { kFormatJ2k, kDetectorIndexJ2k, try_j2k}, - { kFormatJp2, kDetectorIndexJp2Jpx, try_jp2_jpx}, - {kFormatJpeg, kDetectorIndexJpg, try_jpg}, - { kFormatJpx, kDetectorIndexJp2Jpx, try_jp2_jpx}, - { kFormatKtx, kDetectorIndexKtx, try_ktx}, - { kFormatPng, kDetectorIndexPng, try_png}, - { kFormatPsd, kDetectorIndexPsd, try_psd}, - { kFormatQoi, kDetectorIndexQoi, try_qoi}, - {kFormatTiff, kDetectorIndexTiff, try_tiff}, - {kFormatWebp, kDetectorIndexWebp, try_webp}, - { kFormatTga, kDetectorIndexTga, try_tga}, + {kFormatAvif, kDetectorIndexAvifHeic, try_avif_heic}, + { kFormatBmp, kDetectorIndexBmp, try_bmp}, + { kFormatCur, kDetectorIndexCurIco, try_cur_ico}, + { kFormatDds, kDetectorIndexDds, try_dds}, + { kFormatGif, kDetectorIndexGif, try_gif}, + { kFormatHdr, kDetectorIndexHdr, try_hdr}, + {kFormatHeic, kDetectorIndexAvifHeic, try_avif_heic}, + {kFormatIcns, kDetectorIndexIcns, try_icns}, + { kFormatIco, kDetectorIndexCurIco, try_cur_ico}, + { kFormatJ2k, kDetectorIndexJpeg2000CodeStream, try_jpeg2000_code_stream}, + { kFormatJp2, kDetectorIndexJpeg2000, try_jpeg2000}, + { kFormatJph, kDetectorIndexJpeg2000, try_jpeg2000}, + { kFormatJpx, kDetectorIndexJpeg2000, try_jpeg2000}, + {kFormatJpeg, kDetectorIndexJpg, try_jpg}, + { kFormatKtx, kDetectorIndexKtx, try_ktx}, + { kFormatPng, kDetectorIndexPng, try_png}, + { kFormatPsd, kDetectorIndexPsd, try_psd}, + { kFormatQoi, kDetectorIndexQoi, try_qoi}, + {kFormatTiff, kDetectorIndexTiff, try_tiff}, + {kFormatWebp, kDetectorIndexWebp, try_webp}, + { kFormatTga, kDetectorIndexTga, try_tga}, }; static_assert(FORMAT_COUNT == countof(dl), "FORMAT_COUNT != countof(dl)"); static_assert(check_format_order(dl), "Format order is incorrect"); diff --git a/tests/tests.cpp b/tests/tests.cpp index c8a6c9e..c49ae54 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -82,6 +82,8 @@ int main() { ASSET_II(IMAGES_DIR "valid/jp2/jpx_disguised_as_jp2.jp2", kNoError, kFormatJp2, 2717l, 3701l); } + { ASSET_II(IMAGES_DIR "valid/jph/byte.jph", kNoError, kFormatJph, 20l, 20l); } + { ASSET_II(IMAGES_DIR "valid/jpx/sample.jpx", kNoError, kFormatJpx, 2717l, 3701l); } {