Re: copy image to windows clipboard?
- From: "Paul Obermeier" <obermeier@xxxxxxxxx>
- Date: Fri, 24 Mar 2006 21:40:55 +0100
Hello,
Your assumption about lacks in the Img BMP parser are correct.
I've implemented the missing 16 and 32 bit format parser (for reading only)
and put a new binary version of Img
onto my homepage: http://www.posoft.de/download/tkimg/Img1.3.zip
There is also a little test program (based on your code published here) on
the Tclers Wiki: http://wiki.tcl.tk/15647
If I get positive feedback (hopefully) the changes will make it into the Img
sources on SourceForge.
Paul
P.S.: The 16 and 32 bit based BMP format is typically not used with image
files. Windows uses it, when copying images into the clipboard. So, you
should try to test with 16 and 32 bit display settings.
<palmtcl@xxxxxxxxx> schrieb im Newsbeitrag
news:1142361311.282086.180470@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Well it turns out that the offset (14/66 etc) depends on the bitmap.
Here's a new and improved version of write_bitmap_header that seems to
work much better. I had thought the file header field that contained
the offset to the bitmap was the offset to the bitmap header. It is
actually the offset to the pixel values so we need to skip over the
color table entries etc.
GIMP, XP Picture viewer and Paint all show it correctly. Img still
complains about unsupported RLE format. I'm not sure if that's because
of lingering bugs in this function or it really is a Img unsupported
(but valid) format. Anyways, here's the proc:
proc write_bmp_file {filename bmp} {
# Assumes $bmp is clipboard content in format 8 (CF_DIB)
# First parse the bitmap data to collect header information
binary scan $bmp "iiissiiiiii" size width height planes bitcount
compression sizeimage xpelspermeter ypelspermeter clrused clrimportant
# We only handle BITMAPINFOHEADER right now (size must be 40)
if {$size != 40} {
error "Unsupported bitmap format. Header size=$size"
}
# We need to figure out the offset to the actual bitmap data
# from the start of the file header. For this we need to know the
# size of the color table which directly follows the
BITMAPINFOHEADER
if {$bitcount == 0} {
error "Unsupported format: implicit JPEG or PNG"
} elseif {$bitcount == 1} {
set color_table_size 2
} elseif {$bitcount == 4} {
# TBD - Not sure if this is the size or the max size
set color_table_size 16
} elseif {$bitcount == 8} {
# TBD - Not sure if this is the size or the max size
set color_table_size 256
} elseif {$bitcount == 16 || $bitcount == 32} {
if {$compression == 0} {
# BI_RGB
set color_table_size $clrused
} elseif {$compression == 3} {
# BI_BITFIELDS
set color_table_size 3
} else {
error "Unsupported compression type '$compression' for
bitcount value $bitcount"
}
} elseif {$bitcount == 24} {
set color_table_size $clrused
} else {
error "Unsupported value '$bitcount' in bitmap bitcount field"
}
set filehdr_size 14; # sizeof(BITMAPFILEHEADER)
set bitmap_file_offset [expr
{$filehdr_size+$size+($color_table_size*4)}]
set filehdr [binary format "a2 i x2 x2 i" "BM" [expr {$filehdr_size
+ [string length $bmp]}] $bitmap_file_offset]
set fd [open $filename w]
fconfigure $fd -translation binary
puts -nonewline $fd $filehdr
puts -nonewline $fd $bmp
close $fd
}
.
- Follow-Ups:
- Re: copy image to windows clipboard?
- From: palmtcl
- Re: copy image to windows clipboard?
- References:
- copy image to windows clipboard?
- From: Bryan Oakley
- Re: copy image to windows clipboard?
- From: Roy Terry
- Re: copy image to windows clipboard?
- From: Bryan Oakley
- Re: copy image to windows clipboard?
- From: palmtcl
- Re: copy image to windows clipboard?
- From: walton . paul
- Re: copy image to windows clipboard?
- From: palmtcl
- Re: copy image to windows clipboard?
- From: walton . paul
- Re: copy image to windows clipboard?
- From: walton . paul
- Re: copy image to windows clipboard?
- From: walton . paul
- Re: copy image to windows clipboard?
- From: walton . paul
- copy image to windows clipboard?
- Prev by Date: Re: Having trouble with basic serial commands???
- Next by Date: Re: Binary data INTO C extension?
- Previous by thread: Re: copy image to windows clipboard?
- Next by thread: Re: copy image to windows clipboard?
- Index(es):
Relevant Pages
|