]> git.imager.perl.org - imager.git/blame - samples/inline_capture2image.pl
he unpack code for ICO/CUR file handling could extend 32-bit unsigned values to 64...
[imager.git] / samples / inline_capture2image.pl
CommitLineData
c64eee30
TC
1#!perl -w
2use strict;
3use Imager;
4
5# this is just to exercise the code, see the capture2image
6# function below for the meat
7my $from = shift;
8
9my $to = shift;
10
11my $width = shift || 320;
12
13my $height = shift || 240;
14
15$to or die "Usage: $0 from to [width [height]]\n";
16
17my $data;
18open RAWVIDEO, "< $from"
19 or die "Cannot open $from: $!\n";
20binmode RAWVIDEO;
21$data = do { local $/; <RAWVIDEO> };
22close RAWVIDEO;
23
24length $data >= $width * $height * 3
25 or die "Not enough data for video frame\n";
26
27my $im = Imager->new(xsize=>$width, ysize=>$height);
28
29capture2image($im, $data);
30
31$im->write(file=>$to)
32 or die "Cannot save $to: $!\n";
33
34use Inline C => <<'EOS' => WITH => 'Imager';
35void
36capture2image(Imager::ImgRaw out, unsigned char *data) {
37 i_color *line_buf = mymalloc(sizeof(i_color) * out->xsize);
38 i_color *pixelp;
39 int x, y;
40
41 for (y = 0; y < out->ysize; ++y) {
42 pixelp = line_buf;
43 for (x = 0; x < out->xsize; ++x) {
44 pixelp->rgba.b = *data++;
45 pixelp->rgba.g = *data++;
46 pixelp->rgba.r = *data++;
47 ++pixelp;
48 }
49 i_plin(out, 0, out->xsize, y, line_buf);
50 }
51
52 myfree(line_buf);
53}
54EOS
55
56__END__
57
58=head1 NAME
59
5715f7c3 60inline_capture2image.pl - convert captured C<BGR> data to any Imager supported format
c64eee30
TC
61
62=head1 SYNOPSIS
63
64 perl inline_capture2image.pl rawbgr foo.ext
65 perl inline_capture2image.pl rawbgr foo.ext width
66 perl inline_capture2image.pl rawbgr foo.ext width height
67
68=head1 DESCRIPTION
69
70This was inspired by the discussion at
71http://www.perlmonks.org/?node_id=539316 (Feeding video data to
72Imager).
73
74inline_capture2image.pl takes V4L raw captured image data and outputs
75an image in any image format supported by Imager.
76
77=head1 SEE ALSO
78
79Imager, Imager::API
80
81Perl and Video Capture
82http://www.perlmonks.org/?node=474047
83
84Feeding video data to Imager
85http://www.perlmonks.org/?node_id=539316
86
87=head1 AUTHOR
88
5b480b14 89Tony Cook <tonyc@cpan.org>
c64eee30
TC
90
91=head1 REVISION
92
93$Revision$
94
95=cut