Kevin Goodsell wrote:

> Third, only in relatively bad cases will GIF require a byte for every
> pixel. For example, I just created a solid white 200 by 200 image.
> That's 40,000 pixels. The file size is 345 bytes. One byte per pixel is
> what you would get if no compression was used at all (probably what
> happened in this case, but not what happens in general), or if the
> compression performed so badly that it might as well have not been used
> (which is rare for typical images).
>
> -Kevin

Thanks again for the correction.  It has spurred some new exploration.  I've
been looking at the published standard on the format, and it is not at all
like I had assumed.  I'm afraid I was lumping it in with BMP and TIFF.
Anyway, I am starting to untangle the coding:

Greetings! E:\d_drive\perlStuff>perl -w
open IN, 'fullhead.gif';
binmode IN;
local $/;
my $img = <IN>;
my @bytes = split //, $img;
my $gif_type;
for (1..6) {
   $gif_type .= shift @bytes;
}
print "$gif_type\n";
my $width = ord(shift @bytes);
$width += 256 * ord(shift @bytes);
my $height = ord(shift @bytes);
$height += 256 * ord(shift @bytes);
print "Width: $width  Height: $height\n";
my $control_string = ord (shift @bytes);
my $is_map = $control_string / 128;
$control_string %= 128;
my $bit_resolution = int(($control_string / 16) + 1);
$control_string %= 16;
$control_string %= 2;
my $bits_per_pixel = $control_string;
my $background_color = ord(shift @bytes);
print "Background is $background_color\n";
my $color_map = ord(shift @bytes);
print "Color map is $color_map\n";
my @colors;
for (my $i = 0; $i < 2 ** $bit_resolution; $i++) {
   my $color_channels = {};
   $color_channels->{'red'} = ord(shift @bytes);
   $color_channels->{'green'} = ord(shift @bytes);
   $color_channels->{'blue'} = ord(shift @bytes);
   push @colors, $color_channels;
   print 'R:  ', sprintf ("%03d", $color_channels->{'red'}),
   '   G:  ', sprintf ("%03d", $color_channels->{'green'}),
   '   B:  ', sprintf ("%03d", $color_channels->{'blue'}), "\n";
}

foreach my $char (@bytes) {
   my $byte = ord($char);
   my $first_nibble = int($byte / 16);
   my $crumbs = $byte % 16;
   print "$first_nibble\n$crumbs\n";
}
print 'Data size was ', my $byte_size = @bytes, "\n";

^Z
GIF89a
Width: 30  Height: 16
Background is 0
Color map is 0
R:  000   G:  000   B:  000
R:  128   G:  000   B:  000
...
2
1
15
9
0
4
0
1
0
0
...
3
11
Data size was 117

Right now, I'm sort of tracking as I read the spec.  I swear to Gawd, I
couldn't find anything like this last time I went a-hunting!

It's not very often that you'll see me writing this much flush-left scrit,
but right now I just want to follow a file through sequentially, and deal
with each part as it comes.

Joseph



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to