Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

cheshirecat's scratchpad

by cheshirecat (Sexton)
on Jun 07, 2004 at 19:33 UTC ( [id://362080]=scratchpad: print w/replies, xml ) Need Help??

#code to convert 32bit BMP (actually DIB) to 24bit sub check_bmp { $input = shift; $output = shift; open(INPUT,"<$input"); binmode(INPUT); # now read in the header read(INPUT,$buff,54); # sig, filesize, reserved, dataoffset, size, width, height, planes, +bitcount, compression, imagesize # xpixelsM, ypixelsM , colorsused, colorsimportant ( $sig, $filesize, $reserved, $dataoffset, $size, $width, $height, $ +planes, $bitcount, $compression, $imagesize, $xpixelsM, $ypixelsM , $colorsused, $colorsimportant ) + = unpack($headertemplate,$buff); if ($bitcount != 32) { close(INPUT); rename($input,$output); } else # only rework if 32 bit { # print "\n\tProcessing $input to $output\n"; open(OUTPUT,">$output"); binmode(OUTPUT); $bitcount = 24; $compression = 0; $imagesize = int (($imagesize) * 0.75); $filesize = $imagesize + $dataoffset; @fields = ( $sig, $filesize, $reserved, $dataoffset, $size, $width +, $height, $planes, $bitcount, $compression, $imagesize, $xpixelsM, $ypixelsM , $colorsused, $colorsimportant + ); $buff2 = pack($headertemplate,@fields); syswrite(OUTPUT,$buff2,54); $count = 0; # now rewrite the BMP, dropping the alpha channel until( eof(INPUT) ) { read(INPUT, $pixel, 4); ($r, $g, $b, $a) = unpack($rgbapixeltemplate,$pixel); $rgbpixel = pack($rgbpixeltemplate, $r, $g, $b); # $rgbpixel = $r.$g.$b; syswrite(OUTPUT,$rgbpixel,3); } close(INPUT); close(OUTPUT); # remove the .dib file unlink($input); } }
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found