PAWT 1.1.4 Reference Manual

::pawt::rawTop, Main, Index

CommandsTop, Main, Index

ReadImageFile [::pawt::raw]Top, Main, Index

Read a RAW image file into a dictionary.

ReadImageFile rawImgFile ?args?
Parameters
rawImgFileFile name of the RAW image.
argsOptional format specific arguments described below.
-byteorder <string>Motorola for big-endian, Intel for little-endian architecture.
-height <int>Height of the image in pixel.
-nchan <int>Number of channels contained in the image.
-numchan <int>Number of channels contained in the image.
-pixeltype <string>byte for 1-byte unsigned integers, short for 2-byte unsigned integers, int for 4-byte unsigned integers, float for 4-byte single precision floating point values. double for 8-byte double precision floating point values.
-scanorder <string>TopDown or BottomUp.
-skipbytes <int>Skip number of bytes before reading image data. Only valid, if -useheader is false.
-useheader <bool>Use RAW image header.
-width <int>Width of the image in pixel.
Description

The above specified format options can be used to interpret any binary data as an image. Set -useheaderto false and specify the other parameters accordingly.

Get the image data as a dictionary containing 2 keys: Header and Data.

Return value

Returns the image information as a dictionary. If the file does not exist or no supported image format can be detected, an error is thrown.

See also

ReadImageHeader, WriteImageFile

proc ::pawt::raw::ReadImageFile {rawImgFile args} {

    # Read a RAW image file into a dictionary.
    #
    # rawImgFile - File name of the RAW image.
    # args       - Optional format specific arguments described below.
    #
    # -useheader <bool>   - Use RAW image header.
    # -skipbytes <int>    - Skip number of bytes before reading image data.
    #                       Only valid, if `-useheader` is false.
    # -width <int>        - Width of the image in pixel.
    # -height <int>       - Height of the image in pixel.
    # -numchan <int>      - Number of channels contained in the image.
    # -nchan <int>        - Number of channels contained in the image.
    # -byteorder <string> - `Motorola` for big-endian, `Intel` for little-endian architecture.
    # -scanorder <string> - `TopDown` or `BottomUp`.
    # -pixeltype <string> - `byte`   for 1-byte unsigned integers,
    #                       `short`  for 2-byte unsigned integers,
    #                       `int`    for 4-byte unsigned integers,
    #                       `float`  for 4-byte single precision floating point values.
    #                       `double` for 8-byte double precision floating point values.
    #
    # The above specified format options can be used to interpret any binary data as an image.
    # Set `-useheader`to false and specify the other parameters accordingly.
    #
    # Get the image data as a dictionary containing 2 keys: `Header` and `Data`.
    # * See [::pawt::ReadImageHeader] for the entries of the `Header` key.
    # * See [::pawt::ReadImageFile] for the entries of the `Data` key.
    #
    # Returns the image information as a dictionary.
    # If the file does not exist or no supported image format can be detected,
    # an error is thrown.
    #
    # See also: ReadImageHeader WriteImageFile

    set retVal [catch {open $rawImgFile "r"} fp]
    if { $retVal != 0 } {
        error "Cannot open file $rawImgFile"
    }
    fconfigure $fp -translation binary

    set imgDict [dict create]
    if { [llength $args] == 0 } {
        set headerDict [_GetImageHeader $fp [file tail $rawImgFile]]
    } else {
        set headerDict [_CreateHeaderDictFromOptions $rawImgFile {*}$args]
        if { [dict size $headerDict] == 0 } {
            # Option -useheader in args was set to true, so read the header.
            set headerDict [_GetImageHeader $fp [file tail $rawImgFile]]
        }
    }
    set useHeader true
    set skipBytes 0

    foreach { key val } $args {
        switch -exact -- $key {
            "-useheader" {
                set useHeader $val
            }
            "-skipbytes" {
                set skipBytes [expr int($val)]
            }
        }
    }
    if { $skipBytes < 0 || $useHeader } {
        set skipBytes 0
    }
    _GetImageData $fp $headerDict imgDict $skipBytes
    dict append imgDict Header $headerDict

    close $fp
    return $imgDict
}

ReadImageHeader [::pawt::raw]Top, Main, Index

Read the header of a RAW image file.

ReadImageHeader rawImgFile ?args?
Parameters
rawImgFileFile name of the RAW image.
argsOptional format specific arguments. Currently none.
Description

See ::pawt::ReadImageHeader for the default entries of a header dictionary.

Return value

Returns the header information as a dictionary. If the file does not exist or the header contains invalid information, an error is thrown.

See also

ReadImageFile, WriteImageFile

proc ::pawt::raw::ReadImageHeader {rawImgFile args} {

    # Read the header of a RAW image file.
    #
    # rawImgFile - File name of the RAW image.
    # args       - Optional format specific arguments. Currently none.
    #
    # See [::pawt::ReadImageHeader] for the default entries of a
    # header dictionary.
    #
    # Returns the header information as a dictionary.
    # If the file does not exist or the header contains invalid information,
    # an error is thrown.
    #
    # See also: ReadImageFile WriteImageFile

    set retVal [catch {open $rawImgFile "r"} fp]
    if { $retVal != 0 } {
        error "Cannot open file $rawImgFile"
    }
    fconfigure $fp -translation binary
    set headerDict [_GetImageHeader $fp [file tail $rawImgFile]]
    close $fp
    return $headerDict
}

WriteImageFile [::pawt::raw]Top, Main, Index

Write the values of an image dict into a RAW image file.

WriteImageFile imgDict rawImgFile ?args?
Parameters
imgDictImage dictionary.
rawImgFileFile name of the image.
argsOptional format specific arguments described below.
-scanorder <string>Store image data in row order TopDown or BottomUp. If option is not specified, the ScanOrder value of the dictionary is used.
-useheader <bool>Write RAW image header. If option is not specified, a RAW image header is written.
Description

See ::pawt::WriteImageFile for general informations regarding writing images.

Return value

Returns no value. If invalid options are specified or the file could not be written, an error is thrown.

See also

ReadImageFile, ReadImageHeader

proc ::pawt::raw::WriteImageFile {imgDict rawImgFile args} {

    # Write the values of an image dict into a RAW image file.
    #
    # imgDict    - Image dictionary.
    # rawImgFile - File name of the image.
    # args       - Optional format specific arguments described below.
    #
    # -useheader <bool>   - Write RAW image header.
    #                       If option is not specified, a RAW image header is written.
    # -scanorder <string> - Store image data in row order `TopDown` or `BottomUp`.
    #                       If option is not specified, the `ScanOrder` value of
    #                       the dictionary is used.
    #
    # See [::pawt::WriteImageFile] for general informations regarding writing images.
    #
    # Returns no value. If invalid options are specified or the file could not
    # be written, an error is thrown.
    #
    # See also: ReadImageFile ReadImageHeader

    set opts [dict create  -useheader true  -scanorder ""  ]

    foreach { key value } $args {
        if { [dict exists $opts $key] } {
            if { $value eq "" } {
                error "WriteImageFile: No value specified for key \"$key\"."
            }
            dict set opts $key $value
        } else {
            error "WriteImageFile: Unknown option \"$key\" specified."
        }
    }

    set retVal [catch {open $rawImgFile "w"} fp]
    if { $retVal != 0 } {
        error "Cannot open output file $rawImgFile"
    }
    fconfigure $fp -translation binary

    if { [dict get $opts "-useheader"] } {
        _PutImageHeader $fp [dict get $imgDict Header] [dict get $opts "-scanorder"]
    }
    _PutImageData $fp imgDict [dict get $opts "-scanorder"]
    close $fp
}