1
     ˆÅÄÃ564ÂÁÀ 4    ‹      Õ–]oÚ0†ïû+<_ìNÂçF�LA*D™¦iÚ…‰±šØ‘c`ì×ÏÁLeheë¤æ&'‰_?ï±,ò*šôçŸ§ôa~7BÓ�ïGÃ>Â5€OÍ>@4�Ü@«îù ƒ1F81&ïl·Ûú¶YWzó$&K[P-bSg†áðŠ”ÿÂ+DN™�ˆaR%ãß�Z"PkSÆí¼]ŒoDÌ‹òÝð2ž)½;„6HÅ¸q¾ö€i±áš€ËfóÃa²PlW®ë?Û6Õœ.öK•¯:$&AšŠ•°Q9‰ÈV¨Ðq€AÄJ°H©|¨¯Ä#šš ö'_­LRÎ	E‰æË ¿ëãëIápL3N€žÖÜYÍG´0(SL,ggÅ÷N|/¾ŸO9MÄ‹X‹Ü%¥`-[�UZäÔzm[‰>V9	ûS5hüK1¦7³Áxg®$¬LñH÷—;†Ã)Õ\	Ícc‡Ž\ú×rQä×??Ñ�W‹UbpˆP�T^`r-¤ÚÊcŸ¶†'.„´ç£|#þÆÔð�šï×>òZ=ïBg„ödÞþ+üR¥Œëcös»s¨õ><�Þ‹ünÏëœ¥ŽÒ_Dï;z¿šôGß¨&}ÓÑ7«Ißrô­jÒ·}»šôGß©&}×Ñw_ý—Õšoì­ŠC_Ê…u‰éî[ÿ¿�'vNpè)	ì»V®[þ7Ià!�    B   ˆl–Ðz¾” ”Ê:”Ê�jã/\ªbÑ¿�þZxDY¹BÓÅp¡Íù¿„Í:çÄ_ŠI|¥�+Wé3ž¯ÃÂ ?÷     #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# *****************************************************************************
#  $Id$
#
#  Project:  GDAL
#  Purpose:  Validate Cloud Optimized GeoTIFF file structure
#  Author:   Even Rouault, <even dot rouault at spatialys dot com>
#
# *****************************************************************************
#  Copyright (c) 2017, Even Rouault
#
#  Permission is hereby granted, free of charge, to any person obtaining a
#  copy of this software and associated documentation files (the "Software"),
#  to deal in the Software without restriction, including without limitation
#  the rights to use, copy, modify, merge, publish, distribute, sublicense,
#  and/or sell copies of the Software, and to permit persons to whom the
#  Software is furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included
#  in all copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
#  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
#  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#  DEALINGS IN THE SOFTWARE.
# *****************************************************************************

import os.path
import struct
import sys

from osgeo import gdal


def Usage():
    print(
        "Usage: validate_cloud_optimized_geotiff.py [-q] [--full-check=yes/no/auto] test.tif"
    )
    print("")
    print("Options:")
    print("-q: quiet mode")
    print(
        "--full-check=yes/no/auto: check tile/strip leader/trailer bytes. auto=yes for local files, and no for remote files"
    )
    return 2


class ValidateCloudOptimizedGeoTIFFException(Exception):
    pass


def full_check_band(
    f,
    band_name,
    band,
    errors,
    block_order_row_major,
    block_leader_size_as_uint4,
    block_trailer_last_4_bytes_repeated,
    mask_interleaved_with_imagery,
):

    block_size = band.GetBlockSize()
    mask_band = None
    if mask_interleaved_with_imagery:
        mask_band = band.GetMaskBand()
        mask_block_size = mask_band.GetBlockSize()
        if block_size != mask_block_size:
            errors += [
                band_name + ": mask block size is different from its imagery band"
            ]
            mask_band = None

    yblocks = (band.YSize + block_size[1] - 1) // block_size[1]
    xblocks = (band.XSize + block_size[0] - 1) // block_size[0]
    last_offset = 0
    for y in range(yblocks):
        for x in range(xblocks):

            offset = band.GetMetadataItem("BLOCK_OFFSET_%d_%d" % (x, y), "TIFF")
            offset = int(offset) if offset is not None else 0
            bytecount = band.GetMetadataItem("BLOCK_SIZE_%d_%d" % (x, y), "TIFF")
            bytecount = int(bytecount) if bytecount is not None else 0

            if offset > 0:
                if block_order_row_major and offset < last_offset:
                    errors += [
                        band_name
                        + ": offset of block (%d, %d) is smaller than previous block"
                        % (x, y)
            