summaryrefslogtreecommitdiffstats
path: root/tkimg/tests/bmp.test
blob: 9796cfcf2d2f45ce9c0ee4b96a26321fcd1b8550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# This file is a Tcl script to test out BMP reading and writing.
# It is organized in the standard fashion for Tcl tests.
#

if {[string compare test [info procs test]] == 1} {
    source defs
}

set bmpdata \
{Qk12AgAAAAAAADYAAAAoAAAAEAAAAAwAAAABABgAAAAAAEACAABtCwAAbQsAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA2dnZ2dnZ2dnZAAAAgP/w
gP/wgP/wgP/wgP/wgP/wgP/wgP/wgP/wgP/wgP/wAAAA2dnZ2dnZ2dnZAAAAgP/wgP/wgP/w
gP/wgP/wgP/wgP/wgP/wgP/wgP/wgP/wAAAA2dnZ2dnZ2dnZAAAAgP/wgP/wgP/wgP/wgP/w
gP/wgP/wgP/wgP/wgP/wgP/wAAAA2dnZ2dnZ2dnZAAAAgP/wgP/wgP/wgP/wgP/wgP/wgP/w
gP/wgP/wgP/wgP/wAAAA2dnZ2dnZ2dnZAAAAgP/wgP/wgP/wgP/wgP/wgP/wgP/wgP/wgP/w
gP/wgP/wAAAA2dnZ2dnZ2dnZAAAAgP/wgP/wgP/wgP/wgP/wgP/wgP/wgP/wgP/wgP/wgP/w
AAAA2dnZ2dnZ2dnZAAAAgP/wgP/wgP/wgP/wgP/wgP/wgP/wgP/wgP/wgP/wgP/wAAAA2dnZ
2dnZ2dnZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA2dnZ2dnZ2dnZ
2dnZAAAAgP/wgP/wgP/wgP/wgP/wgP/wAAAA2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ
AAAAgP/wgP/wgP/wgP/wAAAA2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZAAAA
AAAAAAAAAAAA2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ}

catch {image delete i}
test bmp-1.1 {} {
    image create photo i -file folder.bmp
    i data -format bmp
} $bmpdata
test bmp-1.2 {} {
    catch {image delete i}
    image create photo i -data $bmpdata
    set data [i data -format bmp]
} $bmpdata
test bmp-1.3 {} {
    i blank
    i put $bmpdata
    set data [i data -format bmp]
} $bmpdata
test bmp-1.4 {} {
    i blank
    i put $bmpdata -format bmp
    set data [i data -format bmp]
} $bmpdata
if {[info tclversion] < 8.0} {
    return
}

test bmp-2.0 {Binary I/O with BMP images} {
    i blank
    set f [open folder.bmp r]
    fconfigure $f -translation binary
    set return [catch {i put [read $f]} msg]
    close $f
    lappend return $msg
} {0 {}}

test bmp-2.1 {Save with given aspect ratio} {
    i blank
    i put $bmpdata -format bmp
    i write folder_out.bmp -format {bmp -resolution {300 100}}
    set f [open folder_out.bmp r]
    fconfigure $f -translation binary
    binary scan [read $f] x38i2 xyres
    set return [read $f]
    close $f
    set xyres
} {2925 975}

test bmp-2.2 {Save with constant resolution of 300 dpi} {
    i blank
    i put $bmpdata -format bmp
    i write folder_out.bmp -format {bmp -resolution {300 i}}
    set f [open folder_out.bmp r]
    fconfigure $f -translation binary
    binary scan [read $f] x38i2 xyres
    set return [read $f]
    close $f
    set xyres
} {11811 11811}

test bmp-2.3 {Save with given resolution of x 100dpi and y 50dpi} {
    i blank
    i put $bmpdata -format bmp
    i write folder_out.bmp -format {bmp -resolution {100 50 i}}
    set f [open folder_out.bmp r]
    fconfigure $f -translation binary
    binary scan [read $f] x38i2 xyres
    set return [read $f]
    close $f
    set xyres
} {3937 1969}
catch {file delete folder_out.bmp}