Issue with PNG and Blog inw Windows using MinGW64
Giovanni Remigi <[email protected]> Wed, 21 Dec 2016 18:47:34 +0000
| Newsgroups | gmane.comp.video.graphicsmagick.apis |
|---|---|
| Message-ID | <CACjhwVO=x6DH=W-hVO9TK9hP29_JLpakK8C7LNfy4pAbPQJNWA@mail.gmail.com> |
--===============2788760098354574458==
Content-Type: multipart/alternative; boundary=001a113ac7ea0ab25a05442f9673
--001a113ac7ea0ab25a05442f9673
Content-Type: text/plain; charset=UTF-8
I'm aware that GraphicsMagick does not support files containing UTF
characters on Windows. I'm using GraphicsMagick as a DLL and If I try
reading from such files my application crashes.
I found a workaround reading an image into a Blob using Qt and then reading
the Blob from memory using GraphicsMagick. This works perfectly but I have
an issue with the opposite operation writing a Blob into a file.
When I encode an Image into a Blob in PNG format using Graphics Magick and
I write the Blob into a file using Qt I experience a data loss. The last
part of the image appears black.
The problem happens only *with big PNG* ( > 32MB) and* on WIndows only*,
while on Linux it works perfectly.
I somehow blame libpng16. On Linux I use libpng12. Using the JPEG format I
do not experience data loss.
Following a sample code to reproduce the problem. Any idea or suggestion?
I'm a bit lost. I've searched everywhere on Internet but I couldn't find a
solution.
Kind Regards
Giovanni
#include <Magick++.h>
#include <memory>
#include <QFile>
#include <QtDebug>
int main(int argc, char **argv)
{
// Initialize Image Magick.
Magick::InitializeMagick(NULL);
std::unique_ptr<Magick::Image> image =
std::make_unique<Magick::Image>("C:/Users/Giovanni/Desktop/interlaced.png");
QString outFileName = "C:/Users/Giovanni/Desktop/output.png";
QFile out(outFileName);
Magick::Blob blob;
bool success = true;
try {
image->write(&blob, "PNG", 8);
} catch (Magick::Exception &error) {
success = false;
qDebug() << QString("Error writing in memory BLOB for image
%1").arg(outFileName);
qDebug() << error.what();
}
if (success) {
success = out.open(QIODevice::WriteOnly);
if (!success) {
qDebug() << QString("Error opening file for writing image
%1").arg(outFileName);
}
}
if (success) {
// @see
http://stackoverflow.com/questions/17108472/how-to-get-buffer-from-imagemagick-image-in-c
QByteArray array(static_cast<const char*>(blob.data()), blob.length());
qint64 bytesWritten = out.write(array);
if (bytesWritten < 0) {
success = false;
qDebug() << QString("Error writing file for image
%1").arg(outFileName);
}
}
}
--001a113ac7ea0ab25a05442f9673
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I'm aware that GraphicsMagick does not support files c=
ontaining UTF characters on Windows. I'm using GraphicsMagick as a DLL =
and If I try reading from such files my application crashes.<div><br><div>I=
found a workaround reading an image into a Blob using Qt and then reading =
the Blob from memory using GraphicsMagick. This works perfectly but I have =
an issue with the opposite operation writing a Blob into a file.</div><div>=
<br></div><div>When I encode an Image into a Blob in PNG format using Graph=
ics Magick and I write the Blob into a file using Qt I experience a data lo=
ss. The last part of the image appears black.</div><div>The problem happens=
only <b>with big PNG</b> ( > 32MB) and<b> on WIndows only</b>, while on=
Linux it works perfectly.</div><div><br></div><div>I somehow blame libpng1=
6. On Linux I use libpng12. Using the JPEG format I do not experience data =
loss.</div><div><br></div><div>Following a sample code to reproduce the pro=
blem. Any idea or suggestion? I'm a bit lost. I've searched everywh=
ere on Internet but I couldn't find a solution.</div><div><br></div><di=
v>Kind Regards</div><div><br></div><div>Giovanni</div><div><br></div><div><=
br></div><div><pre style=3D"margin-top:0px;margin-bottom:0px"><span style=
=3D"color:rgb(0,0,128)">#include</span><span style=3D"color:rgb(192,192,192=
)"> </span><span style=3D"color:rgb(0,128,0)"><Magick++.h></span></pr=
e>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(0,=
0,128)">#include</span><span style=3D"color:rgb(192,192,192)"> </span><span=
style=3D"color:rgb(0,128,0)"><memory></span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(0,=
0,128)">#include</span><span style=3D"color:rgb(192,192,192)"> </span><span=
style=3D"color:rgb(0,128,0)"><QFile></span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(0,=
0,128)">#include</span><span style=3D"color:rgb(192,192,192)"> </span><span=
style=3D"color:rgb(0,128,0)"><QtDebug></span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(12=
8,128,0)">int</span><span style=3D"color:rgb(192,192,192)"> </span>main(<sp=
an style=3D"color:rgb(128,128,0)">int</span><span style=3D"color:rgb(192,19=
2,192)"> </span>argc,<span style=3D"color:rgb(192,192,192)"> </span><span s=
tyle=3D"color:rgb(128,128,0)">char</span><span style=3D"color:rgb(192,192,1=
92)"> </span>**argv)</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">{</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(0,128,0)">//</span><span st=
yle=3D"color:rgb(192,192,192)"> </span><span style=3D"color:rgb(0,128,0)">I=
nitialize</span><span style=3D"color:rgb(192,192,192)"> </span><span style=
=3D"color:rgb(0,128,0)">Image</span><span style=3D"color:rgb(192,192,192)">=
</span><span style=3D"color:rgb(0,128,0)">Magick.</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(128,0,128)">Magick</span>::=
InitializeMagick(<span style=3D"color:rgb(0,0,128)">NULL</span>);</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(128,0,128)">std</span>::<sp=
an style=3D"color:rgb(128,0,128)">unique_ptr</span><<span style=3D"color=
:rgb(128,0,128)">Magick</span>::<span style=3D"color:rgb(128,0,128)">Image<=
/span>><span style=3D"color:rgb(192,192,192)"> </span>image<span style=
=3D"color:rgb(192,192,192)"> </span>=3D<span style=3D"color:rgb(192,192,192=
)"> </span><span style=3D"color:rgb(128,0,128)">std</span>::make_unique<=
Magick::Image>(<span style=3D"color:rgb(0,128,0)">"C:/Users/Giovann=
i/Desktop/interlaced.png"</span>);</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(128,0,128)">QString</span><=
span style=3D"color:rgb(192,192,192)"> </span>outFileName<span style=3D"col=
or:rgb(192,192,192)"> </span>=3D<span style=3D"color:rgb(192,192,192)"> </s=
pan><span style=3D"color:rgb(0,128,0)">"C:/Users/Giovanni/Desktop/outp=
ut.png"</span>;</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(128,0,128)">QFile</span><sp=
an style=3D"color:rgb(192,192,192)"> </span>out(outFileName);</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(128,0,128)">Magick</span>::=
<span style=3D"color:rgb(128,0,128)">Blob</span><span style=3D"color:rgb(19=
2,192,192)"> </span>blob;</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(128,128,0)">bool</span><spa=
n style=3D"color:rgb(192,192,192)"> </span>success<span style=3D"color:rgb(=
192,192,192)"> </span>=3D<span style=3D"color:rgb(192,192,192)"> </span><sp=
an style=3D"color:rgb(128,128,0)">true</span>;</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(128,128,0)">try</span><span=
style=3D"color:rgb(192,192,192)"> </span>{</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span>image->write(&blob,<span style=3D"color:r=
gb(192,192,192)"> </span><span style=3D"color:rgb(0,128,0)">"PNG"=
</span>,<span style=3D"color:rgb(192,192,192)"> </span><span style=3D"color=
:rgb(0,0,128)">8</span>);</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span>}<span style=3D"color:rgb(192,192,192)"> </span><spa=
n style=3D"color:rgb(128,128,0)">catch</span><span style=3D"color:rgb(192,1=
92,192)"> </span>(<span style=3D"color:rgb(128,0,128)">Magick</span>::<span=
style=3D"color:rgb(128,0,128)">Exception</span><span style=3D"color:rgb(19=
2,192,192)"> </span>&error)<span style=3D"color:rgb(192,192,192)"> </sp=
an>{</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span>success<span style=3D"color:rgb(192,192,192)"> <=
/span>=3D<span style=3D"color:rgb(192,192,192)"> </span><span style=3D"colo=
r:rgb(128,128,0)">false</span>;</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(0,0,128)">qDebug</span>=
()<span style=3D"color:rgb(192,192,192)"> </span><<<span style=3D"col=
or:rgb(192,192,192)"> </span><span style=3D"color:rgb(128,0,128)">QString</=
span>(<span style=3D"color:rgb(0,128,0)">"Error</span><span style=3D"c=
olor:rgb(192,192,192)"> </span><span style=3D"color:rgb(0,128,0)">writing</=
span><span style=3D"color:rgb(192,192,192)"> </span><span style=3D"color:rg=
b(0,128,0)">in</span><span style=3D"color:rgb(192,192,192)"> </span><span s=
tyle=3D"color:rgb(0,128,0)">memory</span><span style=3D"color:rgb(192,192,1=
92)"> </span><span style=3D"color:rgb(0,128,0)">BLOB</span><span style=3D"c=
olor:rgb(192,192,192)"> </span><span style=3D"color:rgb(0,128,0)">for</span=
><span style=3D"color:rgb(192,192,192)"> </span><span style=3D"color:rgb(0,=
128,0)">image</span><span style=3D"color:rgb(192,192,192)"> </span><span st=
yle=3D"color:rgb(0,128,0)">%1"</span>).arg(outFileName);</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(0,0,128)">qDebug</span>=
()<span style=3D"color:rgb(192,192,192)"> </span><<<span style=3D"col=
or:rgb(192,192,192)"> </span>error.<span style=3D"font-style:italic;color:r=
gb(0,0,0)">what</span>();</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span>}</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(128,128,0)">if</span><span =
style=3D"color:rgb(192,192,192)"> </span>(success)<span style=3D"color:rgb(=
192,192,192)"> </span>{</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span>success<span style=3D"color:rgb(192,192,192)"> <=
/span>=3D<span style=3D"color:rgb(192,192,192)"> </span>out.<span style=3D"=
font-style:italic;color:rgb(0,0,0)">open</span>(<span style=3D"color:rgb(12=
8,0,128)">QIODevice</span>::<span style=3D"color:rgb(128,0,128)">WriteOnly<=
/span>);</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(128,128,0)">if</span><s=
pan style=3D"color:rgb(192,192,192)"> </span>(!success)<span style=3D"color=
:rgb(192,192,192)"> </span>{</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(0,0,128)">qDebug</s=
pan>()<span style=3D"color:rgb(192,192,192)"> </span><<<span style=3D=
"color:rgb(192,192,192)"> </span><span style=3D"color:rgb(128,0,128)">QStri=
ng</span>(<span style=3D"color:rgb(0,128,0)">"Error</span><span style=
=3D"color:rgb(192,192,192)"> </span><span style=3D"color:rgb(0,128,0)">open=
ing</span><span style=3D"color:rgb(192,192,192)"> </span><span style=3D"col=
or:rgb(0,128,0)">file</span><span style=3D"color:rgb(192,192,192)"> </span>=
<span style=3D"color:rgb(0,128,0)">for</span><span style=3D"color:rgb(192,1=
92,192)"> </span><span style=3D"color:rgb(0,128,0)">writing</span><span sty=
le=3D"color:rgb(192,192,192)"> </span><span style=3D"color:rgb(0,128,0)">im=
age</span><span style=3D"color:rgb(192,192,192)"> </span><span style=3D"col=
or:rgb(0,128,0)">%1"</span>).arg(outFileName);</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span>}</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span>}</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(128,128,0)">if</span><span =
style=3D"color:rgb(192,192,192)"> </span>(success)<span style=3D"color:rgb(=
192,192,192)"> </span>{</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(0,128,0)">//</span><spa=
n style=3D"color:rgb(192,192,192)"> </span><span style=3D"color:rgb(0,128,0=
)">@see</span><span style=3D"color:rgb(192,192,192)"> </span><span style=3D=
"color:rgb(0,128,0)"><a href=3D"http://stackoverflow.com/questions/17108472=
/how-to-get-buffer-from-imagemagick-image-in-c">http://stackoverflow.com/qu=
estions/17108472/how-to-get-buffer-from-imagemagick-image-in-c</a></span></=
pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(128,0,128)">QByteArray<=
/span><span style=3D"color:rgb(192,192,192)"> </span>array(<span style=3D"c=
olor:rgb(128,128,0)">static_cast</span><<span style=3D"color:rgb(128,128=
,0)">const</span><span style=3D"color:rgb(192,192,192)"> </span><span style=
=3D"color:rgb(128,128,0)">char</span>*>(blob.data()),<span style=3D"colo=
r:rgb(192,192,192)"> </span>blob.length());</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(128,0,128)">qint64</spa=
n><span style=3D"color:rgb(192,192,192)"> </span>bytesWritten<span style=3D=
"color:rgb(192,192,192)"> </span>=3D<span style=3D"color:rgb(192,192,192)">=
</span>out.write(array);</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(128,128,0)">if</span><s=
pan style=3D"color:rgb(192,192,192)"> </span>(bytesWritten<span style=3D"co=
lor:rgb(192,192,192)"> </span><<span style=3D"color:rgb(192,192,192)"> <=
/span><span style=3D"color:rgb(0,0,128)">0</span>)<span style=3D"color:rgb(=
192,192,192)"> </span>{</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span>success<span style=3D"color:rgb(192,192,192)=
"> </span>=3D<span style=3D"color:rgb(192,192,192)"> </span><span style=3D"=
color:rgb(128,128,0)">false</span>;</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span><span style=3D"color:rgb(0,0,128)">qDebug</s=
pan>()<span style=3D"color:rgb(192,192,192)"> </span><<<span style=3D=
"color:rgb(192,192,192)"> </span><span style=3D"color:rgb(128,0,128)">QStri=
ng</span>(<span style=3D"color:rgb(0,128,0)">"Error</span><span style=
=3D"color:rgb(192,192,192)"> </span><span style=3D"color:rgb(0,128,0)">writ=
ing</span><span style=3D"color:rgb(192,192,192)"> </span><span style=3D"col=
or:rgb(0,128,0)">file</span><span style=3D"color:rgb(192,192,192)"> </span>=
<span style=3D"color:rgb(0,128,0)">for</span><span style=3D"color:rgb(192,1=
92,192)"> </span><span style=3D"color:rgb(0,128,0)">image</span><span style=
=3D"color:rgb(192,192,192)"> </span><span style=3D"color:rgb(0,128,0)">%1&q=
uot;</span>).arg(outFileName);</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span>}</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)"> </span>}</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">}</pre></div><div><br></div=
><div><div class=3D"gmail_signature"><br></div>
</div></div></div>
--001a113ac7ea0ab25a05442f9673--
--===============2788760098354574458==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
--===============2788760098354574458==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Graphicsmagick-apis mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/graphicsmagick-apis
--===============2788760098354574458==--