include include include # GVERIFY -- Verification of all the pixels in a group # # B.Simon 16-Feb-89 Original procedure gverify (im1, im2, maxdif, ndif) pointer im1 # i: First image pointer im2 # i: Second image int maxdif # i: Maximum number of diferences to report int ndif # io: Number of diferences so far #-- bool first int ndim, pixsize, nword, iword, diff, ipix, jpix, ibit, nbit, ioffset long vector1[IM_MAXDIM], vector2[IM_MAXDIM], pixvec[IM_MAXDIM] pointer bitvec, buffer1, buffer2, word1, word2 string errtitle "Differences between %s[%d] and %s[%d]\nPixel%16tBit List\n" string maxerrs "Maximum number of differences exceeded" int imgnls(), imgnli(), imgnll(), imgnlr(), imgnld(), imgnlx() int sizeof(), bitupk() begin first = true # Compute the size of an image pixel and image line ndim = IM_NDIM(im1) pixsize = sizeof (IM_PIXTYPE(im1)) nbit = pixsize * SZB_CHAR * NBITS_BYTE nword = (IM_LEN(im1,1) * pixsize + SZ_INT - 1) / SZ_INT # Allocate dynamic memory to hold bit vector call malloc (bitvec, nbit, TY_INT) call amovki (0, Memi[bitvec], nbit) call amovkl (long(1), vector1, IM_MAXDIM) call amovkl (long(1), vector2, IM_MAXDIM) repeat { # Read the next line from each image if (ndim > 1) call amovkl (vector1[2], pixvec[2], ndim-1) switch (IM_PIXTYPE(im1)) { case TY_SHORT, TY_USHORT : if (imgnls (im1, buffer1, vector1) == EOF || imgnls (im2, buffer2, vector2) == EOF ) break case TY_INT : if (imgnli (im1, buffer1, vector1) == EOF || imgnli (im2, buffer2, vector2) == EOF ) break case TY_LONG : if (imgnll (im1, buffer1, vector1) == EOF || imgnll (im2, buffer2, vector2) == EOF ) break case TY_REAL : if (imgnlr (im1, buffer1, vector1) == EOF || imgnlr (im2, buffer2, vector2) == EOF ) break case TY_DOUBLE : if (imgnld (im1, buffer1, vector1) == EOF || imgnld (im2, buffer2, vector2) == EOF ) break case TY_COMPLEX : if (imgnlx (im1, buffer1, vector1) == EOF || imgnlx (im2, buffer2, vector2) == EOF ) break } # Compare each pixel in the line for bit differences jpix = 0 word1 = (buffer1 - 1) * pixsize / SZ_INT + 1 word2 = (buffer2 - 1) * pixsize / SZ_INT + 1 do iword = 1, nword { # Exclusive or yields 1 where bits are different diff = xor (Memi[word1], Memi[word2]) if ( diff != 0) { # Compute the pixel number and bit offset within the pixel ipix = (iword - 1) * SZ_INT / pixsize + 1 if (pixsize <= SZ_INT) ioffset = 0 else ioffset = mod (iword - 1, pixsize / SZ_INT) * NBITS_INT # Print a title if this is the first pixel that differs # otherwise print the differences in the previous pixel if (ipix != jpix) { if (first) { first = false call printf (errtitle) call pargstr (IM_HDRFILE(im1)) call pargi (IM_CLINDEX(im1)) call pargstr (IM_HDRFILE(im2)) call pargi (IM_CLINDEX(im2)) } else if (jpix != 0) { pixvec[1] = jpix call bitprint (ndim, pixvec, nbit, Memi[bitvec]) } jpix = ipix } do ibit = 1, NBITS_INT { # Move the differences into the bit vector if (bitupk (diff, ibit, 1) == 1) { ndif = ndif + 1 Memi[bitvec+ibit+ioffset-1] = 1 # Stop if the maximum number of diferences # was exceeded if (ndif > maxdif) { pixvec[1] = ipix call bitprint (ndim, pixvec, nbit, Memi[bitvec]) call flush (STDOUT) call error (1, maxerrs) } } # Print bit differences in inter-word pixels if (ibit + ioffset == nbit) { pixvec[1] = ipix call bitprint (ndim, pixvec, nbit, Memi[bitvec]) jpix = 0 ipix = ipix + 1 ioffset = ioffset - nbit } } } word1 = word1 + 1 word2 = word2 + 1 } # Finish printing any changed pixels before looking at the next line if (jpix != 0) { pixvec[1] = jpix call bitprint (ndim, pixvec, nbit, Memi[bitvec]) } call flush (STDOUT) } end