Validate Screened Data image.

@param ifd the ifd
@param p the profile (default = 0, P2 = 2)
776661
private void validateIfdSD(IFD ifd, int p) {
    IfdTags metadata = ifd.getMetadata();

    if (p == 2) {
      checkRequiredTag(metadata, "NewSubfileType", 1, new long[]{0});
    }
    checkRequiredTag(metadata, "ImageLength", 1);
    checkRequiredTag(metadata, "ImageWidth", 1);
    checkRequiredTag(metadata, "BitsPerSample", 1, new long[]{1});
    checkRequiredTag(metadata, "Compression", 1, new long[]{1,4,8});
    checkRequiredTag(metadata, "PhotometricInterpretation", 1, new long[] {5});
    checkRequiredTag(metadata, "StripOffsets", 1);
    if (p == 0) {
      checkRequiredTag(metadata, "Orientation", 1, new long[]{1,4,5,8});
    } else {
      checkRequiredTag(metadata, "Orientation", 1, new long[]{1});
    }
    if (p == 2) {
      checkRequiredTag(metadata, "SamplesPerPixel", 1, new long[]{1,4});
    }
    checkRequiredTag(metadata, "StripBYTECount", 1);
    checkRequiredTag(metadata, "XResolution", 1);
    checkRequiredTag(metadata, "YResolution", 1);
    checkRequiredTag(metadata, "PlanarConfiguration", 1, new long[]{2});
    if (p == 2) {
      checkRequiredTag(metadata, "ResolutionUnit", 1, new long[]{2, 3});
      checkRequiredTag(metadata, "NumberOfInks", 1, new long[]{4});
    }
    checkRequiredTag(metadata, "InkSet", 1, new long[]{1});
    checkRequiredTag(metadata, "BackgroundColorIndicator", 1, new long[]{0, 1, 2});
  }
97110
public ValidationResult validate(String pid) {
        if (pid == null) {
            throw new NullPointerException("pid may not be null.");
        }

        ObjectInfo object = null;

        try {
            object = objectSource.getValidationObject(pid);
        } catch (ObjectSourceException e) {
            // This falls into the case of object==null.
        }

        if (object == null) {
            ValidationResult result =
                    new ValidationResult(new BasicObjectInfo(pid));
            result.addNote(ValidationResultNotation.objectNotFound(pid));
            return result;
        } else {
            return validate(object);
        }
    }
1172993
function canBeTiled ( profile ) {
        var level0Profiles = [
            "http://library.stanford.edu/iiif/image-api/compliance.html#level0",
            "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",
            "http://iiif.io/api/image/2/level0.json"
        ];
        var isLevel0 = (level0Profiles.indexOf(profile[0]) !== -1);
        var hasSizeByW = false;
        if ( profile.length > 1 && profile[1].supports ) {
            hasSizeByW = profile[1].supports.indexOf( "sizeByW" ) !== -1;
        }
        return !isLevel0 || hasSizeByW;
    }
644632
def p_if_header(p):
    
    global ENABLED

    IFDEFS.append((ENABLED, p.lineno(2)))
    ENABLED = ID_TABLE.defined(p[2])
1180077
public void validateMetadata(IfdTags metadata) {
    int prevTagId = 0;
    try {
      TiffTags.getTiffTags();
    } catch (ReadTagsIOException e) {
    }
    for (TagValue ie : metadata.getTags()) {
      if (!TiffTags.tagMap.containsKey(ie.getId())) {
        validation.addWarning("Ignoring undefined tag id " + ie.getId(), "", "Metadata");
      } else if (!TiffTags.tagTypes.containsKey(ie.getType())) {
        validation.addWarning("Ignoring unknown tag type " + ie.getType(), "", "Metadata");
      }
      else {
        Tag t = TiffTags.getTag(ie.getId());
        String stype = TiffTags.tagTypes.get(ie.getType());
        if (ie.getId() == 320) {
          // Colormap length check
          long bps = 0;
          if (metadata.containsTagId(258))
            bps = metadata.get(258).getFirstNumericValue();
          long calc = 3 * (long) Math.pow(2, bps);
          if (calc != ie.getCardinality()) {
            validation.addError("Invalid cardinality for tag "
                + TiffTags.getTag(ie.getId()).getName() + "[" + ie.getCardinality() + "]",
                "Metadata", stype);
          }
        }
        try {
          // Cardinality check
          int card = Integer.parseInt(t.getCardinality());
          if (card != ie.getCardinality())
            validation.addError("Cardinality for tag " + TiffTags.getTag(ie.getId()).getName()
                + " must be " + card, "Metadata",
                ie.getCardinality());
        } catch (Exception e) {
          // TODO: Deal with formulas?
        }
      }

      if (ie.getId() < prevTagId) {
        if (tagOrderTolerance > 0)
          validation.addWarning("Tags are not in ascending order", "", "Metadata");
        else
          validation.addErrorLoc("Tags are not in ascending order", "Metadata");
      }
      prevTagId = ie.getId();
    }
  }
1261250
@Override
	protected void validateParameters() {
		super.validateParameters();
		// override some arguments
		parameters.put(OPT_NOPREVIEW, "");
		parameters.put(OPT_RAW, "-");// must be this, then image will be in console!
		parameters.put(OPT_RAW_FORMAT, "rgb");// only support rgb
		parameters.put(OPT_CAMSELECT, Integer.toString(this.camSelect));
		parameters.put(OPT_OUTPUT, "/dev/null");
	}
1245271
public boolean isValidProfileSize(String profileSize) {
        if (StringUtils.isBlank(profileSize) || profileSizes.isEmpty()) {
            return false;
        }
        return profileSizes.contains(profileSize);
    }
1355608
private static boolean isDpiSet(final Multimap<String, String> extraParams) {
        String searchKey = "FORMAT_OPTIONS";
        for (String key: extraParams.keys()) {
            if (key.equalsIgnoreCase(searchKey)) {
                for (String value: extraParams.get(key)) {
                    if (value.toLowerCase().contains("dpi:")) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
150837
public void writeIFD(IFD ifd) throws IOException {
    ArrayList<TagValue> oversizedTags = new ArrayList<TagValue>();
    ArrayList<TagValue> undersizedTags = new ArrayList<TagValue>();
    int ntags = classifyTags(ifd, oversizedTags, undersizedTags);

    HashMap<Integer, Integer> pointers = new HashMap<Integer, Integer>();

    // Write IFD entries
    data.putShort((short) ntags);
    ArrayList<TagValue> ltags = ifd.getTags().getTags();
    Collections.sort(ltags, new Comparator<TagValue>() {
      @Override
      public int compare(TagValue a1, TagValue a2) {
        return a1.getId()-a2.getId();
      }
    });
    for (TagValue tv : ltags) {
      int n = tv.getCardinality();
      int id = tv.getId();
      int tagtype = tv.getType();
      data.putShort((short) id);
      data.putShort((short) tagtype);
      if (id == 700) {
        if (tv.getValue().size() > 0)
          n = ((XMP) tv.getValue().get(0)).getLength();
      }
      if (id == 34675)
        n = tv.getReadlength();
      if (id == 33723) {
        if (tv.getValue().size() > 0) {
          abstractTiffType att = tv.getValue().get(0);
          if (att instanceof IPTC) {
            IPTC iptc = (IPTC) att;
            n = (iptc).getLength();
            //n = iptc.getOriginal().size();
          } else n = tv.getCardinality();
        }
      }
      data.putInt(n);

      pointers.put(id, (int) data.position());
      int startpos = (int) data.position();
      if (oversizedTags.contains(tv)) {
        data.putInt(1); // Any number, later we will update the pointer
      } else {
        writeTagValue(tv);
        while ((int) data.position() - startpos < 4)
          data.put((byte) 0);
      }
    }

    long positionNextIfdOffset = data.position();
    data.putInt(0); // No next IFD (later we will update this value if there is a next IFD)

    // Update pointers and write tag values
    for (TagValue tv : oversizedTags) {
        // Update pointer of the tag entry
        int currentPosition = (int) data.position();
        if (currentPosition % 2 != 0)
          currentPosition++; // Word alignment check
        data.seek(pointers.get(tv.getId()));
        data.putInt(currentPosition);
        data.seek(currentPosition);

        writeTagValue(tv);
    }

    if (ifd.hasStrips()) {
      long stripOffsetsPointer = data.position();
      if (stripOffsetsPointer % 2 != 0) {
        // Correct word alignment
        data.put((byte) 0);
        stripOffsetsPointer = (int) data.position();
      }

      // Write strips and return its offsets
      ArrayList<Integer> offsets = writeStripData(ifd);

      if (offsets.size() > 1) {
        // Write offsets
        stripOffsetsPointer = data.position();
        for (int off : offsets) {
          data.putInt(off);
        }
      }

      // Update pointer of the strip offets
      int currentPosition = (int) data.position();
      data.seek(pointers.get(273));
      data.putInt((int) stripOffsetsPointer);
      data.seek(currentPosition);
    } else if (ifd.hasTiles()) {
      long tilesOffsetsPointer = data.position();
      if (tilesOffsetsPointer % 2 != 0) {
        // Correct word alignment
        data.put((byte) 0);
        tilesOffsetsPointer = (int) data.position();
      }
      ArrayList<Integer> offsets = writeTileData(ifd);

      if (offsets.size() > 1) {
        // Write offsets
        tilesOffsetsPointer = data.position();
        for (int off : offsets) {
          data.putInt(off);
        }
      }

      // Update pointer of the tag entry
      int currentPosition = (int) data.position();
      data.seek(pointers.get(324));
      data.putInt((int) tilesOffsetsPointer);
      data.seek(currentPosition);
    }

    if (ifd.hasNextIFD()) {
      // Update pointer of the next IFD offset
      int currentPosition = (int) data.position();
      if (currentPosition % 2 != 0)
        currentPosition++; // Word alignment check
      data.seek((int)positionNextIfdOffset);
      data.putInt(currentPosition);
      data.seek(currentPosition);
    }
  }
1305555
protected void validateEqualInteger(Integer i1, Integer i2, String errorKey, String errorMessage) {
		if (i1 == null || i2 == null || (i1.intValue() != i2.intValue())) {
			addError(errorKey, errorMessage);
		}
	}
17517
@SuppressWarnings("unused")
  @Deprecated
  private void validateSubIfd(IFD ifd, int n) {
    boolean thumbnail = ifd.getParent().getImageSize() > ifd.getImageSize();
    IfdTags metadata = ifd.getMetadata();

    checkRequiredTag(metadata, "ImageLength", 1, "SubIFD" + n);
    checkRequiredTag(metadata, "ImageWidth", 1, "SubIFD" + n);
    int spp = -1;
    if (checkRequiredTag(metadata, "SamplesPerPixel", 1, "SubIFD" + n)) {
      spp = (int) metadata.get("SamplesPerPixel").getFirstNumericValue();
      checkRequiredTag(metadata, "BitsPerSample", spp, "SubIFD" + n);
    }
    if (checkRequiredTag(metadata, "Compression", 1, "SubIFD" + n)) {
      int comp = (int) metadata.get("Compression").getFirstNumericValue();
      if (comp == 1)
        checkForbiddenTag(metadata, "CompressedBitsPerPixel", "IFD" + n);
    }
    checkRequiredTag(metadata, "XResolution", 1, "SubIFD" + n);
    checkRequiredTag(metadata, "YResolution", 1, "SubIFD" + n);
    checkForbiddenTag(metadata, "SubIFDs", "IFD" + n);
    if (thumbnail)
      checkRequiredTag(metadata, "NewSubfileType", 1, new long[] {1}, "SubIFD" + n);
    else
      checkRequiredTag(metadata, "NewSubfileType", 1, new long[] {0}, "SubIFD" + n);
    if (checkRequiredTag(metadata, "PhotometricInterpretation", 1, new long[] {1, 2, 6, 32803,
        32767}, "SubIFD" + n)) {
      int photo = (int) metadata.get("PhotometricInterpretation").getFirstNumericValue();
      if (photo != 6) {
        checkForbiddenTag(metadata, "YCbCrCoefficients", "SubIFD" + n);
        checkForbiddenTag(metadata, "YCbCrSubSampling", "SubIFD" + n);
        checkForbiddenTag(metadata, "YCbCrPositioning", "SubIFD" + n);
        checkForbiddenTag(metadata, "ReferenceBlackWhite", "SubIFD" + n);
      }
      if (photo == 2 || photo == 3) {
        if (spp != 3) {
          validation.addError("Invalid SampesPerPixel value fo TiffEP", "SubIFD" + n, spp);
        }
      } else if (photo == 1 || photo == 32803) {
        if (spp != 1) {
          validation.addError("Invalid SampesPerPixel value fo TiffEP", "SubIFD" + n, spp);
        }
        if (photo == 32803) {
          checkRequiredTag(metadata, "CFARepeatPatternDim", 2, "SubIFD" + n);
          checkRequiredTag(metadata, "CFAPattern", -1, "SubIFD" + n);
        }
      }
    }
    checkRequiredTag(metadata, "PlanarConfiguration", 1, new long[] {1, 2}, "SubIFD" + n);
    checkRequiredTag(metadata, "ResolutionUnit", 1, new long[] {1, 2, 3}, "SubIFD" + n);

    if (!thumbnail) {
      if (ifd.hasStrips()) {
        checkRequiredTag(metadata, "StripBYTECount", -1, "SubIFD" + n);
        checkRequiredTag(metadata, "StripOffsets", -1, "SubIFD" + n);
        checkRequiredTag(metadata, "RowsPerStrip", 1, "SubIFD" + n);
        if (ifd.hasTiles()) {
          validation.addErrorLoc("Image in both strips and tiles", "SubIFD");
        }
      } else if (ifd.hasTiles()) {
        checkRequiredTag(metadata, "TileLength", 1, "SubIFD" + n);
        checkRequiredTag(metadata, "TileOffsets", 1, "SubIFD" + n);
        checkRequiredTag(metadata, "TileWidth", -1, "SubIFD" + n);
      }
    } else {
      checkRequiredTag(metadata, "StripBYTECount", -1, "SubIFD" + n);
      checkRequiredTag(metadata, "StripOffsets", -1, "SubIFD" + n);
      checkRequiredTag(metadata, "RowsPerStrip", 1, "SubIFD" + n);
      checkForbiddenTag(metadata, "TileLength", "SubIFD" + n);
      checkForbiddenTag(metadata, "TileOffsets", "SubIFD" + n);
      checkForbiddenTag(metadata, "TileWidth", "SubIFD" + n);
    }

    int nycbcr = 0;
    if (metadata.containsTagId(TiffTags.getTagId("YCbCrCoefficients")))
      nycbcr++;
    if (metadata.containsTagId(TiffTags.getTagId("YCbCrSubSampling")))
      nycbcr++;
    if (metadata.containsTagId(TiffTags.getTagId("YCbCrPositioning")))
      nycbcr++;
    if (metadata.containsTagId(TiffTags.getTagId("ReferenceBlackWhite")))
      nycbcr++;
    if (nycbcr > 0 && nycbcr != 4) {
      checkRequiredTag(metadata, "YCbCrCoefficients", 3, "SubIFD" + n);
      checkRequiredTag(metadata, "YCbCrSubSampling", 2, "SubIFD" + n);
      checkRequiredTag(metadata, "YCbCrPositioning", 1, "SubIFD" + n);
      checkRequiredTag(metadata, "ReferenceBlackWhite", 6, "SubIFD" + n);
    }
    if (thumbnail) {
      checkForbiddenTag(metadata, "YCbCrCoefficients", "IFD" + n);
      checkForbiddenTag(metadata, "YCbCrSubSampling", "IFD" + n);
      checkForbiddenTag(metadata, "YCbCrPositioning", "IFD" + n);
      checkForbiddenTag(metadata, "ReferenceBlackWhite", "IFD" + n);
    }

    checkForbiddenTag(metadata, "PrimaryChromaticities", "IFD" + n);
    checkForbiddenTag(metadata, "WhitePoint", "IFD" + n);
    checkForbiddenTag(metadata, "TransferFunction", "IFD" + n);
  }
361079
private static Boolean checkMethod(NetworkInterface iface, Method toCheck) {
        if (toCheck != null) {
            try {
                return (Boolean) toCheck.invoke(iface, (Object[]) null);
            } catch (IllegalAccessException e) {
                return false;
            } catch (InvocationTargetException e) {
                return false;
            }
        }
        // Cannot check, hence we assume that is true
        return true;
    }
1196041
@Override
  public void validate() {
    int n = 0;
    try {
      for (TiffObject o : model.getImageIfds()) {
        IFD ifd = (IFD) o;
        IfdTags metadata = ifd.getMetadata();
        validateMetadata(metadata);
        checkImage(ifd, n, metadata);
        n++;
      }
    } catch (Exception ex) {

    }
  }
121588
@Override
	public Void visitInt(int i, String p) {
		//System.out.printf(">> %s intValue: %d\n", p, i);

		if (inTasks && AnnotationAttributeType.VERSION.getValue().equals(p)) {
			// add value
			currentValue = (currentValue == null) ? new Pair<Integer, String>() : currentValue;			
			currentValue.value0=i;
			
			if (currentValue.value0!=null && StringUtils.hasText(currentValue.value1)) {
				tasks.add(currentValue);
				currentValue=null;
			}
		}

		return null;
	}
40615
private static boolean checkParameters(Method method, Object... data)
	{
		Parameter[] parameters = method.getParameters();
		if (ArrayUtils.isEmpty(data) && parameters.length != 0)
			return false;
		if (parameters.length != data.length)
			return false;

		for (int i = 0; i < parameters.length; i++)
		{
			Class<?> paramClass = parameters[i].getType();
			if (data[i] != null)
			{
				Class<?> dataClass = data[i].getClass();
				if (!ClassUtils.isAssignable(dataClass, paramClass, true))
					return false;
			}
		}

		return true;
	}
1050198
private void CheckPalleteImage(IfdTags metadata, int nifd) {
    // Color Map
    if (!metadata.containsTagId(TiffTags.getTagId("ColorMap"))) {
      validation.addErrorLoc("Missing Color Map", "IFD" + nifd);
    } else {
      int n = metadata.get(TiffTags.getTagId("ColorMap")).getCardinality();
      if (n != 3 * (int) Math.pow(2, metadata.get(TiffTags.getTagId("BitsPerSample"))
          .getFirstNumericValue()))
        validation.addError("Incorrect Color Map Cardinality", "IFD" + nifd, metadata.get(320)
            .getCardinality());
    }

    // Bits per Sample
    long bps = metadata.get(TiffTags.getTagId("BitsPerSample")).getFirstNumericValue();
    if (bps != 4 && bps != 8)
      validation.addError("Invalid Bits per Sample", "IFD" + nifd, bps);

    // Compression
    long comp = metadata.get(TiffTags.getTagId("Compression")).getFirstNumericValue();
    // if (comp != 1 && comp != 32773)
    if (comp < 1)
      validation.addError("Invalid Compression", "IFD" + nifd, comp);
  }
205586
public void validateImageType(BufferedImage image) {
		if (image == null) {
			throw new GeoPackageException("The image is null");
		}
		if (image.getColorModel().getTransferType() != DataBuffer.TYPE_USHORT) {
			throw new GeoPackageException(
					"The coverage data tile is expected to be a 16 bit unsigned short, actual: "
							+ image.getColorModel().getTransferType());
		}
	}