info-sather
[Top][All Lists]
Advanced

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

Coupla things


From: Sather User
Subject: Coupla things
Date: Wed, 28 Dec 2011 23:14:20 +1030 (CST)

Something I meant to say re doing TIFF stuff directly in Sather rather
than calling libtiff.  An advantage of Sather is that all tags,
whether ASCII (CHAR), or SHORT or LONG (which both become INT) or
rationals (RAT) etc... they are all < $STR, all subclasses of $STR, so
a variable of type $STR will do for them all in many cases.  And you
can look up the value of a tag using the actual tag identifier, which
becomes an INT in Sather, or using its self-explanatory name, and use
the same routine for both, because either way they too are of type $STR.

The values of a tag in an image file directory are in general an
array, though in many cases it has only one element, and it's easy to
be general if you only want to look up the first array value, hence
IFD::tell1st($STR):$STR, whose argument may be an INT or a STR.  IFDEs
are IFD entries, the identifying tag, its type etc. and values.  The
tags in an IFD are always sorted, or I should say the IFD entries are
sorted according to their tag (numeric) values.  There may not be
enough of them to justify other than a linear search, but the Sather
class ARRAY{TY} has a binary search method, so for ifdes:ARRAY{IFDE}
why not create a fake IFDE containing just the target tag and ...

TAG_LOOKUP::int(v:$STR) returns its argument if an INT and does an
FMAP lookup for the INT if it's a STR.  There are quicker ways of
doing things, perhaps, but they won't be more intelligible.

   tell1st(tag:$STR):$STR is
      -- There is an ARRAY{IFDE} sorted by tag within which there may
      -- be one that has the argument tag.  Search the array for the
      -- IFDE with that tag.  Return the first value of the tag.
      -- Binary search version.
      t::=TAG_LOOKUP::int(tag);
      x::=ifdes.binary_search(#IFDE(t));
      if x = -1 then
         TIFF::defaulted := true;
         return TAG_LOOKUP::default.get(t)
      end;
      TIFF::defaulted := false;
      return ifdes[x].values[0]
   end;
...
   is_uncompressed:BOOL is
      c::=tell1st("Compression");
      typecase c
      when INT then
         if c /= 1 then return false end
      end;
      return true
   end;

or something.

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

Anyway, back on track, here fixes to a couple of ICSI boo-boos re
unsigned arithmetic surviving in GNU sather-1.2.3.

--- sather-1.2.3/System/Common/runtime.h        2007-07-01 13:23:37.000000000 
+0930
+++ Sather-1.2b8/System/Common/runtime.h        2011-09-19 23:30:58.000000000 
+0930
...
-#define INTUMINUS(x,y)  CHKOK(y<=x,"Integer overflow on unsigned 
minus",((unsigned)x)-((unsigned)y))
+#define INTUMINUS(x,y)  CHKOK((unsigned)y<=(unsigned)x,"Integer overflow on 
unsigned minus",((unsigned)x)-((unsigned)y))

In the next, unsigned less-than, just reverse everything.

--- sather-1.2.3/Library/Base/int.sa    2007-07-01 13:23:34.000000000 +0930
+++ Sather-1.2b8/Library/Base/int.sa    2011-09-24 13:40:19.000000000 +0930
...
    is_ult(lhs:SAME):BOOL is
-      if self>=0 and lhs<0 then return true end;
-      if self<0 and lhs>=0 then return false end;
+      if self>=0 and lhs<0 then return false end;
+      if self<0 and lhs>=0 then return true end;
       -- both (self and lhs) have the same sign
       return self<lhs;
    end;

Happy New Year!

-- 
Michael Talbot-Wilson



reply via email to

[Prev in Thread] Current Thread [Next in Thread]