Page 1 of 2

PNG and JPEG images

Posted: Wed Apr 01, 2020 10:03 pm
by jgkoehn
Greetings Sergey,
When I load a JPEG in Ms Word and resize it that carries over to RVF in the rtf format.
However, if I load a PNG in Ms Word and reisize it that does not carry over correctly to RVF.
The visual size is correct but the image appears to be cropped.

I used this page for png https://www.trichview.com/forums/viewtopic.php?t=89

Re: PNG and JPEG images

Posted: Thu Apr 02, 2020 7:07 am
by Sergey Tkachenko
Please give me step-by-step instructions how to reproduce this problem.

Re: PNG and JPEG images

Posted: Thu Apr 02, 2020 1:00 pm
by jgkoehn
1. In a MS Word file. I am in ms word 365
2. load a png image through insert>picture file
3. Now resize the image with the msword picture handles they are little boxes that appear when you click the image. Resizd it a lot smaller than the original to see this issue quicker
4. Now save to rtf and load it in rvf 18.3 (I have my rvf to load a lot as png to save on space)
5. I followed the png procedure for png since I am in delphi7
6. I am not surr if I am just missing a setting if I do this with Jpeg it is fine.

Re: PNG and JPEG images

Posted: Thu Apr 02, 2020 4:50 pm
by Sergey Tkachenko
After loading this RTF in TRichView, please save it as RVF file, and send the both files (RTF and RVF) to me to email richviewgmailcom

Re: PNG and JPEG images

Posted: Thu Apr 02, 2020 6:36 pm
by jgkoehn
Greetings Sergey,
I sent the email over from jgkthewordbookscom

Re: PNG and JPEG images

Posted: Thu Apr 02, 2020 7:57 pm
by Sergey Tkachenko
I received it, need some time to test.

Re: PNG and JPEG images

Posted: Sun Apr 12, 2020 6:54 pm
by csterg
I verify this behavior.
It seems that PNG images are not resampled. Setting rvepImageWidth and rvepImageHeight with SetItemExtraIntProperty does change the graphic size on the canvas, yet the image is not resampled but it is displayed in the original size, thus cropped to the given dimensions.

This used to work in RV14 (my last version), broken in RV17.

Thanks

Re: PNG and JPEG images

Posted: Sun Apr 12, 2020 7:38 pm
by Sergey Tkachenko
The source of the original problem (reported by jgkoehn) was a wrong version of TPNGObject.
While he had the correct version, another version was used to compile the project (because its folder was listed first in the Delphi library paths).

After fixing the library paths, the problem was solved.

PS: TPNGObject is needed for Delphi 2007 and older. For newer version of Delphi, a built-in TPNGImage is used.

Re: PNG and JPEG images

Posted: Mon Apr 20, 2020 3:33 pm
by csterg
I am using D7 with a version of pngobject that used to work with RV14.
Can you give me some pointer to the code to see where resizing happens or is decided so i can step through the code to try to find out what the problem is?

Re: PNG and JPEG images

Posted: Mon Apr 20, 2020 5:35 pm
by Sergey Tkachenko
Resizing itself does not change the image, it only changes ImageWidth and ImageHeight properties.
You can check how the picture is drawn.

Check RVItem.pas,TRVGraphicItemInfo.Paint.
In this procedure, two options are possible.
1) The item may create a thumbnail for scaled image, it happens on the line

Code: Select all

  ImageCopy := RVThumbnailMaker.MakeThumbnail(GraphicHolder.Graphic,
          wScaled, hScaled);
2) The item may draw the image as it is, it happens on the line

Code: Select all

          Style.GraphicInterface.StretchDrawGraphic(Canvas,
            Bounds(X, Y, w, h), Image);

Re: PNG and JPEG images

Posted: Tue Apr 21, 2020 7:59 am
by csterg
Great, thanks

Re: PNG and JPEG images

Posted: Sun Sep 13, 2020 6:14 pm
by csterg
Hi Sergey,
coming back to this to bring up the issue of quality.
I followed the code path and, as you said, when resizing an image it ends up to pnimage.pas -> TPngObject.Draw where StretchDiBits is used that is very simplistic (e.g. no serious interpolation). Obviously the image quality during down-sizing is not good, yet my question is why in RV14 the quality was good, whereas in RV17 i now upgraded to the quality is bad. The difference in quality is quite large.
Did you change something to the way images are drawn?

Thanks

Re: PNG and JPEG images

Posted: Mon Sep 14, 2020 10:42 am
by Sergey Tkachenko
Currently, our advanced scaling is applied only to non-transparent images. Probably, this PNG contains semitransparent pixels.

Re: PNG and JPEG images

Posted: Sun Sep 20, 2020 5:14 pm
by csterg
Just to know: was this any different in RV14? Because, looking at the code, it seems the same.

Re: PNG and JPEG images

Posted: Mon Sep 21, 2020 10:39 am
by Sergey Tkachenko
The code that determines which pictures are transparent was changed.