Skip to content

Commit

Permalink
Merge branch 'OSGeo:master' into i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
yoichigmf authored Aug 22, 2024
2 parents ea32d62 + 3ae328f commit 94b96d4
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 34 deletions.
59 changes: 59 additions & 0 deletions autotest/gdrivers/heif.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
# DEALINGS IN THE SOFTWARE.
###############################################################################

import os
import shutil

import pytest
Expand Down Expand Up @@ -171,3 +172,61 @@ def test_heif_subdatasets(tmp_path):
gdal.Open("HEIF:1")
with pytest.raises(Exception):
gdal.Open("HEIF:1:")


def test_heif_identify_no_match():

drv = gdal.IdentifyDriverEx("data/byte.tif", allowed_drivers=["HEIF"])
assert drv is None


def test_heif_identify_heic():

drv = gdal.IdentifyDriverEx("data/heif/subdatasets.heic", allowed_drivers=["HEIF"])
assert drv.GetDescription() == "HEIF"


@pytest.mark.parametrize(
"major_brand,compatible_brands,expect_success",
[
("heic", [], True),
("heix", [], True),
("j2ki", [], True),
("j2ki", ["j2ki"], True),
("jpeg", [], True),
("jpg ", [], False),
("miaf", [], True),
("mif1", [], True),
("mif2", [], True),
("mif9", [], False), # this doesn't exist
("fake", ["miaf"], True),
("j2kj", [], False),
("fake", [], False),
("fake", ["fake", "also"], False),
("fake", ["fake", "avif"], True),
("fake", ["fake", "bvif"], False),
("fake", ["fake", "mif2"], True),
("fake", ["fake", "mif9"], False),
],
)
def test_identify_various(major_brand, compatible_brands, expect_success):

f = gdal.VSIFOpenL("/vsimem/heif_header.bin", "wb")
gdal.VSIFSeekL(f, 4, os.SEEK_SET)
gdal.VSIFWriteL("ftyp", 1, 4, f) # box type
gdal.VSIFWriteL(major_brand, 1, 4, f)
gdal.VSIFWriteL(b"\x00\x00\x00\x00", 1, 4, f) # minor_version
for brand in compatible_brands:
gdal.VSIFWriteL(brand, 1, 4, f)
length = gdal.VSIFTellL(f)
gdal.VSIFSeekL(f, 0, os.SEEK_SET) # go back and fill in actual box size
gdal.VSIFWriteL(length.to_bytes(4, "big"), 1, 4, f)
gdal.VSIFCloseL(f)

drv = gdal.IdentifyDriverEx("/vsimem/heif_header.bin", allowed_drivers=["HEIF"])
if expect_success:
assert drv.GetDescription() == "HEIF"
else:
assert drv is None

gdal.Unlink("/vsimem/heif_header.bin")
6 changes: 3 additions & 3 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ Ubuntu version:
* Vector drivers: all built-in + XML based ones + SQLite-based ones + network-based ones + PostgreSQL
* Using internal libtiff and libgeotiff
* External libraries enabled: libsqlite3, libproj, libcurl, libjpeg, libpng, libwebp,
libzstd, libexpat, libxerces-c, libpq, libssl, libgeos, libspatialite
* GDAL Python (Python 3.8 for Ubuntu 20.04, Python 3.10 for Ubuntu 22.04)
libzstd, libdeflate, libexpat, libxerces-c, libpq, libssl, libgeos, libspatialite
* GDAL Python (Python 3.8 for Ubuntu 20.04, Python 3.10 for Ubuntu 22.04, Python 3.12 for Ubuntu 24.04)
* Base PROJ grid package (http://download.osgeo.org/proj/proj-datumgrid-1.8.zip)
* Overall licensing terms of the GDAL build: LGPL + permissive (MIT, BSD style, Apache, etc..)

Expand All @@ -74,7 +74,7 @@ See [ubuntu-small/Dockerfile](ubuntu-small/Dockerfile)
* External libraries enabled: small + libnetcdf, libhdf4, libhdf5, libtiledb, libkea,
mongocxx 3.4, libspatialite, unixodbc, libxml2, libcfitsio, libmysqlclient,
libkml, libpoppler, pdfium, openexr, libheif, libdeflate, libparquet, libjxl
* GDAL Python (Python 3.8 for Ubuntu 20.04, Python 3.10 for Ubuntu 22.04)
* GDAL Python (Python 3.8 for Ubuntu 20.04, Python 3.10 for Ubuntu 22.04, Python 3.12 for Ubuntu 24.04)
* *All* PROJ grid packages (equivalent of latest of proj-data-X.zip from http://download.osgeo.org/proj/ at time of generation, > 500 MB)
* Overall licensing terms of the GDAL build: copy-left (GPL) + LGPL + permissive

Expand Down
2 changes: 2 additions & 0 deletions docker/ubuntu-small/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ RUN . /buildscripts/bh-set-envvars.sh \
libjpeg-dev${APT_ARCH_SUFFIX} libgeos-dev${APT_ARCH_SUFFIX} \
libexpat-dev${APT_ARCH_SUFFIX} libxerces-c-dev${APT_ARCH_SUFFIX} \
libwebp-dev${APT_ARCH_SUFFIX} libpng-dev${APT_ARCH_SUFFIX} \
libdeflate-dev${APT_ARCH_SUFFIX} \
libzstd-dev${APT_ARCH_SUFFIX} bash zip curl \
libpq-dev${APT_ARCH_SUFFIX} libssl-dev${APT_ARCH_SUFFIX} libopenjp2-7-dev${APT_ARCH_SUFFIX} \
libspatialite-dev${APT_ARCH_SUFFIX} \
Expand Down Expand Up @@ -236,6 +237,7 @@ RUN apt-get update -y \
libexpat1 \
libxerces-c3.2 \
libwebp7 libpng16-16 \
libdeflate0 \
libzstd1 bash libpq5 libssl3 libopenjp2-7 libspatialite8 \
# pil for antialias option of gdal2tiles
python3-pil \
Expand Down
71 changes: 40 additions & 31 deletions frmts/heif/heifdrivercore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,51 @@
/* HEIFDriverIdentifySimplified() */
/************************************************************************/

int HEIFDriverIdentifySimplified(GDALOpenInfo *poOpenInfo)
static const GByte FTYP_4CC[] = {'f', 't', 'y', 'p'};
static const GByte supportedBrands[][4]{
{'a', 'v', 'i', 'f'}, {'h', 'e', 'i', 'c'}, {'h', 'e', 'i', 'x'},
{'j', '2', 'k', 'i'}, {'j', 'p', 'e', 'g'}, {'m', 'i', 'a', 'f'},
{'m', 'i', 'f', '1'}, {'m', 'i', 'f', '2'}};

int HEIFDriverIdentifySimplified(GDALOpenInfo *poOpenInfo)
{
if (STARTS_WITH_CI(poOpenInfo->pszFilename, "HEIF:"))
{
return true;

if (poOpenInfo->nHeaderBytes < 12 || poOpenInfo->fpL == nullptr)
}
if (poOpenInfo->nHeaderBytes < 16 || poOpenInfo->fpL == nullptr)
{
return false;

// Simplistic test...
const unsigned char abySig1[] = "\x00"
"\x00"
"\x00"
"\x20"
"ftypheic";
const unsigned char abySig2[] = "\x00"
"\x00"
"\x00"
"\x18"
"ftypheic";
const unsigned char abySig3[] = "\x00"
"\x00"
"\x00"
"\x18"
"ftypmif1"
"\x00"
"\x00"
"\x00"
"\x00"
"mif1heic";
return (poOpenInfo->nHeaderBytes >= static_cast<int>(sizeof(abySig1)) &&
memcmp(poOpenInfo->pabyHeader, abySig1, sizeof(abySig1)) == 0) ||
(poOpenInfo->nHeaderBytes >= static_cast<int>(sizeof(abySig2)) &&
memcmp(poOpenInfo->pabyHeader, abySig2, sizeof(abySig2)) == 0) ||
(poOpenInfo->nHeaderBytes >= static_cast<int>(sizeof(abySig3)) &&
memcmp(poOpenInfo->pabyHeader, abySig3, sizeof(abySig3)) == 0);
}
if (memcmp(poOpenInfo->pabyHeader + 4, FTYP_4CC, sizeof(FTYP_4CC)) != 0)
{
return false;
}
uint32_t lengthBigEndian;
memcpy(&lengthBigEndian, poOpenInfo->pabyHeader, sizeof(uint32_t));
uint32_t lengthHostEndian = CPL_MSBWORD32(lengthBigEndian);
if (lengthHostEndian > static_cast<uint32_t>(poOpenInfo->nHeaderBytes))
{
lengthHostEndian = static_cast<uint32_t>(poOpenInfo->nHeaderBytes);
}
for (const GByte *supportedBrand : supportedBrands)
{
if (memcmp(poOpenInfo->pabyHeader + 8, supportedBrand, 4) == 0)
{
return true;
}
}
for (uint32_t offset = 16; offset + 4 <= lengthHostEndian; offset += 4)
{
for (const GByte *supportedBrand : supportedBrands)
{
if (memcmp(poOpenInfo->pabyHeader + offset, supportedBrand, 4) == 0)
{
return true;
}
}
}
return false;
}

/************************************************************************/
Expand Down
3 changes: 3 additions & 0 deletions frmts/kea/keaoverview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ KEAOverview::KEAOverview(KEADataset *pDataset, int nSrcBand,

KEAOverview::~KEAOverview()
{
// according to the docs, this is required
// otherwise not all tiles will be written.
this->FlushCache();
}

// overridden implementation - calls readFromOverview instead
Expand Down

0 comments on commit 94b96d4

Please sign in to comment.