[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] How to read PICT files



I would like to tranform a b/w PICT file into an array of 1s and 0s to be used
latter to generate a bitmap in PocketC and CASL for the PalmPilot. My first
approach has been to open the PICT file using the code below:

======= CODE BEGINS ==========

#!Perl -w
# OuvrirImage.pl
# Date : 29/6/98

my ($file, $fileName, $bytes, $bytesToASCII, @type, $i);
$fileName  = "Macintosh HD:REALBasic:Dossier mes projets:CercleNoir.PICT";
$i = 0;

open(FILEHANDLE, $fileName) ||
 die "Pas pu ouvrir fichier en question. $!\n";

# Sauter 512 caracteres a partir du debut (header)
seek(FILEHANDLE, 512, 1);

# LibellŽ, taille en octets
&printBytes("Taille du fichier : ", 2);
&printBytes("Pos X du frame en haut et a gauche : ", 2);
&printBytes("Pos Y du frame en haut et a droite : ", 2);
&printBytes("Pos X du frame en bas et a droite : ", 2);
&printBytes("Pos Y du frame en bas et a droite : ", 2);
&printBytes("Version de l'opcode : ", 2); # 2 si PICT version 2
&printBytes("Numero de version : ", 2); # 2 si PICT version 2


close(FILEHANDLE);

sub printBytes {
	my($texte, $taille) = @_;
	my($bytes, $bytesToASCII, $format);

	read(FILEHANDLE, $bytes, $taille);
	$format = ("s" . $taille);
	$bytesToASCII = unpack($format, $bytes);
	print("$texte\'$bytesToASCII\'\n");

====== END OF CODE ========

In the above code, I use the unpack('s2' command to read the file's size,
which is two-bytes long, among other things. However, I am not whether 's2' is
the right format to use, as opposed to 'I2' and other formats. Furthermore, if
I ever succeed reading the PICT file's data using unpack, how can I tranform
them into a bitmap array (e.g., if pixel (0,0) is black than $array[1,1]
should be 0, etc.)?

Any suggestions?

Many thanks.

Philippe de Rochambeau

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch