Check if the tags that define the image are correct and consistent.

@param ifd the ifd
@param n the ifd number
@param metadata the ifd metadata
493021
public void checkImage(IFD ifd, int n, IfdTags metadata) {
    CheckCommonFields(ifd, n, metadata);

    if (!metadata.containsTagId(TiffTags.getTagId("PhotometricInterpretation"))) {
      validation.addErrorLoc("Missing Photometric Interpretation", "IFD" + n);
    } else if (metadata.get(TiffTags.getTagId("PhotometricInterpretation")).getValue().size() != 1) {
      validation.addErrorLoc("Invalid Photometric Interpretation", "IFD" + n);
    } else {
      photometric =
          (int) metadata.get(TiffTags.getTagId("PhotometricInterpretation")).getFirstNumericValue();
      switch (photometric) {
        case 0:
        case 1:
          if (!metadata.containsTagId(TiffTags.getTagId("BitsPerSample"))
              || metadata.get(TiffTags.getTagId("BitsPerSample")).getFirstNumericValue() == 1) {
            type = ImageType.BILEVEL;
            CheckBilevelImage(metadata, n);
          } else {
            type = ImageType.GRAYSCALE;
            CheckGrayscaleImage(metadata, n);
          }
          break;
        case 2:
          type = ImageType.RGB;
          CheckRGBImage(metadata, n);
          break;
        case 3:
          type = ImageType.PALETTE;
          CheckPalleteImage(metadata, n);
          break;
        case 4:
          type = ImageType.TRANSPARENCY_MASK;
          CheckTransparencyMask(metadata, n);
          break;
        case 5:
          type = ImageType.CMYK;
          CheckCMYK(metadata, n);
          break;
        case 6:
          type = ImageType.YCbCr;
          CheckYCbCr(metadata, n);
          break;
        case 8:
        case 9:
        case 10:
          type = ImageType.CIELab;
          CheckCIELab(metadata, n);
          break;
        default:
          validation.addWarning("Unknown Photometric Interpretation", "" + photometric, "IFD" + n);
          break;
      }
    }
  }
264930
public static void tryTagImplicit(Node n, boolean taguri) {
      String tid = "";
      switch(n.kind) {
        case Str:
          Data.Str s = (Data.Str)n.data;
          tid = matchImplicit(s.ptr, s.len);
          break;
        case Seq:
          tid = "seq";
          break;
        case Map:
          tid = "map";
          break;
        default:
          break;
      }

      if(taguri) {
        n.type_id = Parser.taguri(YAML.DOMAIN, tid);
      } else {
        n.type_id = tid;
      }
    }
1161559
public static boolean isKnownByteFormat( BufferedImage image ) {
		int type = image.getType();
		return type != BufferedImage.TYPE_BYTE_INDEXED &&
				type != BufferedImage.TYPE_BYTE_BINARY &&
				type != BufferedImage.TYPE_CUSTOM;
	}
782891
private void CheckCMYK(IfdTags metadata, int n) {
    // Samples per pixel
    if (!metadata.containsTagId(TiffTags.getTagId("SamplesPerPixel"))) {
      validation.addErrorLoc("Missing Samples Per Pixel", "IFD" + n);
    }

    // BitsPerSample
    if (!metadata.containsTagId(TiffTags.getTagId("BitsPerSample"))) {
      validation.addErrorLoc("Missing BitsPerSample", "IFD" + n);
    }
  }
985359
@VisibleForTesting
  protected void initMetadata(HttpHeaders headers) throws IOException {
    checkState(
        !metadataInitialized,
        "can not initialize metadata, it already initialized for '%s'", resourceIdString);

    long sizeFromMetadata;
    String range = headers.getContentRange();
    if (range != null) {
      sizeFromMetadata = Long.parseLong(range.substring(range.lastIndexOf('/') + 1));
    } else {
      sizeFromMetadata = headers.getContentLength();
    }

    String generation = headers.getFirstHeaderStringValue("x-goog-generation");

    initMetadata(headers.getContentEncoding(), sizeFromMetadata, generation);
  }
669011
function isImage(node) {
  return (
    node.nodeName === META
    && node.attrs.find(({ name, value }) => {
      value = value.trim();
      return name === 'itemprop' && value === 'image';
    })
  );
}
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);
  }
771136
public boolean removeTag(String tagName) {
    boolean result = false;
    IFD ifd = firstIFD;
    while (ifd != null) {
      if (ifd.containsTagId(TiffTags.getTagId(tagName))) {
        ifd.removeTag(tagName);
      }
      ifd = ifd.getNextIFD();
    }
    createMetadataDictionary();
    return result;
  }
945539
private static ITag injectMetaData(IMetaData<?, ?> meta, ITag tag) {
        IoBuffer bb = IoBuffer.allocate(1000);
        bb.setAutoExpand(true);
        Output out = new Output(bb);
        Serializer.serialize(out, "onMetaData");
        Serializer.serialize(out, meta);
        IoBuffer tmpBody = out.buf().flip();
        int tmpBodySize = out.buf().limit();
        int tmpPreviousTagSize = tag.getPreviousTagSize();
        return new Tag(IoConstants.TYPE_METADATA, 0, tmpBodySize, tmpBody, tmpPreviousTagSize);
    }
446598
public static Specification<JpaDistributionSet> hasTag(final Long tagId) {

        return (targetRoot, query, cb) -> {
            final SetJoin<JpaDistributionSet, JpaDistributionSetTag> tags = targetRoot.join(JpaDistributionSet_.tags,
                    JoinType.LEFT);
            return cb.equal(tags.get(JpaDistributionSetTag_.id), tagId);
        };
    }
954465
public void setIdentifierMetadata(IdentifierMetadata identifierMetadata) {
    if (this.identifierMetadata != null) {
      String format = "Class %s has at least two fields, %s and %s, marked with %s annotation. "
          + "Only one field can be marked as an identifier. ";
      String message = String.format(format, entityClass.getName(),
          this.identifierMetadata.getName(), identifierMetadata.getName(),
          Identifier.class.getName());
      throw new EntityManagerException(message);
    }
    this.identifierMetadata = identifierMetadata;
  }
192860
private void CheckRGBImage(IfdTags metadata, int n) {
    // Samples per Pixel
    long samples = metadata.get(TiffTags.getTagId("SamplesPerPixel")).getFirstNumericValue();
    if (samples < 3)
      validation.addError("Invalid Samples per Pixel", "IFD" + n, samples);

    // Compression
    long comp = metadata.get(TiffTags.getTagId("Compression")).getFirstNumericValue();
    // if (comp != 1 && comp != 32773)
    if (comp < 1)
      validation.addError("Invalid Compression", "IFD" + n, comp);
  }
154050
private void addMetadataFromIFD(IFD ifd, String key, boolean exif) {
    metadata.add(key, ifd);
    for (TagValue tag : ifd.getMetadata().getTags()) {
      if (tag.getCardinality() == 1) {
        abstractTiffType t = tag.getValue().get(0);
        if (t.isIFD()) {
          addMetadataFromIFD((IFD) t, key, true);
        } else if (t.containsMetadata()) {
          try {
            Metadata meta = t.createMetadata();
            metadata.addMetadata(meta);
          } catch (Exception ex) {
            // TODO: What?
          }
        } else {
          if (exif)
            t.setContainer("EXIF");
          metadata.add(tag.getName(), t);
        }
      } else {
        if (exif)
          tag.setContainer("EXIF");
        metadata.add(tag.getName(), tag);
      }
    }
    if (ifd.hasNextIFD()) {
      addMetadataFromIFD(ifd.getNextIFD(), key, false);
    }
  }
724159
public boolean validateMetaDataType(MetaDataType metaDataType, DiagnosticChain diagnostics, Map<Object, Object> context) {
		return validate_EveryDefaultConstraint(metaDataType, diagnostics, context);
	}
721651
private void CheckTransparencyMask(IfdTags metadata, int n) {
    // Samples per pixel
    if (!metadata.containsTagId(TiffTags.getTagId("SamplesPerPixel"))) {
      validation.addErrorLoc("Missing Samples Per Pixel", "IFD" + n);
    } else {
      long spp = metadata.get(TiffTags.getTagId("SamplesPerPixel")).getFirstNumericValue();
      if (spp != 1) {
        validation.addError("Invalid Samples Per Pixel", "IFD" + n, spp);
      }
    }

    // BitsPerSample
    if (!metadata.containsTagId(TiffTags.getTagId("BitsPerSample"))) {
      validation.addErrorLoc("Missing BitsPerSample", "IFD" + n);
    } else {
      long bps = metadata.get(TiffTags.getTagId("BitsPerSample")).getFirstNumericValue();
      if (bps != 1) {
        validation.addError("Invalid BitsPerSample", "IFD" + n, bps);
      }
    }
  }
970538
private void CheckTiles(IFD ifd, IfdTags metadata, int n) {
    long offset;
    int id;

    // Check Tile Offsets
    id = TiffTags.getTagId("TileOffsets");
    offset = metadata.get(id).getFirstNumericValue();
    int no = metadata.get(id).getCardinality();
    if (offset <= 0)
      validation.addError("Invalid value for field " + TiffTags.getTag(id).getName(), "IFD" + n,
          offset);

    // Check Tile Byte Counts
    id = TiffTags.getTagId("TileBYTECounts");
    offset = metadata.get(id).getFirstNumericValue();
    int nc = metadata.get(id).getCardinality();
    if (offset <= 0)
      validation.addError("Invalid value for field " + TiffTags.getTag(id).getName(), "IFD" + n,
          offset);

    if (no != nc) {
      validation.addErrorLoc("Inconsistent tile lengths", "IFD" + n);
    }

    // Check Tile Width
    long tileWidth = 0;
    id = TiffTags.getTagId("TileWidth");
    if (!metadata.containsTagId(id))
      validation.addErrorLoc("Missing required field for tiles " + TiffTags.getTag(id).getName(),
          "IFD" + n);
    else {
      tileWidth = metadata.get(id).getFirstNumericValue();
      if (tileWidth <= 0)
        validation.addError("Invalid value for field " + TiffTags.getTag(id).getName(), "IFD" + n,
            tileWidth);
    }

    // Check Tile Length
    id = TiffTags.getTagId("TileLength");
    long tileLength = 0;
    if (!metadata.containsTagId(id))
      validation.addErrorLoc("Missing required field for tiles " + TiffTags.getTag(id).getName(),
          "IFD" + n);
    else {
      tileLength = metadata.get(id).getFirstNumericValue();
      if (tileLength <= 0)
        validation.addError("Invalid value for field " + TiffTags.getTag(id).getName(), "IFD" + n,
            tileLength);
    }

    long tilesPerImage =
        ((metadata.get(TiffTags.getTagId("ImageWidth")).getFirstNumericValue() + tileWidth - 1) / tileWidth)
            * ((metadata.get(TiffTags.getTagId("ImageLength")).getFirstNumericValue() + tileLength - 1) / tileLength);

    // Check Plannar Configuration
    id = TiffTags.getTagId("PlanarConfiguration");
    int idspp = TiffTags.getTagId("SamplesPerPixel");
    if (metadata.containsTagId(id) && metadata.containsTagId(idspp)) {
      long planar = metadata.get(id).getFirstNumericValue();
      long spp = metadata.get(idspp).getFirstNumericValue();
      if (planar == 2) {
        long spp_tpi = spp * tilesPerImage;
        if (ifd.getImageTiles().getTiles().size() < spp_tpi) {
          validation.addErrorLoc("Insufficient tiles", "IFD" + n);
        }
      }
    }
  }
1019303
public boolean addTag(String tagName, String tagValue) {
    boolean result = false;
    if (firstIFD != null) {
      if (firstIFD.containsTagId(TiffTags.getTagId(tagName))) {
        firstIFD.removeTag(tagName);
      }
      firstIFD.addTag(tagName, tagValue);
      createMetadataDictionary();
    }
    return result;
  }