Posted by SiD on Thu 1 Jan 09:47
report abuse | download | new post
- #!usr/bin/perl
- # --==--==--==--==--==--==--==--==--==--==
- # Author: SiD - flybor[at]hotmail[dot]it
- # License: GNU/Gpl
- # Version: 1.1
- # 1/2009
- # --==--==--==--==--==--==--==--==--==--==
- # PPM Base library
- # For Perl ~~ Greetz to neo :)
- # --==--==--==--==--==--==--==--==--==--==
- use Switch;
- package ppm;
- sub load_image {
- }
- sub new_image {
- }
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Single pixel color change function
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- sub change_single {
- my $rows = 0;
- checktype();
- while($line = <IMGP>) {
- if($rows >= $imgtype) {
- }
- }
- print IMGP2 $line;
- $rows++;
- }
- }
- #-=-=-=-=-=-=-=-=-=-=-=
- # Tern change function
- #-=-=-=-=-=-=-=-=-=-=-=
- sub change_tern {
- checktype();
- if($tern and $ntern !~ /(.+) (.+) (.+)/) {
- }
- while($linen = <IMGP>) {
- print IMGP2 $linen;
- }
- }
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Gradient function
- # For a good gradient, use 256 (WIDTH) ^^
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- sub create_gradient {
- my($dim, $rgb) = @_;
- print IMGP2 "P3\n#Gradient created with PPM Base library :: Perl :: By SiD\n$dim\n255\n";
- $lar = @dims[0];
- $alt = @dims[1];
- $r = @rgbval[0];
- $g = @rgbval[1];
- $b = @rgbval[2];
- for($xb=0; $xb<=$lar; $xb++) {
- for($xb2=0; $xb2<$alt; $xb2++, $g--) {
- if($g >= 0 && $g <= @rgbval[1]) {
- }
- else {
- $g = @rgbval[1]+1;
- }
- }
- }
- }
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Chessboard function - I've to review this..
- # See the image with Photoshop or GIMP!
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- sub chessboard {
- $dims = shift;
- $larg = @dims1[0];
- $alte = @dims1[1];
- print IMGP2 "P1\n#Chessboard created with PPM Base library :: Perl :: By SiD\n$larg $alte\n";
- for($xc=0; $xc<$larg; $xc++) {
- for($xc2=0; $xc2<$alte; $xc2++) {
- if($chesstype eq 0) {
- $chesstype = 1;
- }
- else {
- $chesstype = 0;
- }
- }
- print IMGP2 "\n";
- }
- }
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Line drawer function
- # See the image with Photoshop or GIMP!
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- sub line {
- $size = shift;
- $mode = shift;
- $larg = @size1[0];
- $alte = @size1[0];
- print IMGP2 "P1\n#Line(s) created with PPM Base library :: Perl :: By SiD\n$size $size\n";
- for($xd=0; $xd<$larg; $xd++) {
- for($xd2=0; $xd2<$alte; $xd2++) {
- if($mode eq "vertical") {
- if($linetype eq 0) {
- $linetype = 1;
- }
- else {
- $linetype = 0;
- }
- }
- elsif($mode eq "horizontal") {
- }
- else {
- }
- }
- if($linetype eq 0 && $mode eq "horizontal") {
- $linetype = 1;
- }
- else {
- $linetype = 0;
- }
- print IMGP2 "\n";
- }
- }
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Granule image creator function
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- sub granule {
- $dims = shift;
- $larg = @dims2[0];
- $alte = @dims2[1];
- print IMGP2 "P3\n#Granule image with colours created with PPM Base library :: Perl :: By SiD\n$dims\n255\n";
- for($xe=0; $xe<$larg; $xe++) {
- for($xe2=0; $xe2<$alte; $xe2++) {
- }
- }
- }
- #-=-=-=-=-=-=-=-=-=-=-=
- # Reverse RGB function
- #-=-=-=-=-=-=-=-=-=-=-=
- checktype();
- my $rows = 0;
- while($line = <IMGP>) {
- if($rows >= $imgtype) {
- $line = "";
- $line .= @tempa[$xf2]." ";
- }
- $line .= "\n";
- }
- $line = "" and @tempa = ();
- $rows++;
- }
- }
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Format image with tern function
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- checktype();
- my $rows = 0;
- my $rgbtern = 1;
- while($line = <IMGP>) {
- if($rows >= $imgtype) {
- $newline .= $line." ";
- if($rgbtern eq 3) {
- $newline = "", $rgbtern = 0;
- }
- $rgbtern++;
- }
- else {
- }
- $rows++;
- }
- }
- #-=-=-=-=-=-=-=-=-=-=-=-=
- # Copy PPM image function
- #-=-=-=-=-=-=-=-=-=-=-=-=
- sub copy {
- while($line = <IMGP>) {
- $arows++;
- }
- }
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # 180° Rotation + Reverse function
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- sub reverse_180 {
- checktype();
- my $rows = 0;
- my(@temp, $line);
- while($line = <IMGP>) {
- if($rows >= $imgtype) {
- }
- else {
- }
- $rows++;
- }
- }
- }
- #-=-=-=-=-=-=-=-=-=-=
- # Noise set function
- #-=-=-=-=-=-=-=-=-=-=
- sub noise {
- checktype();
- my $rows = 0;
- my(@temp, $line, $newline);
- while($line = <IMGP>) {
- if($rows >= $imgtype) {
- foreach(@splitter) {
- }
- my @splitter;
- }
- else {
- }
- $rows++;
- }
- }
- else {
- $newline = @temp[$xi];
- }
- $newline = "";
- }
- }
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # P6 to P3 converter function
- # Thanks neo for the help with P6 images ^^
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- sub P6_P3 {
- checktype();
- my $rows = 0;
- while($line = <IMGP>) {
- if($rows >= $imgtype) {
- foreach(@line) {
- }
- my @line;
- }
- else {
- }
- $rows++;
- }
- }
- #-=-=-=-=-=-=-=-=
- # Get image type
- #-=-=-=-=-=-=-=-=
- sub checktype {
- $imgt = <IMGP>;
- if($imgt ne "P6\n") {
- print IMGP2 $imgt;
- }
- switch($imgt) {
- case("P1\n") {
- $imgtype = 2;
- }
- case("P2\n") {
- $imgtype = 3;
- }
- case("P3\n") {
- $imgtype = 3;
- }
- case("P5\n") {
- $imgtype = 3;
- }
- case("P6\n") {
- $imgtype = 3;
- }
- else {
- }
- }
- return $imgtype;
- }
- if($imgr) {
- }
- 1;
- # PPM Base Library
- # Author: SiD
- # http://sid93.wordpress.com
- # flybor[at]hotmail[dot]it
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.