in reply to Re: Re: capturing raw video with v4l
in thread capturing raw video with v4l

Don't know how quick it is, but here's my stab at converting from BGR to RGB.
sub convert_to_rgb { my $bgr = shift; my $bgrLen = length($bgr); #Unpacking the BGR data gives use easy access to individual bytes. my @bgrArray = unpack("C$bgrLen",$bgr); my @rgbArray; my $ct=0; while ($ct < $bgrLen) { $rgbArray[$ct] = $bgrArray[$ct+2]; $rgbArray[$ct+1] = $bgrArray[$ct+1]; $rgbArray[$ct+2] = $bgrArray[$ct]; $ct+=3; } #Pack the data to match the input format. my $rgb = pack("C$bgrLen",@rgbArray); return $rgb; }
Pass the code $nfr and the returned value can be written to file in place of $nfr.

Replies are listed 'Best First'.
Re: Re: Re: Re: capturing raw video with v4l
by zentara (Cardinal) on Feb 18, 2004 at 16:15 UTC
    Hi, that's a nice pure perl snippet, however it still would be faster to let Imager do it, since it uses xs and C to do the same thing, and faster too for big image files.

    I'm not really a human, but I play one on earth. flash japh