|
|
|
SAA_imagelibFileGetInfoGets information about an image file:
You should always try to get as much information as you need in a single call, because this function actually opens the file and reads its header. SAA_imagelibFileGetInfo filename formatName description nbData type info filenameName of the image file. formatNameReturns the file format name. Use descriptionReturns the file description. Use nbNumber of information types to retrieve. infoDescArray of information types, which specify what image information to retrieve. The image library supports the following information types:
infoReturns an array containing the requested image information.Use SAA_AllocAttributeValue to allocate it. To extract information from the ExampleThis code fragment shows how to get information for an image file, load the file, apply an effect to it, and save it in another format. proc SAA_imagelibFileGetInfoExampl { filename } {
global SAA_Constants
package require SWU
package require SW
set type [SWU_listToCArray [list $SAA_Constants(SAA_IL_INFO_WIDTH) \
$SAA_Constants(SAA_IL_INFO_HEIGHT) $SAA_Constants(SAA_IL_INFO_PHOTOMETRIC) \
$SAA_Constants(SAA_IL_INFO_SAMPLES_PER_PIXEL) $SAA_Constants(SAA_IL_INFO_BITS_PER_SAMPLE) \
$SAA_Constants(SAA_IL_INFO_PLANAR_CONFIG) $SAA_Constants(SAA_IL_INFO_COMPRESSION) \
$SAA_Constants(SAA_IL_INFO_ORIENTATION) $SAA_Constants(SAA_IL_INFO_NB_IMAGES) \
$SAA_Constants(SAA_IL_INFO_PALETTE_SIZE) $SAA_Constants(SAA_IL_INFO_SAMPLE_SIZE)] Integer]
# Get image file information.
SAA_imagelibFileGetInfoLength filename formatLen descriptionLen
set info [SAA_AllocAttributeValue 11]
puts "Format length $formatLen"
puts "Description length $descriptionLen"
SAA_imagelibFileGetInfo filename formatName description 11 $type $info
# Print out image file information.
puts "Dimensions : [SW_getAttributeValue [access $info 0]] x [SW_getAttributeValue [access $info 1]]"
set tmpVal [SW_getAttributeValue [access $info 2]]
puts -nonewline "Photometric: "
switch -exact -- $tmpVal \
$SAA_Constants(SAA_IL_PHOTOMETRIC_UNDEFINED) { puts "Undefined " } \
$SAA_Constants(SAA_IL_PHOTOMETRIC_RGB) { puts "RGB "} \
$SAA_Constants(SAA_IL_PHOTOMETRIC_RGBA) { puts "RGBA "} \
$SAA_Constants(SAA_IL_PHOTOMETRIC_BGR) {puts "BGR "} \
$SAA_Constants(SAA_IL_PHOTOMETRIC_ABGR) {puts "ABGR "} \
$SAA_Constants(SAA_IL_PHOTOMETRIC_CMAP) {puts "Color Map "} \
$SAA_Constants(SAA_IL_PHOTOMETRIC_GRAY) {puts "Gray Scale "} \
$SAA_Constants(SAA_IL_PHOTOMETRIC_RED) { puts "Red " } \
$SAA_Constants(SAA_IL_PHOTOMETRIC_GREEN) {puts "Green "} \
$SAA_Constants(SAA_IL_PHOTOMETRIC_BLUE) { puts "Blue "} \
$SAA_Constants(SAA_IL_PHOTOMETRIC_ALPHA) { puts "Alpha " } \
$SAA_Constants(SAA_IL_PHOTOMETRIC_DEPTH) { puts "Depth " } \
$SAA_Constants(SAA_IL_PHOTOMETRIC_MASK) { puts "Mask " } \
$SAA_Constants(SAA_IL_PHOTOMETRIC_YUV) { puts "YUV " } \
$SAA_Constants(SAA_IL_PHOTOMETRIC_ANY) {puts "Any " }
puts "Samples Per Pixel : [SW_getAttributeValue [access $info 3]]"
puts "Bits Per Sample : [SW_getAttributeValue [access $info 4]]"
puts -nonewline "Planar Config : "
set tmpVal [SW_getAttributeValue [ access $info 5 ]]
switch -exact -- $tmpVal \
$SAA_Constants(SAA_IL_PLANARCONFIG_INTERLEAVED) { puts "Interleaved " } \
$SAA_Constants(SAA_IL_PLANARCONFIG_SEQUENTIAL) { puts "Sequential " } \
$SAA_Constants(SAA_IL_PLANARCONFIG_SEPARATE) {puts "Separate " }
puts -nonewline "Compression : "
set tmpVal [SW_getAttributeValue [ access $info 6 ] ]
switch -exact -- $tmpVal \
$SAA_Constants(SAA_IL_COMPRESSION_NONE) { puts "None " } \
$SAA_Constants(SAA_IL_COMPRESSION_RLE) { puts "Run Length " } \
$SAA_Constants(SAA_IL_COMPRESSION_LZW) { puts "LZW " } \
$SAA_Constants(SAA_IL_COMPRESSION_JPEG) {puts "Jpeg " } \
$SAA_Constants(SAA_IL_COMPRESSION_PACKBITS) { puts "PackBits " }
puts -nonewline "Orientation : "
set tmpVal [SW_getAttributeValue [access $info 7]]
switch -exact -- $tmpVal \
$SAA_Constants(SAA_IL_ORIENTATION_TOPLEFT) { puts "Top Left " } \
$SAA_Constants(SAA_IL_ORIENTATION_BOTTOMLEFT) { puts "Bottom Left " }
puts "Number Of Images : [ SW_getAttributeValue [ access $info 8] ] "
puts "Palette Size : [ SW_getAttributeValue [ access $info 9] ] "
puts "Sample Size : [ SW_getAttributeValue [ access $info 10] ]"
# Load the image file.
set bufferSize [ expr [ SW_getAttributeValue [ access $info 0] ] * \
[ SW_getAttributeValue [ access $info 1] ] * [ SW_getAttributeValue [ access $info 10] ] ]
puts "buffer size is $bufferSize"
# Allocate buffer. Usually you don't need to allocate memory for a string if it is
# not longer then 1000 characters. But in our case buffer is too long so it needs to
# allocated.
set buffer [SAA_AllocChar $bufferSize]
puts "buffer is allocated"
SAA_imagelibFileLoad filename NULL 1 [ SW_getAttributeValue [ access $info 0]] \
[ SW_getAttributeValue [ access $info 1]] $buffer NULL
puts "Image is loaded"
# Apply the OilPaint image processor.
set processor "OILPAINT"
SAA_imagelibProcExecute processor NULL \
[SW_getAttributeValue [ access $info 0]] \
[SW_getAttributeValue [ access $info 1]] \
$buffer \
[SW_getAttributeValue [ access $info 0]] \
[SW_getAttributeValue [ access $info 1]] \
$buffer
# Save file as JPG.
SW_setAttributeValue [ access $info 6] $SAA_Constants(SAA_IL_COMPRESSION_JPEG) int
set fileName "c:/temp/foo.jpg"
set format "JPEG"
puts "about to save file"
SAA_imagelibFileSave fileName format NULL [SW_getAttributeValue [ access $info 0]] \
[ SW_getAttributeValue [ access $info 1]] 11 $type $info $buffer 0 NULL
foreach item "$type $info $buffer" {
SAA_Free $item
}
}
|
|
copyright Video-Collage Inc. |