SWF-Builder

 view release on metacpan or  search on metacpan

lib/SWF/Builder/Character/Bitmap.pm  view on Meta::CPAN

		$g = $g * $a / 255;
		$b = $b * $a / 255;
		my $rgba = pack($tmpl, $r, $g, $b, $a);
		unless (exists $colors{$rgba}) {
		    $colors{$rgba} = pack('C',$index++);
		}
		$pixels .= $colors{$rgba};
	    }
	    $pixels .= $pad;
	}

	%colors = reverse %colors;
	$index=0;
	for my $k (sort keys %colors) {
	    my ($output, $status) = $d->deflate($colors{$k});
	    die "Compress error." unless $status == Z_OK;
	    $bm->add($output);
	    $index++;
	}
	$tag->BitmapColorTableSize($index-1);
	my ($output, $status) = $d->deflate($pixels);
	die "Compress error." unless $status == Z_OK;
	$bm->add($output);
	($output, $status) = $d->flush();
	die "Compress error." unless $status == Z_OK;
	$bm->add($output);
    } else {
	$tag->BitmapFormat(5);   # Fullcolor pixmap
	for(my $y = 0; $y<$height; $y++) {
	    for(my $x = 0; $x<$width; $x++) {
		my ($r, $g, $b, $a) = $pixsub->($x,$y);
		$r = $r * $a / 255;
		$g = $g * $a / 255;
		$b = $b * $a / 255;
		my ($output, $status) = $d->deflate(pack('CCCC', $a,$r,$g,$b));
		die "Compress error." unless $status == Z_OK;
		$bm->add($output);
	    }
	}
    }
    my ($output, $status) = $d->flush();
    die "Compress error." unless $status == Z_OK;
    $bm->add($output);

    $tag->pack($stream);
}

1;
__END__

=head1 NAME

SWF::Builder::Character::Bitmap - SWF Bitmap object

=head1 SYNOPSIS

    my $jpeg = $mc->new_jpeg( 'picture.jpg' );
    $jpeg->place;

    use GD;
    $gd = GD::Image->newFromPng( 'tile.png' );
    my $bm = $mc->new_bitmap( $gd, 'GD' );
    my $shape = $mc->new_shape
                ->fillstyle($bm, 'tiled', $bm->matrix)
		->box(0, 0, 100, 100);

=head1 DESCRIPTION

SWF supports JPEG and lossless bitmaps.

=over 4

=item $jpg_bm = $mc->new_jpeg( JPEGFile => $filename / JPEGData => $jpegdata, AlphaFile => $filename / AlphaData => $alphadata / Alpha => $alpha )

=item $jpg_bm = $mc->new_jpeg( $filename )

returns a new JPEG bitmap. It can take named parameters as follows:

=over 4

=item JPEGFile / JPEGData

set a JPEG Data from a file and a binary data string, respectively.

=item AlphaFile / AlphaData / Alpha

set an alpha (transparency) data from a file, a binary data string, and a
single byte, respectively.
The alpha data is width x height length string of byte, 0(transparent) to
255(opaque). A single byte Alpha is expanded into the proper size.

=back

When you give a single parameter, it is regarded 
as the JPEG file name. Same as JPEGFile => $filename.

=item $jpg_bm->JPEGData/AlphaData/Alpha( $data )

set a JPEG/Alpha data.

=item $jpg_bm->load_jpeg/load_alpha( $filename )

load a JPEG/alpha data file.

=item $ll_bm = $mc->new_bitmap( $obj [, $type] )

returns a new lossless bitmap converted from a $type of $obj.
If $type is omitted, it is guessed.
If $obj is not an object, it is treated as a file name.

Acceptable types are as follows:

=over 4

=item GD

takes a GD::Image object.

=item ImageMagick

takes an Image::Magick object.



( run in 2.151 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )