Permalink
Browse files

working on type 3 images. wrote a little perl script to get size/dept…

…h/type directly from headers to be sure
  • Loading branch information...
1 parent 0b974ba commit d5f6b35aa7bafa6e004a260b248160486e8028c0 @iamcal committed Aug 24, 2010
Showing with 39 additions and 15 deletions.
  1. +22 −15 bake.pl
  2. +17 −0 peek.pl
View
@@ -55,17 +55,17 @@ sub store_bytes {
# type 0 : grayscale
#
- &create_type0_8bit($mode, 'square', $bytes);
- &create_type0_4bit($mode, 'square', $bytes);
- &create_type0_2bit($mode, 'square', $bytes);
- &create_type0_1bit($mode, 'square', $bytes);
-return;
+ #&create_type0_8bit($mode, 'square', $bytes);
+ #&create_type0_4bit($mode, 'square', $bytes);
+ #&create_type0_2bit($mode, 'square', $bytes);
+ #&create_type0_1bit($mode, 'square', $bytes);
+
#
# type 2 : truecolor, no alpha
#
- &create_type2_8bit($mode, 'square', $bytes);
+ #&create_type2_8bit($mode, 'square', $bytes);
#
@@ -74,9 +74,9 @@ sub store_bytes {
&create_type3_8bit($mode, 'square', $bytes);
&create_type3_4bit($mode, 'square', $bytes);
- &create_type3_2bit($mode, 'square', $bytes);
- &create_type3_1bit($mode, 'square', $bytes);
-
+ #&create_type3_2bit($mode, 'square', $bytes);
+ #&create_type3_1bit($mode, 'square', $bytes);
+return;
#
# type 4: greyscale & alpha
@@ -107,8 +107,6 @@ sub create_type0 {
$im->Set(option => "png:color-type=0");
$im->Set(option => "png:bit-depth=$bits");
-
-
&pack_image($im, $shape, $bytes, $bits, sub{
my $val = $_[0];
if ($bits == 4){ $val = $_[0] | ($_[0] << 4); }
@@ -174,22 +172,31 @@ sub create_type3 {
my ($mode, $shape, $bytes, $bits) = @_;
my $im = Image::Magick->new();
- $im->Set(type => 'Palette');
+
+ $im->Set(option => "png:color-type=3");
+ $im->Set(option => "png:bit-depth=$bits");
+ #$im->Set(type => 'Palette');
for my $i(0..15){
$im->Set("colormap[$i]", sprintf('#%02x%02x%02x', $i, 0, 0));
}
+ $im->Set(option => "png:color-type=3");
+ $im->Set(option => "png:bit-depth=$bits");
+
&pack_image($im, $shape, $bytes, $bits, sub{
my $val = $_[0];
#print "$val, ";
return sprintf('#%02x%02x%02x', $val, 0, 0);
});
+ $im->Set(option => "png:color-type=3");
+ $im->Set(option => "png:bit-depth=$bits");
+
my $name = "${mode}_t3_${bits}b_${shape}.png";
my $ret = $im->Write(
- filename => "png8:$dir/$name",
- depth => 4,
+ filename => "$dir/$name",
+ #depth => 4,
);
&debug($name);
@@ -411,7 +418,7 @@ sub debug {
print "\n";
print "$name:\n";
- print `pngcrush -n -v $dir/$name | grep ' ' | grep -v \\| | grep -v ' '`;
+ print `./peek.pl $dir/$name`;
}
#########################################################################################
View
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+open F, $ARGV[0] or die $!;
+my $junk;
+my $buffer;
+read F, $junk, 16;
+read F, $buffer, 10;
+
+my ($w, $h, $depth, $type) = unpack('NNCC', $buffer);
+
+print "\tSize : $w x $h\n";
+print "\tType : $type\n";
+print "\tDepth : $depth\n";
+

0 comments on commit d5f6b35

Please sign in to comment.