Re: [GnomeMeeting-devel-list] [PATCH] vfakeio modification



Am Montag, 9. Februar 2004 18:11 schrieb PUYDT Julien:
> On lun, 2004-02-09 at 10:50, Damien Sandras wrote:
> > Notice that if you select a image bigger than the video size, you only
> > have black. Was it your intended behavior? The old behavior in 0.98.5
> > was resizing the image.
>
> The following patch changes that behaviour:
> * if the image fits in the preview, it is centered;
> * if it doesn't, it is first scaled (1:1 to keep the best result), then
> centered.
>
> Rants:
> * the gdk-pixbuf doc is unclear;
> * gdk-pixbuf stores image size in (int) instead of the saner (unsigned);
> * the C language's implicit conversions sucks.
>
> Snark

I think you can make the code a bit simpler:

--------------------------
Original version:
+      else { /* the picture doesn't fit: scale 1:1, and center */
+       double scale_w, scale_h, scale;
+       
+       if (width < (unsigned)orig_width)
+         scale_w = (double)width / orig_width;
+       else
+         scale_w = 1;
+       
+       if (height < (unsigned)orig_height)
+         scale_h = (double)height / orig_height;
+       else
+         scale_h = 1;
+       
+       if (scale_w < scale_h)
+         scale = scale_w;
+       else
+         scale = scale_h;

Faster version:
+      else { /* the picture doesn't fit: scale 1:1, and center */
+       double scale_w, scale_h, scale;
+       
+       scale_w = (double)width / orig_width;
+       scale_h = (double)height / orig_height;
+       
+       if (scale_w < scale_h)
+         scale = scale_w;
+       else
+         scale = scale_h;

at least one of the two scales will be smaller than one, so just take the 
smaller one of the two.

even faster version:
+      else { /* the picture doesn't fit: scale 1:1, and center */
+       double scale;
+       
+       scale = (double)width / orig_width;
+       
+       if ( ((double)height / orig_height) < scale)
+         scale = (double)height / orig_height;

------------------------

Greets,

Stefan
-- 
Stefan Brüns  /  Kastanienweg 6 - Zimmer 1206  /  52074 Aachen
mailto:lurch gmx li  http://www.kawo1.rwth-aachen.de/~lurchi/
   phone: +49 241 169-4206     mobile: +49 160 7532733 

Attachment: pgpb81yIA4YAH.pgp
Description: signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]