home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / Perl / Non-RPC / !Perl / riscos / RISCOS / JPEG.pm < prev    next >
Text File  |  1998-07-26  |  2KB  |  81 lines

  1. package RISCOS::JPEG;
  2.  
  3.  
  4. use RISCOS::SWI;
  5. require Exporter;
  6. use strict;
  7. use RISCOS::Units 'inch2draw';
  8.  
  9. use vars qw (@ISA @EXPORT_OK $VERSION $jpeg_info);
  10.  
  11. @ISA = qw(Exporter);
  12.  
  13. $VERSION = 0.01;
  14.  
  15. @EXPORT_OK = qw(jpeg_info jpeg_size);
  16.  
  17. # JPEG, default pixels density to use
  18. sub jpeg_info ($;$) {
  19.     my $dpi = $_[1];
  20.     my $result = kernelswi ($jpeg_info, 0, $_[0], length $_[0]);
  21.     return () unless defined $result;
  22.     my ($flags, $width, $height, $xdpi, $ydpi, $workspace) 
  23.       = unpack 'Ix4I5', $result;
  24.     if ($flags & 4 and defined $dpi) {
  25.         $ydpi *= $dpi / $xdpi;
  26.         $xdpi = $dpi;
  27.     }
  28.     ($width, $height, $xdpi, $ydpi, $flags & 1, $flags & 2, $flags & 4,
  29.        $workspace);
  30. }
  31.  
  32. sub jpeg_size ($;$) {
  33.     my ($width, $height, $xdpi, $ydpi) = &jpeg_info;
  34.     return () unless defined $ydpi;
  35.     inch2draw ($width / $xdpi, $height / $ydpi);
  36. }
  37.  
  38. $jpeg_info = SWINumberFromString('JPEG_Info');
  39. die "$^E - do you have JPEG support?" unless defined $jpeg_info;
  40. __END__
  41.  
  42. =head1 NAME
  43.  
  44. RISCOS::JPEG -- perl interface to S<RISC OS> JPEG SWIs.
  45.  
  46. =head1 SYNOPSIS
  47.  
  48.     use RISCOS::JPEG 'jpeg_info';
  49.     ($width, $height, $xdpi, $ydpi, $bw, $no_trans, $ratio) = jpeg_info $jpeg;
  50.     
  51. =head1 DESCRIPTION
  52.  
  53. This module provides a perl interface to S<RISC OS> JPEG SWIs.
  54.  
  55. =over 4
  56.  
  57. =item jpeg_info <JPEG> [,<DPI>]
  58.  
  59. returns an array of C<($width, $height, $xdpi, $ydpi, $bw, $no_trans, $ratio)>
  60. for the JPEG contained in the scalar passed. C<$width> and C<$height> are in
  61. pixels, C<$xdpi> and C<$ydpi> are absolute Dots Per Inch if C<$ratio> is false.
  62. If C<$ratio> is true and I<DPI> is defined then it is returned as the X DPI,
  63. and the returned Y DPI is at the correct ratio. C<$bw> is true if the JPEG is
  64. greyscale, C<$no_trans> is true if transformed plots are unavailable.
  65.  
  66. =item jpeg_size <JPEG> [,<DPI>]
  67.  
  68. returns C<($width, $height)> in Draw units of the JPEG.
  69.  
  70. =back
  71.  
  72. =head1 BUGS
  73.  
  74. Not tested enough.
  75.  
  76. =head1 AUTHOR
  77.  
  78. Nicholas Clark <F<nick@unfortu.net>>
  79.  
  80. =cut
  81.