Image data parsing

A

anatolym

Hello All,

I have a problem here and I tried a few things, but non worked.

Any help would be greatly appreciated!

I'm parsing an XML file, trying to get the image part out and save
it as an image file. File format (gif, png, jpeg, bmp) is unknown.

The following is a fragment of the XML:

<picture width="2550" height="675" baseline="674">
<pict-header>
<width>170</width>
<height>45</height>
<bits-per-pixel>8</bits-per-pixel>
<palette>
<palette-entry>#000000</palette-entry>
<palette-entry>#010101</palette-entry>
<palette-entry>#020202</palette-entry>
<palette-entry>#030303</palette-entry>
<palette-entry>#040404</palette-entry>
<palette-entry>#050505</palette-entry>
<palette-entry>#0d0d0d</palette-entry>

-- snip: lots of palette entries here --

<palette-entry>#f5f5f5</palette-entry>
<palette-entry>#f6f6f6</palette-entry>
<palette-entry>#fdfdfd</palette-entry>
<palette-entry>#fefefe</palette-entry>
<palette-entry>#ffffff</palette-entry>
</palette>
</pict-header>
<pict-data>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////8AAP////8AAAD/
/wAAAP8AAAD//wAA/wD/AAAA//8AAAD/////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////AAD///8A////AP//AP///wD/
/wD//wAAAP8A/////wD/////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
-- snip: more picture data ---
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////AAD/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////wAA
</pict-data>
</picture>


I tried to use Imager module to read this in and write to a file:

$type = "jpeg"; # gif, png, bmp, etc.

$filename = "fig_$iname.$type";

use Imager;
$img = Imager->new(xsize=>$pHw, ysize=>$pHh, bits=>$pBits,
type=>'paletted');

my @colors;
while($pPlt =~ m|<palette-entry>(#[\dabcdf]+)</palette-entry>|ig) {
push @colors, Imager::Color->new($1);
}
$img->addcolors(colors=>\@colors);

$img->read(data=>$pData, type=>$type) or die "Cannot read: ",
$img->errstr;

$img->write(file=>"$dir/$filename", type=>$type) or die "Cannot
write:", img->errstr;


I tryed all of the above types, but it bombs out with "Cannot read:"
every time.


Is it possible at all to parse this kind of data into a file?
If possible - what am I doing wrong?


Thanks a lot for your help!

AnatolyM
 
M

Martien Verbruggen

Hello All,

I have a problem here and I tried a few things, but non worked.

Any help would be greatly appreciated!

I'm parsing an XML file, trying to get the image part out and save
it as an image file. File format (gif, png, jpeg, bmp) is unknown.

You will only be successful in that if you know how the XML is built up.
If you don't know the format of the data, then you have very little
chance to decode it.

[snip XML]

I've done a bit of snooping around, and I found one XML DTD that
actually seems to have all the elements that you have in that XML. If
that DTD is the one used for this, then your image data is probably a
base 64 encoded string representing each pixel's index into the palette.
However, I'm just guessing. I'd ask the people who created the XML file
in the first place.
I tried to use Imager module to read this in and write to a file:

I doubt very much that it will be able to take random unspecified data
you throw at it, and make sense of it for you. I suspect you'll have to
do the hard work, and try a few things, or find the documentation or
information on this from the source.

Martien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top