[poppler] Image Resolution check

Andreas Zwinkau beza1e1 at web.de
Mon Aug 1 00:07:32 PDT 2011


Answering my own question:

I forgot that the position on the page (translation) is also included
into the transformation. So my code actually calculated the position
of the bottom left corner of the image.

Also, i did not think of rotation. Hence, the correct code is:

                void checkResolution(int width, int height, GfxState *state) {
                        /* top left */
                        double device_tlx, device_tly;
                        state->transform(0.0,0.0,&device_tlx,&device_tly);
                        /* top right */
                        double device_trx, device_try;
                        state->transform(1.0,0.0,&device_trx,&device_try);
                        /* bottom left */
                        double device_blx, device_bly;
                        state->transform(0.0,1.0,&device_blx,&device_bly);
                        /* transformed width and height */
                        double device_width  =
distance(device_tlx-device_trx, device_tly-device_try);
                        double device_height =
distance(device_tlx-device_blx, device_tly-device_bly);
                        printf("drawImage %dx%d -device->
%.0fx%.0f\n", width, height, device_width, device_height);
                }

This code compute the positions of the top-left, top-right, and
bottom-left corners of the image. The width is the (euclidian)
distance between top-left and top-right. Likewise, the height is the
distance between top-left and bottom-left.

The ratio is now correct:
drawImage 1162x256 -device-> 610x129
drawImage 262x997 -device-> 484x1835

What, i'm still not 100% sure about are the units. The result is
"dots" aka "pixels"? This means in the example above, the first image
has more than sufficient resolution, but the second one is rendered
nearly twice as big and should have been higher resolution.

Thanks for listening! ;)

On Sat, Jul 30, 2011 at 12:44 PM, Andreas Zwinkau <beza1e1 at web.de> wrote:
> I want to check the resolution of images within pdfs. I made myself an
> OutputDev class, which should  perform the check in the drawImage
> method (and alike). Here is the function, which is called for the
> check:
>
>                void checkResolution(int width, int height, GfxState *state) {
>                        double device_width, device_height;
>                        state->transform(1.0,1.0,&device_width,&device_height);
>                        printf("drawImage %dx%d -device->
> %.0fx%.0f\n", width, height, device_width, device_height);
>                }
>
> PDF 1.7 Spec says in §4.2.1: "All images are 1 unit wide by 1 unit
> high in user space, regardless of the number of samples in the image."
> Therefore i thought, the GfxState::transform method called with (1,1)
> should give me the size of the image on the output device.
> The calculated values in device_height and device_width adapt
> according to the resolution i give to displayPages, but they seem to
> be off.
>
> Some example output with small logos for 300 DPI:
> drawImage 119x119 -device-> 2386x3343
> drawImage 192x192 -device-> 2346x3380
> drawImage 118x118 -device-> 2362x3390
> drawImage 118x118 -device-> 2362x3390
> Some data with 72 DPI fed into displayPages:
> drawImage 119x119 -device-> 573x802
> drawImage 192x192 -device-> 563x811
> drawImage 118x118 -device-> 567x814
> drawImage 118x118 -device-> 567x814
> I would have expected something close to the original pixel size for
> the 72 DPI case.
> Would the 119x119 image really have to be rendered to 573x802 pixels
> for a 72 DPI OutputDev?
>
> In another example, the ratio seems to be off:
> drawImage 1162x256 -device-> 1345x1971
> drawImage 262x997 -device-> 2272x1962
> The images are not (significantly) transformed in the pdf compared to
> the originals.
>
> What did i do wrong?



-- 
Andreas Zwinkau

work email: zwinkau at kit.edu
private email: beza1e1 at web.de
homepage: http://beza1e1.tuxen.de


More information about the poppler mailing list