Re: Issue with PNG and Blog inw Windows using MinGW64

Giovanni Remigi <[email protected]> Thu, 5 Jan 2017 10:52:23 +0000
Newsgroups gmane.comp.video.graphicsmagick.apis
Message-ID <CACjhwVNjEegugGG-Ak6CcrqBT+G-Y0fJAYEySnNVW0ofyGz=CA@mail.gmail.com>
--===============2392452403152546526==
Content-Type: multipart/alternative; boundary=94eb2c09d61240b3e5054556b27d

--94eb2c09d61240b3e5054556b27d
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

The problem with saving the BLOB to file is Qt related and has nothing to
do with Graphics Magick.

I proved this using the following code. I can save copy a BLOB to file
correctly.

        std::ofstream outFile;

        outFile.open("C:/Users/Giovanni/Desktop/output.png",
std::ios::out | std::ios::binary);

        // blob.data() returns a void* with the actual data,
blob.length() tells you how much data is there

        outFile.write((char*)blob.data(),blob.length());

        outFile.close();



On 5 January 2017 at 10:24, Giovanni Remigi <[email protected]>
wrote:

> >> 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.
> >
> >By "UTF characters" do you mean UTF-16?  GraphicsMagick can work ok
> >with UTF-8.  What do you mean by "files containing UTF characters on
> >Windows"?
>
> Yes I meant UTF-16 on Windows e.g. "=C4=9F=C4=9E=C4=B1=C4=B0=C3=B6=C3=96=
=C3=BC=C3=9C=C5=9F=C5=9E=C3=A7=C3=87.png". GraphicsMagick UTF-8 works perfe=
ctly on Linux and Mac but not on Windows. I searched for a while until I de=
cided to go for the Blob workaround.
>
> >
> >> I found a workaround reading an image into a Blob using Qt and then re=
ading
> >> 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 la=
st
> >> 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 don't know anything about QByteArray but it seems to me
> >that bytesWritten should equal blob.length() on success.
>
> I changed the code to check blob.length() as you suggested. When I'm tryi=
ng to save a big image the number of bytes written is less than blob.length=
(). In fact the saved image is displayed with a big black band at the botto=
m. I'm not sure the reason. It happens only with big images and of course, =
on Windows only :-( Small images work fine.
>
> I wonder if there is a limitation on the max size of a blob object in mem=
ory.
>
> >
> >> I somehow blame libpng16. On Linux I use libpng12. Using the JPEG form=
at I
> >> do not experience data loss.
> >
> >Are you sure that your Qt build is using a consistent libpng version?
> >Is it possible that Qt is built against a different libpng than
> >GraphicsMagick was built against?
>
> It shouldn't matter. Qt simply transfer the blob from memory to file and =
from file to memory. It doesn't use libpng in this process.
>
> >
> >Bob
> >--
> >Bob Friesenhahn
> >bfriesen@..., http://www.simplesystems.org/users/bfriesen/
> >GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/
>
>


--=20
Giovanni Remigi
[email protected]
www.kineticsystem.org
+353 87 2815898

--94eb2c09d61240b3e5054556b27d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">The problem with saving the BLOB to file is Qt related and=
 has nothing to do with Graphics Magick.<div><br></div><div>I proved this u=
sing the following code. I can save copy a BLOB to file correctly.</div><di=
v><br></div><div>
<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>:=
:<span style=3D"color:rgb(128,0,128)">ofstream</span><span style=3D"color:r=
gb(192,192,192)"> </span>outFile;</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)">        </span>outFile.open(<span style=3D"color:rgb(0,128,0)">=
&quot;C:/Users/Giovanni/Desktop/output.png&quot;</span>,<span style=3D"colo=
r:rgb(192,192,192)"> </span><span style=3D"color:rgb(128,0,128)">std</span>=
::<span style=3D"color:rgb(128,0,128)">ios</span>::out<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)">std</span>::<span style=3D"color:rgb(12=
8,0,128)">ios</span>::binary);</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=
)">blob.data()</span><span style=3D"color:rgb(192,192,192)"> </span><span s=
tyle=3D"color:rgb(0,128,0)">returns</span><span style=3D"color:rgb(192,192,=
192)"> </span><span style=3D"color:rgb(0,128,0)">a</span><span style=3D"col=
or:rgb(192,192,192)"> </span><span style=3D"color:rgb(0,128,0)">void*</span=
><span style=3D"color:rgb(192,192,192)"> </span><span style=3D"color:rgb(0,=
128,0)">with</span><span style=3D"color:rgb(192,192,192)"> </span><span sty=
le=3D"color:rgb(0,128,0)">the</span><span style=3D"color:rgb(192,192,192)">=
 </span><span style=3D"color:rgb(0,128,0)">actual</span><span style=3D"colo=
r:rgb(192,192,192)"> </span><span style=3D"color:rgb(0,128,0)">data,</span>=
<span style=3D"color:rgb(192,192,192)"> </span><span style=3D"color:rgb(0,1=
28,0)">blob.length()</span><span style=3D"color:rgb(192,192,192)"> </span><=
span style=3D"color:rgb(0,128,0)">tells</span><span style=3D"color:rgb(192,=
192,192)"> </span><span style=3D"color:rgb(0,128,0)">you</span><span style=
=3D"color:rgb(192,192,192)"> </span><span style=3D"color:rgb(0,128,0)">how<=
/span><span style=3D"color:rgb(192,192,192)"> </span><span style=3D"color:r=
gb(0,128,0)">much</span><span style=3D"color:rgb(192,192,192)"> </span><spa=
n style=3D"color:rgb(0,128,0)">data</span><span style=3D"color:rgb(192,192,=
192)"> </span><span style=3D"color:rgb(0,128,0)">is</span><span style=3D"co=
lor:rgb(192,192,192)"> </span><span style=3D"color:rgb(0,128,0)">there</spa=
n></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)">        </span>outFile.write((<span style=3D"color:rgb(128,128,=
0)">char</span>*)blob.data(),blob.length());</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(19=
2,192,192)">        </span>outFile.close();</pre><pre style=3D"margin-top:0=
px;margin-bottom:0px"><br></pre></div></div><div class=3D"gmail_extra"><br>=
<div class=3D"gmail_quote">On 5 January 2017 at 10:24, Giovanni Remigi <spa=
n dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_=
blank">[email protected]</a>&gt;</span> wrote:<br><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pad=
ding-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_extra"><pre style=3D"ma=
rgin-top:0px;margin-bottom:0px;padding:15px;border-width:0px 0px 0px 1px;bo=
rder-top-style:initial;border-right-style:initial;border-bottom-style:initi=
al;border-left-style:solid;border-top-color:initial;border-right-color:init=
ial;border-bottom-color:initial;border-left-color:rgb(229,229,229);outline:=
0px;vertical-align:baseline;background-image:initial;background-position:in=
itial;background-size:initial;background-repeat:initial;background-origin:i=
nitial;background-clip:initial;word-wrap:break-word;overflow:auto"><font co=
lor=3D"#555555" face=3D"monospace, sans-serif"><span style=3D"font-size:13p=
x;white-space:pre-wrap">&gt;&gt; I&#39;m aware that GraphicsMagick does not=
 support files containing UTF
&gt;&gt; characters on Windows. I&#39;m using GraphicsMagick as a DLL and I=
f I try
&gt;&gt; reading from such files my application crashes.
&gt;
&gt;By &quot;UTF characters&quot; do you mean UTF-16?  GraphicsMagick can w=
ork ok=20
&gt;with UTF-8.  What do you mean by &quot;files containing UTF characters =
on=20
&gt;Windows&quot;?</span></font></pre><pre style=3D"margin-top:0px;margin-b=
ottom:0px;padding:15px;border-width:0px 0px 0px 1px;border-top-style:initia=
l;border-right-style:initial;border-bottom-style:initial;border-left-style:=
solid;border-top-color:initial;border-right-color:initial;border-bottom-col=
or:initial;border-left-color:rgb(229,229,229);outline:0px;vertical-align:ba=
seline;background-image:initial;background-position:initial;background-size=
:initial;background-repeat:initial;background-origin:initial;background-cli=
p:initial;word-wrap:break-word;overflow:auto"><font color=3D"#555555" face=
=3D"monospace, sans-serif"><span style=3D"font-size:13px;white-space:pre-wr=
ap">Yes I meant UTF-16 on Windows e.g. &quot;=C4=9F=C4=9E=C4=B1=C4=B0=C3=B6=
=C3=96=C3=BC=C3=9C=C5=9F=C5=9E=C3=A7=C3=87.png&quot;. GraphicsMagick UTF-8 =
works perfectly on Linux and Mac but not on Windows. I searched for a while=
 until I decided to go for the Blob workaround.</span></font></pre><pre sty=
le=3D"margin-top:0px;margin-bottom:0px;padding:15px;border-width:0px 0px 0p=
x 1px;border-top-style:initial;border-right-style:initial;border-bottom-sty=
le:initial;border-left-style:solid;border-top-color:initial;border-right-co=
lor:initial;border-bottom-color:initial;border-left-color:rgb(229,229,229);=
outline:0px;vertical-align:baseline;background-image:initial;background-pos=
ition:initial;background-size:initial;background-repeat:initial;background-=
origin:initial;background-clip:initial;word-wrap:break-word;overflow:auto">=
<font color=3D"#555555" face=3D"monospace, sans-serif"><span style=3D"font-=
size:13px;white-space:pre-wrap">&gt;
&gt;&gt; I found a workaround reading an image into a Blob using Qt and the=
n reading
&gt;&gt; the Blob from memory using GraphicsMagick. This works perfectly bu=
t I have
&gt;&gt; an issue with the opposite operation writing a Blob into a file.
&gt;&gt;
&gt;&gt; When I encode an Image into a Blob in PNG format using Graphics Ma=
gick and
&gt;&gt; I write the Blob into a file using Qt I experience a data loss. Th=
e last
&gt;&gt; part of the image appears black.
&gt;&gt; The problem happens only *with big PNG* ( &gt; 32MB) and* on WIndo=
ws only*,
&gt;&gt; while on Linux it works perfectly.
&gt;
&gt;I don&#39;t know anything about QByteArray but it seems to me=20
&gt;that bytesWritten should equal blob.length() on success.</span></font><=
/pre><pre style=3D"margin-top:0px;margin-bottom:0px;padding:15px;border-wid=
th:0px 0px 0px 1px;border-top-style:initial;border-right-style:initial;bord=
er-bottom-style:initial;border-left-style:solid;border-top-color:initial;bo=
rder-right-color:initial;border-bottom-color:initial;border-left-color:rgb(=
229,229,229);outline:0px;vertical-align:baseline;background-image:initial;b=
ackground-position:initial;background-size:initial;background-repeat:initia=
l;background-origin:initial;background-clip:initial;word-wrap:break-word;ov=
erflow:auto"><font color=3D"#555555" face=3D"monospace, sans-serif"><span s=
tyle=3D"font-size:13px;white-space:pre-wrap">I changed the code to check bl=
ob.length() as you suggested. When I&#39;m trying to save a big image the n=
umber of bytes written is less than blob.length(). In fact the saved image =
is displayed with a big black band at the bottom. I&#39;m not sure the reas=
on. It happens only with big images and of course, on Windows only :-( Smal=
l images work fine.</span></font></pre><pre style=3D"margin-top:0px;margin-=
bottom:0px;padding:15px;border-width:0px 0px 0px 1px;border-top-style:initi=
al;border-right-style:initial;border-bottom-style:initial;border-left-style=
:solid;border-top-color:initial;border-right-color:initial;border-bottom-co=
lor:initial;border-left-color:rgb(229,229,229);outline:0px;vertical-align:b=
aseline;background-image:initial;background-position:initial;background-siz=
e:initial;background-repeat:initial;background-origin:initial;background-cl=
ip:initial;word-wrap:break-word;overflow:auto"><font color=3D"#555555" face=
=3D"monospace, sans-serif"><span style=3D"font-size:13px;white-space:pre-wr=
ap">I wonder if there is a limitation on the max size of a blob object in m=
emory.</span></font></pre><pre style=3D"margin-top:0px;margin-bottom:0px;pa=
dding:15px;border-width:0px 0px 0px 1px;border-top-style:initial;border-rig=
ht-style:initial;border-bottom-style:initial;border-left-style:solid;border=
-top-color:initial;border-right-color:initial;border-bottom-color:initial;b=
order-left-color:rgb(229,229,229);outline:0px;vertical-align:baseline;backg=
round-image:initial;background-position:initial;background-size:initial;bac=
kground-repeat:initial;background-origin:initial;background-clip:initial;wo=
rd-wrap:break-word;overflow:auto"><font color=3D"#555555" face=3D"monospace=
, sans-serif"><span style=3D"font-size:13px;white-space:pre-wrap">&gt;
&gt;&gt; I somehow blame libpng16. On Linux I use libpng12. Using the JPEG =
format I
&gt;&gt; do not experience data loss.
&gt;
&gt;Are you sure that your Qt build is using a consistent libpng version?=
=20
&gt;Is it possible that Qt is built against a different libpng than=20
&gt;GraphicsMagick was built against?</span></font></pre><pre style=3D"marg=
in-top:0px;margin-bottom:0px;padding:15px;border-width:0px 0px 0px 1px;bord=
er-top-style:initial;border-right-style:initial;border-bottom-style:initial=
;border-left-style:solid;border-top-color:initial;border-right-color:initia=
l;border-bottom-color:initial;border-left-color:rgb(229,229,229);outline:0p=
x;vertical-align:baseline;background-image:initial;background-position:init=
ial;background-size:initial;background-repeat:initial;background-origin:ini=
tial;background-clip:initial;word-wrap:break-word;overflow:auto"><font colo=
r=3D"#555555" face=3D"monospace, sans-serif"><span style=3D"font-size:13px;=
white-space:pre-wrap">It shouldn&#39;t matter. Qt simply transfer the blob =
from memory to file and from file to memory. It doesn&#39;t use libpng in t=
his process.</span></font></pre><pre style=3D"margin-top:0px;margin-bottom:=
0px;padding:15px;border-width:0px 0px 0px 1px;border-top-style:initial;bord=
er-right-style:initial;border-bottom-style:initial;border-left-style:solid;=
border-top-color:initial;border-right-color:initial;border-bottom-color:ini=
tial;border-left-color:rgb(229,229,229);outline:0px;vertical-align:baseline=
;background-image:initial;background-position:initial;background-size:initi=
al;background-repeat:initial;background-origin:initial;background-clip:init=
ial;word-wrap:break-word;overflow:auto"><font color=3D"#555555" face=3D"mon=
ospace, sans-serif"><span style=3D"font-size:13px;white-space:pre-wrap">&gt=
;
&gt;Bob
&gt;--=20
&gt;Bob Friesenhahn
&gt;bfriesen@..., <a href=3D"http://www.simplesystems.org/users/bfriesen/" =
target=3D"_blank">http://www.simplesystems.org/<wbr>users/bfriesen/</a>
&gt;GraphicsMagick Maintainer,    <a href=3D"http://www.GraphicsMagick.org/=
" target=3D"_blank">http://www.GraphicsMagick.org/</a>
</span></font></pre>
</div></div>
</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br><div class=
=3D"gmail_signature" data-smartmail=3D"gmail_signature">Giovanni Remigi<br>=
<a href=3D"mailto:[email protected]" target=3D"_blank">g.remigi@ki=
neticsystem.org</a><br><a href=3D"http://www.kineticsystem.org" target=3D"_=
blank">www.kineticsystem.org</a><br>+353 87 2815898</div>
</div>

--94eb2c09d61240b3e5054556b27d--


--===============2392452403152546526==
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
--===============2392452403152546526==
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

--===============2392452403152546526==--