POV-Ray : Newsgroups : povray.general : Image resolution : Re: Image resolution Server Time
31 Jul 2024 20:13:03 EDT (-0400)
  Re: Image resolution  
From: Tim Attwood
Date: 16 Sep 2006 04:22:35
Message: <450bb44b$1@news.povray.org>
>  It would be easier to just use the command-line parameter:

There's often easier ways... like looking at the image size
in an editor.

A built-in function for this would be handy...

The file_image_size macro tries to measure the pixel width
by sampling at random for a point that differs in color from
it's neighbors. Not all images have such points, so this
can fail to report the proper sizes on low-color images.

#include "strings.inc"
#include "math.inc"

// internal macro for file_image_size
#macro seek(point, dist)
      #local rez = dist*0.1;
      #local RP_COLOR = _IMF(point.x, point.y, point.z);
      #local seekcount = 0;
      #local seekf = true;
      #local last = point;
      #while (seekf & (seekcount<11))
         #local seekcount = seekcount + 1;
         #local samp = point+seekcount*rez;
         #local TEMP_COLOR = _IMF(samp.x,samp.y,samp.z);
         #local seekf = VEq5D(RP_COLOR, TEMP_COLOR);
         #if (seekf) #local last = samp; #end
      #end
      #local zed = 0.00001; // desired accuracy
      #if ((abs(rez.x)>zed)|(abs(rez.y)>zed)|(abs(rez.z)>zed))
         #local result = seek(last, rez);
      #else
         #local result = samp;
      #end
      (result)
#end

// returns a 2D vector with the image size
// Usage: (string, string, float)
// itype = the image type
// iname = the file name
// num = the number of samples
// Example: #local G1 = file_image_size("png", "plasma3.png", 12);
#macro file_image_size(itype, iname, num)
   #local SI = "#declare _IMF = function {\n";
   #local SI = concat(SI, "pigment {\n");
   #local SI = concat(SI, "image_map {\n");
   #local SI = concat(SI, itype," \"",iname,"\"\n");
   #local SI = concat(SI, "map_type 0\n");
   #local SI = concat(SI, "once}scale 1000000}};\n");
   Parse_String(SI)
   #local S = seed(num);
   #local DX = 1000000;
   #local DY = 1000000;
   #local C = 0;
   #while (C < num)
      // a random point
      #local RP = <rand(S)*1000000,rand(S)*1000000,0>;
      #local temp = seek(RP, <DX,0,0>);
      #local xright = temp.x;
      #local temp = seek(RP, <-DX,0,0>);
      #local xleft = temp.x;
      #local temp = seek(RP, <0,DY,0>);
      #local yup = temp.y;
      #local temp = seek(RP, <0,-DY,0>);
      #local ydown = temp.y;
      // found
      #local found_DX = (xright-xleft);
      #local found_DY = (yup-ydown);
      // adjust pixel size guess
      #local DX = min(DX,found_DX);
      #local DY = min(DY,found_DY);
      #local C = C + 1;
   #end
   #undef _IMF
   #local result = <int((1/DX)*1000000+0.9999), int((1/DY)*1000000+0.9999)>;
   (result)
#end


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.