Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- our $mergebinhigh;
- our $mergebinlow;
- our $mergelength=0;
- our $headerlength = 55;
- use Getopt::Long;
- our ($filename, $startnum, $endnum, $outputhigh, $outputlow, $uebertraghigh, $uebertraglow, $delete);
- GetOptions('filename=s' => \$filename, 'startnum=s' => \$startnum, 'endnum=s' => \$endnum,
- 'outputhigh=s' => \$outputhigh, 'outputlow=s' => \$outputlow, 'uebertraghigh=s' => \$uebertraghigh, 'uebertraglow=s' => \$uebertraglow, 'delete=s' => \$delete) or die("Error in command line arguments\n");;
- if (-e $uebertraghigh)
- {
- addimage($uebertraghigh, 'high');
- unlink($uebertraghigh) if ($delete);
- }
- if (-e $uebertraglow)
- {
- addimage($uebertraglow, 'low');
- unlink($uebertraglow) if ($delete);
- }
- for (my $num = $startnum; $num <= $endnum; $num++)
- {
- my $filenumname = $filename;
- $filenumname=~s/%NUM%/$num/gi;
- if (-e $filenumname)
- {
- if (($outputhigh) && ($outputlow))
- {
- addimage($filenumname);
- }
- elsif ($outputhigh)
- {
- addimage($filenumname,'high');
- }
- elsif ($outputlow)
- {
- addimage($filenumname,'low');
- }
- unlink($filenumname) if ($delete);
- }
- else
- {
- print "merging: $filenumname file not found!!!\n";
- }
- }
- #### output file
- if ($outputhigh)
- {
- open (FILE, '>:raw',$outputhigh) || die ("canot open $outputhigh because of $!");
- binmode (FILE);
- print FILE $mergebinhigh;
- close (FILE);
- print "[$$] merging finished $filename $startnum .. $endnum to $outputhigh\n";
- }
- if ($outputlow)
- {
- open (FILE, '>:raw',$outputlow) || die ("canot open $outputhigh because of $!");
- binmode (FILE);
- print FILE $mergebinlow;
- close (FILE);
- print "[$$] merging finished $filename $startnum .. $endnum to $outputhigh\n";
- }
- #print "\n" . `ps $$` . "\n";
- exit;
- sub addimage
- {
- my ($filename, $modus) = @_;
- open (FILE, '<:raw',$filename) || die ("canot open $_[0] because of $!");
- binmode (FILE);
- read FILE, my $content, 100000000;
- close (FILE);
- #print "datei $_[0] gelesene bytes: " . length($content) . "\n";
- if ($mergelength eq 0)
- {
- $mergelength = length($content);
- $mergebinhigh = $content;
- $mergebinlow = $content;
- #print "first image $filename loaded.\n";
- return;
- }
- if ($mergelength ne length($content))
- {
- print "file length of $filename not matches others! skipping.\n";
- return;
- }
- #print "merging $filename ...\n";
- my ($a, $b);
- my $mergeddata;
- if ($modus ne 'low')
- {
- $mergeddata = substr($mergebinhigh,0,$headerlength);
- for (my $i = $headerlength; $i<=$mergelength;$i++)
- {
- $a = substr($mergebinhigh,$i,1);
- $b = substr($content,$i,1);
- if ($a ge $b)
- {
- $mergeddata .= $a;
- }
- else
- {
- $mergeddata .= $b;
- }
- }
- $mergebinhigh = $mergeddata;
- }
- if ($modus ne 'high')
- {
- $mergeddata = substr($mergebinlow,0,$headerlength);
- for (my $i = $headerlength; $i<=$mergelength;$i++)
- {
- $a = substr($mergebinlow,$i,1);
- $b = substr($content,$i,1);
- if ($a lt $b)
- {
- $mergeddata .= $a;
- }
- else
- {
- $mergeddata .= $b;
- }
- }
- $mergebinlow = $mergeddata;
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement