JP2OpenJPEG——基于OpenJPEG库的JPEG2000驱动程序

司机简称

JP2打开JPEG

生成依赖项

openjpeg>=2.1

这个驱动程序是一个基于OpenJPEG库的JPEG2000读写器的实现 v2 .

驱动程序使用VSI虚拟文件API,因此它可以读取JPEG2000压缩的NITF文件。

XMP元数据可以从JPEG2000文件中提取,并作为XML原始内容存储在XML:XMP元数据域中。

驱动程序支持将地理参考信息编写为GeoJP2和GMLJP2框。

驱动程序支持创建透明文件、任意带区计数和添加/读取元数据。还支持更新现有文件的地理参考或元数据。可选的知识产权元数据可以在xml:IPR框。

驱动程序功能

Supports CreateCopy()

This driver supports the GDALDriver::CreateCopy() operation

Supports Georeferencing

This driver supports georeferencing

Supports VirtualIO

This driver supports virtual I/O operations (/vsimem/, etc.)

影像配准

地理参考信息可以来自不同的来源:内部(GeoJP2或GMLJP2框)、worldfile.j2w/.wld sidecar文件或PAM(持久辅助元数据).aux.xml sidecar文件。默认情况下,按以下顺序获取信息(首先列出的是最优先的):PAM、GeoJP2、GMLJP2、WORLDFILE。

Starting with GDAL 2.2, the allowed sources and their priority order can be changed with the GDAL_GEOREF_SOURCES configuration option (or GEOREF_SOURCES open option) whose value is a comma-separated list of the following keywords : PAM, GEOJP2, GMLJP2, INTERNAL (shortcut for GEOJP2,GMLJP2), WORLDFILE, NONE. First mentioned sources are the most prioritary over the next ones. A non mentioned source will be ignored.

例如,将其设置为“WORLDFILE,PAM,INTERNAL”将使潜在的WORLDFILE优先于PAM或内部JP2框生成地理转换矩阵。将其设置为“PAM,WORLDFILE,GEOJP2”将使用上述源代码并忽略GMLJP2框。

螺纹支架

By default, if the JPEG2000 file has internal tiling, GDAL will try to decode several tiles in multiple threads if the RasterIO() request it receives intersect several tiles. This behavior can be controlled with the GDAL_NUM_THREADS configuration option that defaults to ALL_CPUS in that context. In case RAM is limited, it can be needed to set this configuration option to 1 to disable multi-threading

从OpenJPEG2.2.0开始,还可以在代码块级别启用多线程解码。这必须通过OPJu NUMu THREADS环境变量(注意:这是一个系统环境变量,不是GDAL配置选项)启用,该变量可以设置为数值或NUMu cpu。其默认值为1。从gdal2.3开始,GDAL自动启用代码块级别的多线程。从GDAL 3.0.1和OpenJPEG 2.3.2开始,多线程编码会自动启用,并且可以通过OPJu NUMu THREADS环境变量或GDALu NUMu THREADS配置选项进行控制。

两种多线程机制可以结合在一起。

期权

以下打开选项可用:

  • STRICT=YES/NO: (GDAL >= 3.5 and OpenJPEG >= 2.5) Whether strict/pedantic decoding mode should be enabled. This can be set to NO to allow decoding (some) broken files, typically truncated single-tiled files . Default to YES (strict mode)

  • 1BIT_ALPHA_PROMOTION=YES/NO :是否应将1位alpha通道提升为8位。默认为“是”。

  • GEOREF_SOURCES=string :(GDAL>2.2)定义允许哪些地理参考源及其优先级顺序。见 Georeferencing 段落。

  • USE_TILE_AS_BLOCK=YES/NO :(GDAL>2.2)是否始终使用JPEG-2000块大小作为GDAL块大小默认为否。在执行整个图像解压缩和图像单平铺时,设置此选项非常有用。但是请注意,磁贴大小不能超过2 GB,因为这是GDAL支持的限制。

创建选项

  • CODEC=JP2/J2K :JP2将在码流数据周围添加JP2框。该值由文件扩展名自动确定。如果既不是JP2也不是J2K,则使用J2K编解码器。

  • GMLJP2=YES/NO :指示文件中是否应包含符合JPEG2000规范中OGC GML的GML框。除非使用GMLJP2V2_DEF,否则GMLJP2框的版本将为版本1。默认为“是”。

  • GMLJP2V2_DEF=filename :表示GML框是否符合 OGC GML in JPEG2000, version 2.0.1 文件中应包含规范。 文件名 必须指向一个包含JSon内容的文件,该文件定义了如何构建GMLJP2 v2框。有关JSon配置文件的语法,请参见以下部分。还可以直接传递作为字符串内联的JSon内容。如果filename设置为YES,则将生成最小实例。注:GDAL2.0和2.1使用旧版本 OGC GML in JPEG2000, version 2.0 规范,其本质不同于gmljp2:GMLJP2CoverageCollection的gml:domainSet、gml:rangeSet和gmlcov:rangeType元素的内容。

  • GeoJP2=YES/NO :指示文件中是否应包含符合GeoJP2(JPEG2000中的GeoTIFF)规范的UUID/GeoTIFF框。默认为“是”。

  • QUALITY=float_value,float_value,... :0到100之间的百分比。值50表示文件大小为未压缩数据的一半,33表示1/3,以此类推。。默认值为25(除非数据集是由带有颜色表的单个带组成的,在这种情况下,默认质量为100)。可以指定多个质量值(逗号分隔)来要求多个质量层。质量值应该增加。

  • REVERSIBLE=YES/NO :YES表示使用可逆5x3整数滤波器,不使用不可逆DWT 9-7。默认为“否”(除非数据集由带颜色表的单个带组成,在这种情况下使用可逆过滤器)。

  • RESOLUTIONS=int_value :分辨率级别数。选择默认值时,磁贴的最小概览不大于128x128。

  • BLOCKXSIZE=int_value :平铺宽度。默认为1024。

  • BLOCKYSIZE=int_value :瓷砖高度。默认为1024。

  • PROGRESSION=LRCP/RLCP/RPCL/PCRL/CPRL :进程顺序。默认为LRCP。

  • SOP=YES/NO :是指生成SOP(数据包开始)标记段。默认为否。

  • EPH=YES/NO :YES表示生成EPH(包头结束)标记段。默认为否。

  • YCBCR420=YES/NO :是,如果RGB必须重新采样到YCbCr 4:2:0。默认为“否”。

  • YCC=YES/NO : YES if RGB must be transformed to YCC color space ("MCT transform", i.e. internal transform, without visual degradation). Defaults to YES.

  • NBITS=int_value :子字节文件(1-7)、子uint16(9-15)、子uint32(17-31)的位(精度)。

  • 1BIT_ALPHA=YES/NO :是否将alpha通道编码为1位通道(当存在alpha通道时)。默认为“否”,除非INSPIREu TG=YES。启用此选项可能会导致与某些读取器的兼容性问题。在撰写本文时,那些基于MrSID JPEG2000 SDK的文件无法打开这些文件。关于ECW JPEG2000 SDK,使用有损/不可逆压缩对1位alpha信道进行解码会产生视觉伪影(使用无损编码可以)。

  • ALPHA=YES/NO :是否强制将最后一个通道编码为alpha通道。仅当该通道的颜色解释还不是Alpha时才有用。默认为“否”。

  • PROFILE=AUTO/UNRESTRICTED/PROFILE_1 :确定要使用的码流配置文件。UNRESTRICTED对应于“UNRESTRICTED JPEG 2000 Part 1码流”(RSIZ=0)。PROFILE_1对应于“JPEG 2000第1部分PROFILE 1码流”(RSIZ=2),该码流增加了平铺尺寸和分辨率数量的限制。在自动模式下,驾驶员将确定BLOCKXSIZE、BLOCKYSIZE、RESOLUTIONS、CODEBLOCK_WIDTH和CODEBLOCK_HEIGHT值是否与PROFILE_1兼容,并在相关案例中公布。请注意,这些选项的默认值与概要文件1兼容。否则不受限制的广告。默认为自动。

  • INSPIRE_TG=YES/NO :是否使用符合 Inspire Orthoimagery Technical Guidelines . 默认为“否”。设置为“是”时,表示PROFILE=PROFILE_1,1BIT_ALPHA=YES,geoboxs_AFTER_JP2C=YES。CODEC、BLOCKXSIZE、BLOCKYSIZE、RESOLUTIONS、NBITS、PROFILE、CODEBLOCK_WIDTH和CODEBLOCK_HEIGHT选项将根据技术指南的要求和建议进行检查。

  • JPX=YES/NO :在编写GMLJP2框时,是否公布JPX特性,并添加一个Reader requirement框。默认为“是”。除非与读取器发生兼容性问题,否则不应使用此选项。

  • GEOBOXES_AFTER_JP2C=YES/NO :是否在码流后放置GeoJP2/GMLJP2框。默认为“否”,除非INSPIREu TG=YES。除非与读取器发生兼容性问题,否则不应使用此选项。

  • PRECINCTS={prec_w,prec_h},{prec_w,prec_h},...: A list of {precincts width,precincts height} tuples to specify precincts size. Each value should be a multiple of 2. The maximum number of tuples used will be the number of resolutions. The first tuple corresponds to the higher resolution level, and the following ones to the lower resolution levels. If less tuples are specified, the last one is used by dividing its values by 2 for each extra lower resolution level. The default value used is {512,512},{256,512},{128,512},{64,512},{32,512},{16,512},{8,512},{4,512},{2,512}. An empty string may be used to disable precincts ( i.e. the default {32767,32767},{32767,32767}, ... will then be used).

  • TILEPARTS=DISABLED/RESOLUTIONS/LAYERS/COMPONENTS :是否生成瓷砖零件以及根据哪个标准生成。默认为禁用。

  • CODEBLOCK_WIDTH=int_value :Codeblock width:介于4和1024之间的两个值的幂。默认为64。注意代码块的宽度 * 代码块高度不能大于4096。为了与配置文件1兼容,代码块宽度不能大于64。

  • CODEBLOCK_HEIGHT=int_value :Codeblock height:4到1024之间两个值的幂。默认为64。注意代码块的宽度 * 代码块高度不能大于4096。为了与配置文件1兼容,代码块高度不能大于64。

  • CODEBLOCK_STYLE=string :(GDAL>=2.4和OpenJPEG>=2.3.0)代码块编码过程的样式。以下6个独立设置可以组合在一起(值应以逗号分隔):

    • BYPASS (1) :启用选择性算术编码旁路(以牺牲较大的文件大小为代价,可以显著提高编码/解码速度)

    • RESET (2) :重置编码过程边界上的上下文概率

    • TERMALL (4) :在每个编码过程中启用终止

    • VSC (8) :启用垂直因果上下文

    • PREDICTABLE (16) :启用可预测终止(有助于错误检测)

    • SEGSYM (32):启用分段符号(有助于错误检测)

    也可以通过添加所选选项(例如,“BYPASS,TERMALL”相当于“5”=1+4)来给出全局代码块样式的相应数值,而不是通过文本指定它们

    默认情况下,它们都不启用。启用它们通常会增加码流大小,但会提高编码/解码速度或弹性/错误检测。

  • PLT=YES/NO: (GDAL >= 3.1.1 and OpenJPEG >= 2.4.0) Whether to write a PLT (Packet Length) marker segment in tile-part headers. Defaults to NO.

  • TLM=YES/NO: (GDAL >= 3.4.0 and OpenJPEG >= 2.5.0) Whether to write a TLM (Tile-part Length) marker segment in main header. Defaults to NO.

  • WRITE_METADATA=YES/NO :是否应将元数据写入专用的JP2“xml”框中。默认为否。“xml”框的内容如下:

    <GDALMultiDomainMetadata>
      <Metadata>
        <MDI key="foo">bar</MDI>
      </Metadata>
      <Metadata domain='aux_domain'>
        <MDI key="foo">bar</MDI>
      </Metadata>
      <Metadata domain='a_xml_domain' format='xml'>
        <arbitrary_xml_content>
        </arbitrary_xml_content>
      </Metadata>
    </GDALMultiDomainMetadata>
    

    如果有名称以“xml:BOX”开头的元数据域,它们将分别作为单独的JP2“xml”框写入。

    如果有一个名为“xml:XMP”的元数据域,它的内容将作为JP2“uuid”XMP框写入。

    如果有一个名为“xml:IPR”的元数据域,它的内容将被写为JP2'jp2i'框。

  • MAIN_MD_DOMAIN_ONLY=YES/NO :(仅当WRITE_METADATA=YES时)是否应仅写入主域中的元数据。默认为否。

  • USE_SRC_CODESTREAM=YES/NO :(实验性的!)当源数据集为JPEG2000时,是否重用未修改的源数据集的码流。默认为NO。请注意,启用该功能可能会导致JP2 box w.r.t.的内容与源代码流的内容不一致。在该模式下,大多数其他创建选项将被忽略。在某些用例中添加/更正地理参考、元数据。。。INSPIREu TG和PROFILE选项将被忽略,并且码流的配置文件将被选项指定/暗示的配置文件覆盖(这可能与码流的特征不一致)。

无损压缩

如果定义了以下所有创建选项,则可以实现无损压缩:

  • 质量=100

  • 可逆=是

  • YCBCR420=否(默认)

GMLJP2v2定义文件

GMLJP2v2框通常包含带有SRS信息和地理转换矩阵的GMLJP2RecitivedGridCoverage。还可以添加元数据、矢量特征(GML特征集合)、注释(KML)、样式(通常是SLD或其他XML格式)或任何XML内容作为扩展。GMLJP2V2_DEF creation选项的值应该是符合以下语法的文件(以“35;”开头的元素是文档,可以省略):

{
    "#doc" : "Unless otherwise specified, all elements are optional",

    "#root_instance_doc": "Describe content of the GMLJP2CoverageCollection",
    "root_instance": {
        "#gml_id_doc": "Specify GMLJP2CoverageCollection gml:id. Default is ID_GMLJP2_0",
        "gml_id": "some_gml_id",

        "#grid_coverage_file_doc": [
            "External XML file, whose root might be a GMLJP2GridCoverage, ",
            "GMLJP2RectifiedGridCoverage or a GMLJP2ReferenceableGridCoverage.",
            "If not specified, GDAL will auto-generate a GMLJP2RectifiedGridCoverage" ],
        "grid_coverage_file": "gmljp2gridcoverage.xml",

        "#grid_coverage_range_type_field_predefined_name_doc": [
            "New in GDAL 2.2",
            "One of Color, Elevation_meter or Panchromatic ",
            "to fill gmlcov:rangeType/swe:DataRecord/swe:field",
            "Only used if grid_coverage_file is not defined.",
            "Exclusive with grid_coverage_range_type_file" ],
        "grid_coverage_range_type_field_predefined_name": "Color",

        "#grid_coverage_range_type_file_doc": [
            "New in GDAL 2.2",
            "File that is XML content to put under gml:RectifiedGrid/gmlcov:rangeType",
            "Only used if grid_coverage_file is not defined.",
            "Exclusive with grid_coverage_range_type_field_predefined_name" ],
        "grid_coverage_range_type_file": "grid_coverage_range_type.xml",

        "#crs_url_doc": [
            "true for http://www.opengis.net/def/crs/EPSG/0/XXXX CRS URL.",
            "If false, use CRS URN. Default value is true",
            "Only taken into account for a auto-generated GMLJP2RectifiedGridCoverage"],
        "crs_url": true,

        "#metadata_doc": [ "An array of metadata items. Can be either strings, with ",
                           "a filename or directly inline XML content, or either ",
                           "a more complete description." ],
        "metadata": [

            "dcmetadata.xml",

            {
                "#file_doc": "Can use relative or absolute paths. Exclusive of content, gdal_metadata and generated_metadata.",
                "file": "dcmetadata.xml",

                "#gdal_metadata_doc": "Whether to serialize GDAL metadata as GDALMultiDomainMetadata",
                "gdal_metadata": false,

                "#dynamic_metadata_doc":
                    [ "The metadata file will be generated from a template and a source file.",
                      "The template is a valid GMLJP2 metadata XML tree with placeholders like",
                      "{{{XPATH(some_xpath_expression)}}}",
                      "that are evaluated from the source XML file. Typical use case",
                      "is to generate a gmljp2:eopMetadata from the XML metadata",
                      "provided by the image provider in their own particular format." ],
                "dynamic_metadata" :
                {
                    "template": "my_template.xml",
                    "source": "my_source.xml"
                },

                "#content": "Exclusive of file. Inline XML metadata content",
                "content": "<gmljp2:metadata>Some simple textual metadata</gmljp2:metadata>",

                "#parent_node": ["Where to put the metadata.",
                                 "Under CoverageCollection (default) or GridCoverage" ],
                "parent_node": "CoverageCollection"
            }
        ],

        "#annotations_doc": [ "An array of filenames, either directly KML files",
                              "or other vector files recognized by GDAL that ",
                              "will be translated on-the-fly as KML" ],
        "annotations": [
            "my.kml"
        ],

        "#gml_filelist_doc" :[
            "An array of GML files or vector files that will be on-the-fly converted",
            "to GML 3.2. Can be either GML filenames (or other OGR datasource names), ",
            "or a more complete description" ],
        "gml_filelist": [

            "my.gml",

            "my.shp",

            {
                "#file_doc": "OGR datasource. Can use relative or absolute paths. Exclusive of remote_resource",
                "file": "converted/test_0.gml",

                "#remote_resource_doc": "URL of a feature collection that must be referenced through a xlink:href",
                "remote_resource": "https://github.com/OSGeo/gdal/blob/master/autotest/ogr/data/expected_gml_gml32.gml",

                "#namespace_doc": ["The namespace in schemaLocation for which to substitute",
                                  "its original schemaLocation with the one provided below.",
                                  "Ignored for a remote_resource"],
                "namespace": "http://example.com",

                "#schema_location_doc": ["Value of the substituted schemaLocation. ",
                                         "Typically a schema box label (link)",
                                         "Ignored for a remote_resource"],
                "schema_location": "gmljp2://xml/schema_0.xsd",

                "#inline_doc": [
                    "Whether to inline the content, or put it in a separate xml box. Default is true",
                    "Ignored for a remote_resource." ],
                "inline": true,

                "#parent_node": ["Where to put the FeatureCollection.",
                                 "Under CoverageCollection (default) or GridCoverage" ],
                "parent_node": "CoverageCollection"
            }
        ],


        "#styles_doc": [ "An array of styles. For example SLD files" ],
        "styles" : [
            {
                "#file_doc": "Can use relative or absolute paths.",
                "file": "my.sld",

                "#parent_node": ["Where to put the FeatureCollection.",
                                 "Under CoverageCollection (default) or GridCoverage" ],
                "parent_node": "CoverageCollection"
            }
        ],

        "#extensions_doc": [ "An array of extensions." ],
        "extensions" : [
            {
                "#file_doc": "Can use relative or absolute paths.",
                "file": "my.xml",

                "#parent_node": ["Where to put the FeatureCollection.",
                                 "Under CoverageCollection (default) or GridCoverage" ],
                "parent_node": "CoverageCollection"
            }
        ]
    },

    "#boxes_doc": "An array to describe the content of XML asoc boxes",
    "boxes": [
        {
            "#file_doc": "can use relative or absolute paths. Required",
            "file": "converted/test_0.xsd",

            "#label_doc": ["the label of the XML box. If not specified, will be the ",
                          "filename without the directory part." ],
            "label": "schema_0.xsd"
        }
    ]
}

元数据可以从模板文件(在该上下文中,使用XML结构)和XML源文件动态生成。模板文件的处理方法是搜索{{XPATH(XPATH-expr)}}}等模式,并用它们对源文件内容的求值替换它们。xpath_expr必须是与xpath 1.0兼容的表达式,并添加以下函数:

  • if(cond_expr,expr_if_true,expr_if_false) :如果cond_expr的计算结果为true,则返回expr_if_true。否则返回expru ifu false

  • UUID() :计算为随机UUID

可以找到处理昴宿星图像XML元数据的模板文件 here ,可以找到一个模板文件来处理GeoEye/worldwiew图像的XML元数据 here .

矢量信息

包含GMLJP2 v2框的JPEG2000文件,其中嵌入了GML功能集合和/或KML注释,可以用OGR API作为矢量文件打开。例如:

ogrinfo -ro my.jp2

INFO: Open of my.jp2'
      using driver `JP2OpenJPEG' successful.
1: FC_GridCoverage_1_rivers (LineString)
2: FC_GridCoverage_1_borders (LineString)
3: Annotation_1_poly

功能集合可以从GMLJP2 v2框链接到远程位置。默认情况下,不遵循链接。如果打开选项open_REMOTE_GML设置为YES,则会执行此操作。

也见

其他JPEG2000 GDAL驱动程序: