PNG and JPEG images

General TRichView support forum. Please post your questions here
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

PNG and JPEG images

Post 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
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: PNG and JPEG images

Post by Sergey Tkachenko »

Please give me step-by-step instructions how to reproduce this problem.
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: PNG and JPEG images

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: PNG and JPEG images

Post 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
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: PNG and JPEG images

Post by jgkoehn »

Greetings Sergey,
I sent the email over from jgkthewordbookscom
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: PNG and JPEG images

Post by Sergey Tkachenko »

I received it, need some time to test.
csterg
Posts: 306
Joined: Fri Nov 25, 2005 9:09 pm

Re: PNG and JPEG images

Post 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
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: PNG and JPEG images

Post 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.
csterg
Posts: 306
Joined: Fri Nov 25, 2005 9:09 pm

Re: PNG and JPEG images

Post 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?
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: PNG and JPEG images

Post 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);
csterg
Posts: 306
Joined: Fri Nov 25, 2005 9:09 pm

Re: PNG and JPEG images

Post by csterg »

Great, thanks
csterg
Posts: 306
Joined: Fri Nov 25, 2005 9:09 pm

Re: PNG and JPEG images

Post 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
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: PNG and JPEG images

Post by Sergey Tkachenko »

Currently, our advanced scaling is applied only to non-transparent images. Probably, this PNG contains semitransparent pixels.
csterg
Posts: 306
Joined: Fri Nov 25, 2005 9:09 pm

Re: PNG and JPEG images

Post by csterg »

Just to know: was this any different in RV14? Because, looking at the code, it seems the same.
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: PNG and JPEG images

Post by Sergey Tkachenko »

The code that determines which pictures are transparent was changed.
Post Reply