CRIMP
Check-in [6c31876011]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added read support for Richard Suchenwirth's strimj'es. See http://wiki.tcl.tk/_/search?S=strimj Plus demo (image) and docs.
Timelines: family | ancestors | descendants | both | ak-experimental
Files: files | file ages | folders
SHA1: 6c31876011e271a588d7acd5dbb08894430dcd08
User & Date: andreask 2010-08-17 22:25:45.000
Context
2010-08-18
07:03
Updated the notes a bit check-in: f496692d48 user: andreask tags: ak-experimental
2010-08-17
22:25
Added read support for Richard Suchenwirth's strimj'es. See http://wiki.tcl.tk/_/search?S=strimj Plus demo (image) and docs. check-in: 6c31876011 user: andreask tags: ak-experimental
04:49
Reorganized the high-level API to the write primitives to support writing to strings, channels, and files with common code. Further reorganized the PPM and PGM support to provide primitives as expected by the new highlevel API. Updated demos. Documentation written. check-in: d7dcfe922d user: andreask tags: ak-experimental
Changes
Unified Diff Ignore Whitespace Patch
Added demos/read_strimj.tcl.












>
>
>
>
>
>
1
2
3
4
5
6
def read_strimj {
    label {Read (strimj)}
    setup {
	show_image [crimp read strimj [fileutil::cat $dir/images/hello.strimj]]
    }
}
Changes to doc/crimp.man.
853
854
855
856
857
858
859






































860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
above.

[list_end]


[subsection {I/O commands}]
[list_begin definitions]






































[call [cmd ::crimp] [method {read tcl}] [arg pixelmatrix]]

This method takes the [arg pixelmatrix], a list of rows, with each row
a list of pixel values in the domain [lb]0..255[rb] and returns an
image of type [const grey8] whose height is the number of rows, i.e.
the length of the outer list, and whose width is the maximum length
found among the inner lists. Rows whose inner list is shorter than the
maximum length are padded with black pixels, i.e. a pixel value of
[const 255].


[call [cmd ::crimp] [method {read tk}] [arg photo]]

This method returns an image of type [const rgba] containing the data
from the specified Tk [arg photo] image.


[call [cmd ::crimp] [method {read pgm}] [arg string]]

This method returns an image of type [const grey8] containing the data
of the portable grey map (PGM) stored in the [arg string]. The method
recognizes images in both plain and raw sub-formats.


[call [cmd ::crimp] [method {read ppm}] [arg string]]

This method returns an image of type [const rgb] containing the data
of the portable pix map (PPM) stored in the [arg string]. The method
recognizes images in both plain and raw sub-formats.


[call [cmd ::crimp] [method {write 2tk}] [arg photo] [arg image]]

This method writes the input [arg image] to the specified Tk
[arg photo] image.

[para] The method supports the writing of [const rgb], [const rgba],







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
















<
<
<
<
<
<
<
<
<
<
<
<
<
<







853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913














914
915
916
917
918
919
920
above.

[list_end]


[subsection {I/O commands}]
[list_begin definitions]
[call [cmd ::crimp] [method {read pgm}] [arg string]]

This method returns an image of type [const grey8] containing the data
of the portable grey map (PGM) stored in the [arg string]. The method
recognizes images in both plain and raw sub-formats.


[call [cmd ::crimp] [method {read ppm}] [arg string]]

This method returns an image of type [const rgb] containing the data
of the portable pix map (PPM) stored in the [arg string]. The method
recognizes images in both plain and raw sub-formats.


[call [cmd ::crimp] [method {read strimj}] [arg string] [opt [arg colormap]]]

This method returns an image of type [const rgba] containing the data
of the [term strimj] (string image) (See [uri http://wiki.tcl.tk/1846])
stored in the [arg string].

[para] The caller can override the standard mapping from pixel characters
to colors by specifying a [arg colormap]. This argument is interpreted as
dictionary mapping characters to triples of integers in the range
[lb]0...255[rb], specifying the red, green, and blue intensities.

[para] An example of a strimj is:
[example {
@...@.......@.@......
@...@.......@.@......
@...@..@@@..@.@..@@@.
@@@@@.@...@.@.@.@...@
@...@.@@@@@.@.@.@...@
@...@.@.....@.@.@...@
@...@.@...@.@.@.@...@
@...@..@@@..@.@..@@@.
}]


[call [cmd ::crimp] [method {read tcl}] [arg pixelmatrix]]

This method takes the [arg pixelmatrix], a list of rows, with each row
a list of pixel values in the domain [lb]0..255[rb] and returns an
image of type [const grey8] whose height is the number of rows, i.e.
the length of the outer list, and whose width is the maximum length
found among the inner lists. Rows whose inner list is shorter than the
maximum length are padded with black pixels, i.e. a pixel value of
[const 255].


[call [cmd ::crimp] [method {read tk}] [arg photo]]

This method returns an image of type [const rgba] containing the data
from the specified Tk [arg photo] image.
















[call [cmd ::crimp] [method {write 2tk}] [arg photo] [arg image]]

This method writes the input [arg image] to the specified Tk
[arg photo] image.

[para] The method supports the writing of [const rgb], [const rgba],
Changes to embedded/man/files/crimp.n.
1
2
3
4
5
6
7
8
9
'\"
'\" Generated from file '/home/aku/Projects/Tcl/Crimp/Devel/embedded/man/files/crimp.n' by tcllib/doctools with format 'nroff'
'\" Copyright (c) 2010 Andreas Kupries
'\" Copyright (c) 2010 Documentation, Andreas Kupries
'\"
'\" The definitions below are for supplemental macros used in Tcl/Tk
'\" manual entries.
'\"
'\" .AP type name in/out ?indent?

|







1
2
3
4
5
6
7
8
9
'\"
'\" Generated from file '/net/nas/data/andreask/trans/tim-ak/cr/dev/embedded/man/files/crimp.n' by tcllib/doctools with format 'nroff'
'\" Copyright (c) 2010 Andreas Kupries
'\" Copyright (c) 2010 Documentation, Andreas Kupries
'\"
'\" The definitions below are for supplemental macros used in Tcl/Tk
'\" manual entries.
'\"
'\" .AP type name in/out ?indent?
340
341
342
343
344
345
346
347
348
349
350
351
352
353






354
355
356
357
358
359
360
.sp
\fB::crimp\fR \fBjoin 2rgba\fR \fIredImage\fR \fIgreenImage\fR \fIblueImage\fR \fIalphaImage\fR
.sp
\fB::crimp\fR \fBjoin 2rgb\fR \fIredImage\fR \fIgreenImage\fR \fIblueImage\fR
.sp
\fB::crimp\fR \fBsplit\fR \fIimage\fR
.sp
\fB::crimp\fR \fBread tcl\fR \fIpixelmatrix\fR
.sp
\fB::crimp\fR \fBread tk\fR \fIphoto\fR
.sp
\fB::crimp\fR \fBread pgm\fR \fIstring\fR
.sp
\fB::crimp\fR \fBread ppm\fR \fIstring\fR






.sp
\fB::crimp\fR \fBwrite 2tk\fR \fIphoto\fR \fIimage\fR
.sp
\fB::crimp\fR \fBwrite 2string\fR \fIformat\fR \fIimage\fR
.sp
\fB::crimp\fR \fBwrite 2chan\fR \fIformat\fR \fIchan\fR \fIimage\fR
.sp







<
<
<
<



>
>
>
>
>
>







340
341
342
343
344
345
346




347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
.sp
\fB::crimp\fR \fBjoin 2rgba\fR \fIredImage\fR \fIgreenImage\fR \fIblueImage\fR \fIalphaImage\fR
.sp
\fB::crimp\fR \fBjoin 2rgb\fR \fIredImage\fR \fIgreenImage\fR \fIblueImage\fR
.sp
\fB::crimp\fR \fBsplit\fR \fIimage\fR
.sp




\fB::crimp\fR \fBread pgm\fR \fIstring\fR
.sp
\fB::crimp\fR \fBread ppm\fR \fIstring\fR
.sp
\fB::crimp\fR \fBread strimj\fR \fIstring\fR ?\fIcolormap\fR?
.sp
\fB::crimp\fR \fBread tcl\fR \fIpixelmatrix\fR
.sp
\fB::crimp\fR \fBread tk\fR \fIphoto\fR
.sp
\fB::crimp\fR \fBwrite 2tk\fR \fIphoto\fR \fIimage\fR
.sp
\fB::crimp\fR \fBwrite 2string\fR \fIformat\fR \fIimage\fR
.sp
\fB::crimp\fR \fBwrite 2chan\fR \fIformat\fR \fIchan\fR \fIimage\fR
.sp
1193
1194
1195
1196
1197
1198
1199


































1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
the channels found in the input image.
.sp
The channel images in the result are provided in the same order as
they are accepted by the complementary \fBjoin\fR method, see
above.
.PP
.SS "I/O COMMANDS"


































.TP
\fB::crimp\fR \fBread tcl\fR \fIpixelmatrix\fR
This method takes the \fIpixelmatrix\fR, a list of rows, with each row
a list of pixel values in the domain [0..255] and returns an
image of type \fBgrey8\fR whose height is the number of rows, i.e.
the length of the outer list, and whose width is the maximum length
found among the inner lists. Rows whose inner list is shorter than the
maximum length are padded with black pixels, i.e. a pixel value of
\fB255\fR.
.TP
\fB::crimp\fR \fBread tk\fR \fIphoto\fR
This method returns an image of type \fBrgba\fR containing the data
from the specified Tk \fIphoto\fR image.
.TP
\fB::crimp\fR \fBread pgm\fR \fIstring\fR
This method returns an image of type \fBgrey8\fR containing the data
of the portable grey map (PGM) stored in the \fIstring\fR. The method
recognizes images in both plain and raw sub-formats.
.TP
\fB::crimp\fR \fBread ppm\fR \fIstring\fR
This method returns an image of type \fBrgb\fR containing the data
of the portable pix map (PPM) stored in the \fIstring\fR. The method
recognizes images in both plain and raw sub-formats.
.TP
\fB::crimp\fR \fBwrite 2tk\fR \fIphoto\fR \fIimage\fR
This method writes the input \fIimage\fR to the specified Tk
\fIphoto\fR image.
.sp
The method supports the writing of \fBrgb\fR, \fBrgba\fR,
and \fBgrey8\fR images.
.TP







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>














<
<
<
<
<
<
<
<
<
<







1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249










1250
1251
1252
1253
1254
1255
1256
the channels found in the input image.
.sp
The channel images in the result are provided in the same order as
they are accepted by the complementary \fBjoin\fR method, see
above.
.PP
.SS "I/O COMMANDS"
.TP
\fB::crimp\fR \fBread pgm\fR \fIstring\fR
This method returns an image of type \fBgrey8\fR containing the data
of the portable grey map (PGM) stored in the \fIstring\fR. The method
recognizes images in both plain and raw sub-formats.
.TP
\fB::crimp\fR \fBread ppm\fR \fIstring\fR
This method returns an image of type \fBrgb\fR containing the data
of the portable pix map (PPM) stored in the \fIstring\fR. The method
recognizes images in both plain and raw sub-formats.
.TP
\fB::crimp\fR \fBread strimj\fR \fIstring\fR ?\fIcolormap\fR?
This method returns an image of type \fBrgba\fR containing the data
of the \fIstrimj\fR (string image) (See \fIhttp://wiki.tcl.tk/1846\fR)
stored in the \fIstring\fR.
.sp
The caller can override the standard mapping from pixel characters
to colors by specifying a \fIcolormap\fR. This argument is interpreted as
dictionary mapping characters to triples of integers in the range
[0...255], specifying the red, green, and blue intensities.
.sp
An example of a strimj is:
.nf

@...@.......@.@......
@...@.......@.@......
@...@..@@@..@.@..@@@.
@@@@@.@...@.@.@.@...@
@...@.@@@@@.@.@.@...@
@...@.@.....@.@.@...@
@...@.@...@.@.@.@...@
@...@..@@@..@.@..@@@.

.fi
.TP
\fB::crimp\fR \fBread tcl\fR \fIpixelmatrix\fR
This method takes the \fIpixelmatrix\fR, a list of rows, with each row
a list of pixel values in the domain [0..255] and returns an
image of type \fBgrey8\fR whose height is the number of rows, i.e.
the length of the outer list, and whose width is the maximum length
found among the inner lists. Rows whose inner list is shorter than the
maximum length are padded with black pixels, i.e. a pixel value of
\fB255\fR.
.TP
\fB::crimp\fR \fBread tk\fR \fIphoto\fR
This method returns an image of type \fBrgba\fR containing the data
from the specified Tk \fIphoto\fR image.
.TP










\fB::crimp\fR \fBwrite 2tk\fR \fIphoto\fR \fIimage\fR
This method writes the input \fIimage\fR to the specified Tk
\fIphoto\fR image.
.sp
The method supports the writing of \fBrgb\fR, \fBrgba\fR,
and \fBgrey8\fR images.
.TP
Changes to embedded/www/files/crimp.html.
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    }
    UL.requirements {
	margin-bottom: 	1em;
	border-bottom:	1px solid black;
    }
--></style>
</head>
<! -- Generated from file '/home/aku/Projects/Tcl/Crimp/Devel/embedded/www/files/crimp.html' by tcllib/doctools with format 'html'
   -->
<! -- Copyright &copy; 2010 Andreas Kupries   -- Copyright &copy; 2010 Documentation, Andreas Kupries
   -->
<! -- CVS: $Id$ crimp.n
   -->
<body><div class="doctools">
<hr> [







|







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    }
    UL.requirements {
	margin-bottom: 	1em;
	border-bottom:	1px solid black;
    }
--></style>
</head>
<! -- Generated from file '/net/nas/data/andreask/trans/tim-ak/cr/dev/embedded/www/files/crimp.html' by tcllib/doctools with format 'html'
   -->
<! -- Copyright &copy; 2010 Andreas Kupries   -- Copyright &copy; 2010 Documentation, Andreas Kupries
   -->
<! -- CVS: $Id$ crimp.n
   -->
<body><div class="doctools">
<hr> [
179
180
181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206

207
208
209
210
211
212
213
<li><a href="#41"><b class="cmd">::crimp</b> <b class="method">convert 2hsv</b> <i class="arg">image</i></a></li>
<li><a href="#42"><b class="cmd">::crimp</b> <b class="method">convert 2rgba</b> <i class="arg">image</i></a></li>
<li><a href="#43"><b class="cmd">::crimp</b> <b class="method">convert 2rgb</b> <i class="arg">image</i></a></li>
<li><a href="#44"><b class="cmd">::crimp</b> <b class="method">join 2hsv</b> <i class="arg">hueImage</i> <i class="arg">satImage</i> <i class="arg">valImage</i></a></li>
<li><a href="#45"><b class="cmd">::crimp</b> <b class="method">join 2rgba</b> <i class="arg">redImage</i> <i class="arg">greenImage</i> <i class="arg">blueImage</i> <i class="arg">alphaImage</i></a></li>
<li><a href="#46"><b class="cmd">::crimp</b> <b class="method">join 2rgb</b> <i class="arg">redImage</i> <i class="arg">greenImage</i> <i class="arg">blueImage</i></a></li>
<li><a href="#47"><b class="cmd">::crimp</b> <b class="method">split</b> <i class="arg">image</i></a></li>
<li><a href="#48"><b class="cmd">::crimp</b> <b class="method">read tcl</b> <i class="arg">pixelmatrix</i></a></li>
<li><a href="#49"><b class="cmd">::crimp</b> <b class="method">read tk</b> <i class="arg">photo</i></a></li>
<li><a href="#50"><b class="cmd">::crimp</b> <b class="method">read pgm</b> <i class="arg">string</i></a></li>
<li><a href="#51"><b class="cmd">::crimp</b> <b class="method">read ppm</b> <i class="arg">string</i></a></li>

<li><a href="#52"><b class="cmd">::crimp</b> <b class="method">write 2tk</b> <i class="arg">photo</i> <i class="arg">image</i></a></li>
<li><a href="#53"><b class="cmd">::crimp</b> <b class="method">write 2string</b> <i class="arg">format</i> <i class="arg">image</i></a></li>
<li><a href="#54"><b class="cmd">::crimp</b> <b class="method">write 2chan</b> <i class="arg">format</i> <i class="arg">chan</i> <i class="arg">image</i></a></li>
<li><a href="#55"><b class="cmd">::crimp</b> <b class="method">write 2file</b> <i class="arg">format</i> <i class="arg">path</i> <i class="arg">image</i></a></li>
<li><a href="#56"><b class="cmd">::crimp</b> <b class="method">kernel make</b> <i class="arg">matrix</i> <span class="opt">?<i class="arg">scale</i>?</span></a></li>
<li><a href="#57"><b class="cmd">::crimp</b> <b class="method">kernel transpose</b> <i class="arg">kernel</i></a></li>
<li><a href="#58"><b class="cmd">::crimp</b> <b class="method">map</b> <i class="arg">arg</i>...</a></li>
<li><a href="#59"><b class="cmd">::crimp</b> <b class="method">table degamma</b> <i class="arg">y</i></a></li>
<li><a href="#60"><b class="cmd">::crimp</b> <b class="method">table gainw</b> <i class="arg">gain</i> <i class="arg">bias</i></a></li>
<li><a href="#61"><b class="cmd">::crimp</b> <b class="method">table gain</b> <i class="arg">gain</i> <i class="arg">bias</i></a></li>
<li><a href="#62"><b class="cmd">::crimp</b> <b class="method">table gamma</b> <i class="arg">y</i></a></li>
<li><a href="#63"><b class="cmd">::crimp</b> <b class="method">table gauss</b> <i class="arg">sigma</i></a></li>
<li><a href="#64"><b class="cmd">::crimp</b> <b class="method">table identity</b></a></li>
<li><a href="#65"><b class="cmd">::crimp</b> <b class="method">table invers</b></a></li>
<li><a href="#66"><b class="cmd">::crimp</b> <b class="method">table solarize</b> <i class="arg">threshold</i></a></li>
<li><a href="#67"><b class="cmd">::crimp</b> <b class="method">table threshold-ge</b> <i class="arg">threshold</i></a></li>
<li><a href="#68"><b class="cmd">::crimp</b> <b class="method">table threshold-le</b> <i class="arg">threshold</i></a></li>

</ul>
</div>
</div>
<div id="section1" class="section"><h2><a name="section1">Description</a></h2>
<p>This package provides image manipulation commands which are mostly
independent of Tk. The only parts currently depending on Tk are for
the import and export of images from and to Tk photos, necessary for







|
|
|
|
>
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
|
>







179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195

196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<li><a href="#41"><b class="cmd">::crimp</b> <b class="method">convert 2hsv</b> <i class="arg">image</i></a></li>
<li><a href="#42"><b class="cmd">::crimp</b> <b class="method">convert 2rgba</b> <i class="arg">image</i></a></li>
<li><a href="#43"><b class="cmd">::crimp</b> <b class="method">convert 2rgb</b> <i class="arg">image</i></a></li>
<li><a href="#44"><b class="cmd">::crimp</b> <b class="method">join 2hsv</b> <i class="arg">hueImage</i> <i class="arg">satImage</i> <i class="arg">valImage</i></a></li>
<li><a href="#45"><b class="cmd">::crimp</b> <b class="method">join 2rgba</b> <i class="arg">redImage</i> <i class="arg">greenImage</i> <i class="arg">blueImage</i> <i class="arg">alphaImage</i></a></li>
<li><a href="#46"><b class="cmd">::crimp</b> <b class="method">join 2rgb</b> <i class="arg">redImage</i> <i class="arg">greenImage</i> <i class="arg">blueImage</i></a></li>
<li><a href="#47"><b class="cmd">::crimp</b> <b class="method">split</b> <i class="arg">image</i></a></li>
<li><a href="#48"><b class="cmd">::crimp</b> <b class="method">read pgm</b> <i class="arg">string</i></a></li>
<li><a href="#49"><b class="cmd">::crimp</b> <b class="method">read ppm</b> <i class="arg">string</i></a></li>
<li><a href="#50"><b class="cmd">::crimp</b> <b class="method">read strimj</b> <i class="arg">string</i> <span class="opt">?<i class="arg">colormap</i>?</span></a></li>
<li><a href="#51"><b class="cmd">::crimp</b> <b class="method">read tcl</b> <i class="arg">pixelmatrix</i></a></li>
<li><a href="#52"><b class="cmd">::crimp</b> <b class="method">read tk</b> <i class="arg">photo</i></a></li>
<li><a href="#53"><b class="cmd">::crimp</b> <b class="method">write 2tk</b> <i class="arg">photo</i> <i class="arg">image</i></a></li>
<li><a href="#54"><b class="cmd">::crimp</b> <b class="method">write 2string</b> <i class="arg">format</i> <i class="arg">image</i></a></li>
<li><a href="#55"><b class="cmd">::crimp</b> <b class="method">write 2chan</b> <i class="arg">format</i> <i class="arg">chan</i> <i class="arg">image</i></a></li>
<li><a href="#56"><b class="cmd">::crimp</b> <b class="method">write 2file</b> <i class="arg">format</i> <i class="arg">path</i> <i class="arg">image</i></a></li>
<li><a href="#57"><b class="cmd">::crimp</b> <b class="method">kernel make</b> <i class="arg">matrix</i> <span class="opt">?<i class="arg">scale</i>?</span></a></li>

<li><a href="#58"><b class="cmd">::crimp</b> <b class="method">kernel transpose</b> <i class="arg">kernel</i></a></li>
<li><a href="#59"><b class="cmd">::crimp</b> <b class="method">map</b> <i class="arg">arg</i>...</a></li>
<li><a href="#60"><b class="cmd">::crimp</b> <b class="method">table degamma</b> <i class="arg">y</i></a></li>
<li><a href="#61"><b class="cmd">::crimp</b> <b class="method">table gainw</b> <i class="arg">gain</i> <i class="arg">bias</i></a></li>
<li><a href="#62"><b class="cmd">::crimp</b> <b class="method">table gain</b> <i class="arg">gain</i> <i class="arg">bias</i></a></li>
<li><a href="#63"><b class="cmd">::crimp</b> <b class="method">table gamma</b> <i class="arg">y</i></a></li>
<li><a href="#64"><b class="cmd">::crimp</b> <b class="method">table gauss</b> <i class="arg">sigma</i></a></li>
<li><a href="#65"><b class="cmd">::crimp</b> <b class="method">table identity</b></a></li>
<li><a href="#66"><b class="cmd">::crimp</b> <b class="method">table invers</b></a></li>
<li><a href="#67"><b class="cmd">::crimp</b> <b class="method">table solarize</b> <i class="arg">threshold</i></a></li>
<li><a href="#68"><b class="cmd">::crimp</b> <b class="method">table threshold-ge</b> <i class="arg">threshold</i></a></li>
<li><a href="#69"><b class="cmd">::crimp</b> <b class="method">table threshold-le</b> <i class="arg">threshold</i></a></li>
</ul>
</div>
</div>
<div id="section1" class="section"><h2><a name="section1">Description</a></h2>
<p>This package provides image manipulation commands which are mostly
independent of Tk. The only parts currently depending on Tk are for
the import and export of images from and to Tk photos, necessary for
819
820
821
822
823
824
825
826




























827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
<p>The channel images in the result are provided in the same order as
they are accepted by the complementary <b class="method">join</b> method, see
above.</p></dd>
</dl>
</div>
<div id="subsection4" class="subsection"><h3><a name="subsection4">I/O commands</a></h3>
<dl class="definitions">
<dt><a name="48"><b class="cmd">::crimp</b> <b class="method">read tcl</b> <i class="arg">pixelmatrix</i></a></dt>




























<dd><p>This method takes the <i class="arg">pixelmatrix</i>, a list of rows, with each row
a list of pixel values in the domain [0..255] and returns an
image of type <b class="const">grey8</b> whose height is the number of rows, i.e.
the length of the outer list, and whose width is the maximum length
found among the inner lists. Rows whose inner list is shorter than the
maximum length are padded with black pixels, i.e. a pixel value of
<b class="const">255</b>.</p></dd>
<dt><a name="49"><b class="cmd">::crimp</b> <b class="method">read tk</b> <i class="arg">photo</i></a></dt>
<dd><p>This method returns an image of type <b class="const">rgba</b> containing the data
from the specified Tk <i class="arg">photo</i> image.</p></dd>
<dt><a name="50"><b class="cmd">::crimp</b> <b class="method">read pgm</b> <i class="arg">string</i></a></dt>
<dd><p>This method returns an image of type <b class="const">grey8</b> containing the data
of the portable grey map (PGM) stored in the <i class="arg">string</i>. The method
recognizes images in both plain and raw sub-formats.</p></dd>
<dt><a name="51"><b class="cmd">::crimp</b> <b class="method">read ppm</b> <i class="arg">string</i></a></dt>
<dd><p>This method returns an image of type <b class="const">rgb</b> containing the data
of the portable pix map (PPM) stored in the <i class="arg">string</i>. The method
recognizes images in both plain and raw sub-formats.</p></dd>
<dt><a name="52"><b class="cmd">::crimp</b> <b class="method">write 2tk</b> <i class="arg">photo</i> <i class="arg">image</i></a></dt>
<dd><p>This method writes the input <i class="arg">image</i> to the specified Tk
<i class="arg">photo</i> image.</p>
<p>The method supports the writing of <b class="const">rgb</b>, <b class="const">rgba</b>,
and <b class="const">grey8</b> images.</p></dd>
<dt><a name="53"><b class="cmd">::crimp</b> <b class="method">write 2string</b> <i class="arg">format</i> <i class="arg">image</i></a></dt>
<dd></dd>
<dt><a name="54"><b class="cmd">::crimp</b> <b class="method">write 2chan</b> <i class="arg">format</i> <i class="arg">chan</i> <i class="arg">image</i></a></dt>
<dd></dd>
<dt><a name="55"><b class="cmd">::crimp</b> <b class="method">write 2file</b> <i class="arg">format</i> <i class="arg">path</i> <i class="arg">image</i></a></dt>
<dd><p>This family of methods either returns the input <i class="arg">image</i> as a
binary string in the specified <i class="arg">format</i>, or writes this string to
the open channel <i class="arg">chan</i>, or the named file at <i class="arg">path</i>.</p>
<p>The image types accepted for writing are <i class="arg">format</i>
dependent, and listed below, with the supported formats.</p>
<p>The currently supported formats are</p>
<dl class="definitions">







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







|


<
<
<
<
<
<
<
<
|




|

|

|







820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865








866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
<p>The channel images in the result are provided in the same order as
they are accepted by the complementary <b class="method">join</b> method, see
above.</p></dd>
</dl>
</div>
<div id="subsection4" class="subsection"><h3><a name="subsection4">I/O commands</a></h3>
<dl class="definitions">
<dt><a name="48"><b class="cmd">::crimp</b> <b class="method">read pgm</b> <i class="arg">string</i></a></dt>
<dd><p>This method returns an image of type <b class="const">grey8</b> containing the data
of the portable grey map (PGM) stored in the <i class="arg">string</i>. The method
recognizes images in both plain and raw sub-formats.</p></dd>
<dt><a name="49"><b class="cmd">::crimp</b> <b class="method">read ppm</b> <i class="arg">string</i></a></dt>
<dd><p>This method returns an image of type <b class="const">rgb</b> containing the data
of the portable pix map (PPM) stored in the <i class="arg">string</i>. The method
recognizes images in both plain and raw sub-formats.</p></dd>
<dt><a name="50"><b class="cmd">::crimp</b> <b class="method">read strimj</b> <i class="arg">string</i> <span class="opt">?<i class="arg">colormap</i>?</span></a></dt>
<dd><p>This method returns an image of type <b class="const">rgba</b> containing the data
of the <i class="term">strimj</i> (string image) (See <a href="http://wiki.tcl.tk/1846">http://wiki.tcl.tk/1846</a>)
stored in the <i class="arg">string</i>.</p>
<p>The caller can override the standard mapping from pixel characters
to colors by specifying a <i class="arg">colormap</i>. This argument is interpreted as
dictionary mapping characters to triples of integers in the range
[0...255], specifying the red, green, and blue intensities.</p>
<p>An example of a strimj is:</p>
<pre class="example">
@...@.......@.@......
@...@.......@.@......
@...@..@@@..@.@..@@@.
@@@@@.@...@.@.@.@...@
@...@.@@@@@.@.@.@...@
@...@.@.....@.@.@...@
@...@.@...@.@.@.@...@
@...@..@@@..@.@..@@@.
</pre>
</dd>
<dt><a name="51"><b class="cmd">::crimp</b> <b class="method">read tcl</b> <i class="arg">pixelmatrix</i></a></dt>
<dd><p>This method takes the <i class="arg">pixelmatrix</i>, a list of rows, with each row
a list of pixel values in the domain [0..255] and returns an
image of type <b class="const">grey8</b> whose height is the number of rows, i.e.
the length of the outer list, and whose width is the maximum length
found among the inner lists. Rows whose inner list is shorter than the
maximum length are padded with black pixels, i.e. a pixel value of
<b class="const">255</b>.</p></dd>
<dt><a name="52"><b class="cmd">::crimp</b> <b class="method">read tk</b> <i class="arg">photo</i></a></dt>
<dd><p>This method returns an image of type <b class="const">rgba</b> containing the data
from the specified Tk <i class="arg">photo</i> image.</p></dd>








<dt><a name="53"><b class="cmd">::crimp</b> <b class="method">write 2tk</b> <i class="arg">photo</i> <i class="arg">image</i></a></dt>
<dd><p>This method writes the input <i class="arg">image</i> to the specified Tk
<i class="arg">photo</i> image.</p>
<p>The method supports the writing of <b class="const">rgb</b>, <b class="const">rgba</b>,
and <b class="const">grey8</b> images.</p></dd>
<dt><a name="54"><b class="cmd">::crimp</b> <b class="method">write 2string</b> <i class="arg">format</i> <i class="arg">image</i></a></dt>
<dd></dd>
<dt><a name="55"><b class="cmd">::crimp</b> <b class="method">write 2chan</b> <i class="arg">format</i> <i class="arg">chan</i> <i class="arg">image</i></a></dt>
<dd></dd>
<dt><a name="56"><b class="cmd">::crimp</b> <b class="method">write 2file</b> <i class="arg">format</i> <i class="arg">path</i> <i class="arg">image</i></a></dt>
<dd><p>This family of methods either returns the input <i class="arg">image</i> as a
binary string in the specified <i class="arg">format</i>, or writes this string to
the open channel <i class="arg">chan</i>, or the named file at <i class="arg">path</i>.</p>
<p>The image types accepted for writing are <i class="arg">format</i>
dependent, and listed below, with the supported formats.</p>
<p>The currently supported formats are</p>
<dl class="definitions">
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
<p>The methods support the writing of <b class="const">rgb</b>, <b class="const">rgba</b>,
<b class="const">hsv</b>, and <b class="const">grey8</b> images.</p></dd>
</dl></dd>
</dl>
</div>
<div id="subsection5" class="subsection"><h3><a name="subsection5">Support</a></h3>
<dl class="definitions">
<dt><a name="56"><b class="cmd">::crimp</b> <b class="method">kernel make</b> <i class="arg">matrix</i> <span class="opt">?<i class="arg">scale</i>?</span></a></dt>
<dd><p>This method takes a <i class="arg">matrix</i> of weights and an optional
<i class="arg">scale</i> factor and returns a structure containing the associated
convolution kernel, ready for use by method <b class="method">convole</b>.</p>
<p>If <i class="arg">scale</i> is left unspecified it defaults to the sum of
all weights in the matrix.</p>
<p>The <i class="arg">matrix</i> has the same general format as the pixel
matrix for method <b class="method">read tcl</b>, i.e. a list of lists (rows) of
values, and is treated in the same way, i.e. the number of columns is
the maxium length over the row lists, and shorter lists are padded
with <b class="const">255</b>.</p></dd>
<dt><a name="57"><b class="cmd">::crimp</b> <b class="method">kernel transpose</b> <i class="arg">kernel</i></a></dt>
<dd><p>This method takes a <i class="arg">kernel</i> as returned by the method
<b class="method">kernel make</b> and returns a transposed kernel, i.e. one where
the x- and y-axes are switched.
For example</p>
<pre class="example">
                    (1)
                    (2)
    {1 2 4 2 1} ==&gt; (4)
                    (2)
                    (1)
</pre>
<p>This method is its own inverse, i.e. application to its result returns
the original input, i.e.</p>
<pre class="example">
    [transpose [transpose $K]] == $K
</pre>
</dd>
<dt><a name="58"><b class="cmd">::crimp</b> <b class="method">map</b> <i class="arg">arg</i>...</a></dt>
<dd><p>This method accepts the same sub-methods and arguments as are accepted
by the <b class="method">table</b> method below. In contrast to <b class="method">table</b> the
result is not a list of values, but a map image directly suitable as
argument to the <b class="method">remap</b> method.</p></dd>
<dt><a name="59"><b class="cmd">::crimp</b> <b class="method">table degamma</b> <i class="arg">y</i></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through the <b class="function">inverse gamma correction</b> with
parameter <i class="arg">y</i>.
This inverse correction, defined in the domain of [0..1] for
both argument and result, is defined as:</p>
<p><img alt="gamma_inv" src="../image/gamma_inv.png"></p>
<p>Scaling of argument and result into the domain [0..255] of pixel
values, and rounding results to the nearest integer, causes the actual
definition used to be</p>
<p><img alt="scaled_gamma_inv" src="../image/scaled_gamma_inv.png"></p></dd>
<dt><a name="60"><b class="cmd">::crimp</b> <b class="method">table gainw</b> <i class="arg">gain</i> <i class="arg">bias</i></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through a simple linear function with parameters
<i class="arg">gain</i> and <i class="arg">bias</i>. The results are rounded to the nearest
integer and forced into the domain [0..255] by wrapping them
around (modulo), making the definition:</p>
<p><img alt="linear_wrap" src="../image/linear_wrap.png"></p></dd>
<dt><a name="61"><b class="cmd">::crimp</b> <b class="method">table gain</b> <i class="arg">gain</i> <i class="arg">bias</i></a></dt>
<dd><p>This method is like <b class="method">gainw</b>, except that it deals with results
out of the domain [0..255] by clamping them to 0 and 255
respectively instead of wrapping around. I.e. its definition is</p>
<p><img alt="linear_clamp" src="../image/linear_clamp.png"></p></dd>
<dt><a name="62"><b class="cmd">::crimp</b> <b class="method">table gamma</b> <i class="arg">y</i></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through the <b class="function">gamma correction</b> with parameter
<i class="arg">y</i>.
This correction, defined in the domain of [0..1] for both
argument and result, is defined as:</p>
<p><img alt="gamma" src="../image/gamma.png"></p>
<p>Scaling of argument and result into the domain [0..255] of pixel
values, and rounding results to the nearest integer, causes the actual
definition used to be</p>
<p><img alt="scaled_gamma" src="../image/scaled_gamma.png"></p></dd>
<dt><a name="63"><b class="cmd">::crimp</b> <b class="method">table gauss</b> <i class="arg">sigma</i></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through the <b class="function">sampled gauss</b> function with
parameter <i class="arg">sigma</i>.
This function is defined as:</p>
<p><img alt="gauss" src="../image/gauss.png"></p></dd>
<dt><a name="64"><b class="cmd">::crimp</b> <b class="method">table identity</b></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through the <b class="function">identity</b> function, which is defined
as</p>
<p><img alt="identity" src="../image/identity.png"></p></dd>
<dt><a name="65"><b class="cmd">::crimp</b> <b class="method">table invers</b></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through the <b class="function">inverse</b> function, which is defined
as</p>
<p><img alt="inverse" src="../image/inverse.png"></p></dd>
<dt><a name="66"><b class="cmd">::crimp</b> <b class="method">table solarize</b> <i class="arg">threshold</i></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through the <b class="function">solarize</b> function, with parameter
<i class="arg">threshold</i>. This function is defined as:</p>
<p><img alt="solarize" src="../image/solarize.png"></p>
<p>Note how the function is the <b class="function">identity</b> for values under the
threshold, and the <b class="function">inverse</b> for values at and above it. Its
application to an image produces what is known as either
<i class="term"><a href="../index.html#key46">solarization</a></i> or <i class="term"><a href="../index.html#key40">sabattier effect</a></i>.</p></dd>
<dt><a name="67"><b class="cmd">::crimp</b> <b class="method">table threshold-ge</b> <i class="arg">threshold</i></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through a <b class="function">thresholding</b> (or <i class="term"><a href="../index.html#key48">binarization</a></i>)
function, with parameter <i class="arg">threshold</i>. This function is defined as:</p>
<p><img alt="threshold-ge" src="../image/threshold-ge.png"></p></dd>
<dt><a name="68"><b class="cmd">::crimp</b> <b class="method">table threshold-le</b> <i class="arg">threshold</i></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through a <b class="function">thresholding</b> (or <i class="term"><a href="../index.html#key48">binarization</a></i>)
function, with parameter <i class="arg">threshold</i>. This function is defined as:</p>
<p><img alt="threshold-le" src="../image/threshold-le.png"></p></dd>
</dl>
</div>
</div>







|










|

















|




|










|






|




|










|





|




|




|








|




|







901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
<p>The methods support the writing of <b class="const">rgb</b>, <b class="const">rgba</b>,
<b class="const">hsv</b>, and <b class="const">grey8</b> images.</p></dd>
</dl></dd>
</dl>
</div>
<div id="subsection5" class="subsection"><h3><a name="subsection5">Support</a></h3>
<dl class="definitions">
<dt><a name="57"><b class="cmd">::crimp</b> <b class="method">kernel make</b> <i class="arg">matrix</i> <span class="opt">?<i class="arg">scale</i>?</span></a></dt>
<dd><p>This method takes a <i class="arg">matrix</i> of weights and an optional
<i class="arg">scale</i> factor and returns a structure containing the associated
convolution kernel, ready for use by method <b class="method">convole</b>.</p>
<p>If <i class="arg">scale</i> is left unspecified it defaults to the sum of
all weights in the matrix.</p>
<p>The <i class="arg">matrix</i> has the same general format as the pixel
matrix for method <b class="method">read tcl</b>, i.e. a list of lists (rows) of
values, and is treated in the same way, i.e. the number of columns is
the maxium length over the row lists, and shorter lists are padded
with <b class="const">255</b>.</p></dd>
<dt><a name="58"><b class="cmd">::crimp</b> <b class="method">kernel transpose</b> <i class="arg">kernel</i></a></dt>
<dd><p>This method takes a <i class="arg">kernel</i> as returned by the method
<b class="method">kernel make</b> and returns a transposed kernel, i.e. one where
the x- and y-axes are switched.
For example</p>
<pre class="example">
                    (1)
                    (2)
    {1 2 4 2 1} ==&gt; (4)
                    (2)
                    (1)
</pre>
<p>This method is its own inverse, i.e. application to its result returns
the original input, i.e.</p>
<pre class="example">
    [transpose [transpose $K]] == $K
</pre>
</dd>
<dt><a name="59"><b class="cmd">::crimp</b> <b class="method">map</b> <i class="arg">arg</i>...</a></dt>
<dd><p>This method accepts the same sub-methods and arguments as are accepted
by the <b class="method">table</b> method below. In contrast to <b class="method">table</b> the
result is not a list of values, but a map image directly suitable as
argument to the <b class="method">remap</b> method.</p></dd>
<dt><a name="60"><b class="cmd">::crimp</b> <b class="method">table degamma</b> <i class="arg">y</i></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through the <b class="function">inverse gamma correction</b> with
parameter <i class="arg">y</i>.
This inverse correction, defined in the domain of [0..1] for
both argument and result, is defined as:</p>
<p><img alt="gamma_inv" src="../image/gamma_inv.png"></p>
<p>Scaling of argument and result into the domain [0..255] of pixel
values, and rounding results to the nearest integer, causes the actual
definition used to be</p>
<p><img alt="scaled_gamma_inv" src="../image/scaled_gamma_inv.png"></p></dd>
<dt><a name="61"><b class="cmd">::crimp</b> <b class="method">table gainw</b> <i class="arg">gain</i> <i class="arg">bias</i></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through a simple linear function with parameters
<i class="arg">gain</i> and <i class="arg">bias</i>. The results are rounded to the nearest
integer and forced into the domain [0..255] by wrapping them
around (modulo), making the definition:</p>
<p><img alt="linear_wrap" src="../image/linear_wrap.png"></p></dd>
<dt><a name="62"><b class="cmd">::crimp</b> <b class="method">table gain</b> <i class="arg">gain</i> <i class="arg">bias</i></a></dt>
<dd><p>This method is like <b class="method">gainw</b>, except that it deals with results
out of the domain [0..255] by clamping them to 0 and 255
respectively instead of wrapping around. I.e. its definition is</p>
<p><img alt="linear_clamp" src="../image/linear_clamp.png"></p></dd>
<dt><a name="63"><b class="cmd">::crimp</b> <b class="method">table gamma</b> <i class="arg">y</i></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through the <b class="function">gamma correction</b> with parameter
<i class="arg">y</i>.
This correction, defined in the domain of [0..1] for both
argument and result, is defined as:</p>
<p><img alt="gamma" src="../image/gamma.png"></p>
<p>Scaling of argument and result into the domain [0..255] of pixel
values, and rounding results to the nearest integer, causes the actual
definition used to be</p>
<p><img alt="scaled_gamma" src="../image/scaled_gamma.png"></p></dd>
<dt><a name="64"><b class="cmd">::crimp</b> <b class="method">table gauss</b> <i class="arg">sigma</i></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through the <b class="function">sampled gauss</b> function with
parameter <i class="arg">sigma</i>.
This function is defined as:</p>
<p><img alt="gauss" src="../image/gauss.png"></p></dd>
<dt><a name="65"><b class="cmd">::crimp</b> <b class="method">table identity</b></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through the <b class="function">identity</b> function, which is defined
as</p>
<p><img alt="identity" src="../image/identity.png"></p></dd>
<dt><a name="66"><b class="cmd">::crimp</b> <b class="method">table invers</b></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through the <b class="function">inverse</b> function, which is defined
as</p>
<p><img alt="inverse" src="../image/inverse.png"></p></dd>
<dt><a name="67"><b class="cmd">::crimp</b> <b class="method">table solarize</b> <i class="arg">threshold</i></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through the <b class="function">solarize</b> function, with parameter
<i class="arg">threshold</i>. This function is defined as:</p>
<p><img alt="solarize" src="../image/solarize.png"></p>
<p>Note how the function is the <b class="function">identity</b> for values under the
threshold, and the <b class="function">inverse</b> for values at and above it. Its
application to an image produces what is known as either
<i class="term"><a href="../index.html#key46">solarization</a></i> or <i class="term"><a href="../index.html#key40">sabattier effect</a></i>.</p></dd>
<dt><a name="68"><b class="cmd">::crimp</b> <b class="method">table threshold-ge</b> <i class="arg">threshold</i></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through a <b class="function">thresholding</b> (or <i class="term"><a href="../index.html#key48">binarization</a></i>)
function, with parameter <i class="arg">threshold</i>. This function is defined as:</p>
<p><img alt="threshold-ge" src="../image/threshold-ge.png"></p></dd>
<dt><a name="69"><b class="cmd">::crimp</b> <b class="method">table threshold-le</b> <i class="arg">threshold</i></a></dt>
<dd><p>This method returns a list of 256 values, the result of running the
values 0 to 255 through a <b class="function">thresholding</b> (or <i class="term"><a href="../index.html#key48">binarization</a></i>)
function, with parameter <i class="arg">threshold</i>. This function is defined as:</p>
<p><img alt="threshold-le" src="../image/threshold-le.png"></p></dd>
</dl>
</div>
</div>
Added images/hello.strimj.
















>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
@...@.......@.@......
@...@.......@.@......
@...@..@@@..@.@..@@@.
@@@@@.@...@.@.@.@...@
@...@.@@@@@.@.@.@...@
@...@.@.....@.@.@...@
@...@.@...@.@.@.@...@
@...@..@@@..@.@..@@@.
Added reader/strimj.tcl.














































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
# -*- tcl -*-
# # ## ### ##### ######## #############
# Reader for strimj formatted images.
# See http://wiki.tcl.tk/_//search?S=strimj
# Code derived from http://wiki.tcl.tk/15325

namespace eval ::crimp::read::strimj {
    variable colors {
	{ } {0   0   0   0}
	@   {0   0   0   255}
	b   {0   0   255 255}
	g   {0   255 0   255}
	c   {0   255 255 255}
	r   {255 0   0   255}
	m   {255 0   255 255}
	o   {255 165 0   255}
	y   {255 255 0   255}
	.   {255 255 255 255}
    }
}

proc ::crimp::read::strimj {text {colormap {}}} {
    variable strimj::colors
    array set map $colors
    array set map $colormap

    set rr {} ; set ri {}
    set gr {} ; set gi {}
    set br {} ; set bi {}
    set ar {} ; set ai {}

    foreach line [split $text \n] {
	foreach pixel [split $line {}] {
	    lassign $map($pixel) r g b a
	    lappend rr $r
	    lappend gr $g
	    lappend br $b
	    lappend ar $a
	}

	lappend ri $rr ; set rr {}
	lappend gi $gr ; set gr {}
	lappend bi $br ; set br {}
	lappend ai $ar ; set ar {}
    }

   return [crimp join 2rgba \
	       [tcl $ri] \
	       [tcl $gi] \
	       [tcl $bi] \
	       [tcl $ai]]
}

# # ## ### ##### ######## #############
return