Check RGB Image.

@param metadata the metadata
@param n the IFD number
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);
  }
63173
public void setMetadata(com.google.api.ads.admanager.axis.v201805.VideoMetadata metadata) {
        this.metadata = metadata;
    }
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) {

    }
  }
686634
def setPixelColorRGB(self, n, red, green, blue):
        
        self.setPixelColor(n, Color(red, green, blue))
1307682
private void CheckStrips(IfdTags metadata, int n) {
    long offset;
    int id;

    // Strip offsets
    id = TiffTags.getTagId("StripOffsets");
    offset = metadata.get(id).getFirstNumericValue();
    int nso = metadata.get(id).getCardinality();
    if (offset <= 0)
      validation.addError("Invalid value for field " + TiffTags.getTag(id).getName(), "IFD" + n,
          offset);

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

    if (nso != nsc) {
      validation.addErrorLoc("Inconsistent strip lengths", "IFD" + n);
    }

    int pixelSize = 0;
    for (int i = 0; i < metadata.get("BitsPerSample").getCardinality(); i++) {
      pixelSize += metadata.get("BitsPerSample").getValue().get(i).toInt();
    }
    if (metadata.get("Compression").getFirstNumericValue() == 1
 && pixelSize >= 8) {
      int calculatedImageLength = 0;
      for (int i = 0; i < nsc; i++) {
        calculatedImageLength += metadata.get(id).getValue().get(i).toInt();
      }
      if (calculatedImageLength != metadata.get("ImageLength").getFirstNumericValue()
          * metadata.get("ImageWidth").getFirstNumericValue() * pixelSize / 8) {
        // validation.toString();
        validation.addErrorLoc("Calculated and declared image size do not match", "IFD" + n);
      }
    }

    // Rows per Strip
    id = TiffTags.getTagId("RowsPerStrip");
    if (!metadata.containsTagId(id)) {
      if (rowsPerStripTolerance > 0)
        validation.addWarning("Missing required field", TiffTags.getTag(id).getName(), "IFD" + n);
      else
        validation.addError("Missing required field", "IFD" + n, TiffTags.getTag(id).getName());
    } else {
      offset = metadata.get(id).getFirstNumericValue();
      if (offset <= 0)
        validation.addError("Invalid value for field " + TiffTags.getTag(id).getName(), "IFD" + n,
            offset);
    }
  }
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});
  }
3974
private void generateThumbails(final Metadata m, final Element e) {
        for (final Thumbnail thumb : m.getThumbnail()) {
            final Element t = new Element("thumbnail", NS);
            addNotNullAttribute(t, "url", thumb.getUrl());
            addNotNullAttribute(t, "width", thumb.getWidth());
            addNotNullAttribute(t, "height", thumb.getHeight());
            addNotNullAttribute(t, "time", thumb.getTime());
            e.addContent(t);
        }
    }
434960
def _pngmeta(self):
        
        reserved = ('interlace', 'gamma', 'dpi', 'transparency', 'aspect')

        try:
            tags = self.tags
        except AttributeError:
            tags = {}

        # Undocumented class
        from PIL import PngImagePlugin
        meta = PngImagePlugin.PngInfo()

        # Copy from tags to new dict
        for k__, v__ in tags.items():
            if k__ not in reserved:
                meta.add_text(k__, v__, 0)

        return meta
773597
private IIOMetadataNode createNewExifNode( IIOMetadata tiffMetadata, IIOMetadata thumbMeta, BufferedImage thumbnail ) {

        IIOMetadataNode app1Node = null;
        ImageWriter tiffWriter = null;
        try {
            Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("tiff");
            while( writers.hasNext() ) {
                tiffWriter = writers.next();
                if (tiffWriter.getClass().getName().startsWith("com.sun.media")) {
                    // Break on finding the core provider.
                    break;
                }
            }
            if (tiffWriter == null) {
                System.out.println("Cannot find core TIFF writer!");
                System.exit(0);
            }

            ImageWriteParam writeParam = tiffWriter.getDefaultWriteParam();
            writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            writeParam.setCompressionType("EXIF JPEG");

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            MemoryCacheImageOutputStream app1EXIFOutput = new MemoryCacheImageOutputStream(baos);
            tiffWriter.setOutput(app1EXIFOutput);

            // escribir
            tiffWriter.prepareWriteEmpty(jpegReader.getStreamMetadata(), new ImageTypeSpecifier(image), image.getWidth(),
                    image.getHeight(), tiffMetadata, null, writeParam);

            tiffWriter.endWriteEmpty();

            // Flush data into byte stream.
            app1EXIFOutput.flush();

            // Create APP1 parameter array.
            byte[] app1Parameters = new byte[6 + baos.size()];

            // Add EXIF APP1 ID bytes.
            app1Parameters[0] = (byte) 'E';
            app1Parameters[1] = (byte) 'x';
            app1Parameters[2] = (byte) 'i';
            app1Parameters[3] = (byte) 'f';
            app1Parameters[4] = app1Parameters[5] = (byte) 0;

            // Append TIFF stream to APP1 parameters.
            System.arraycopy(baos.toByteArray(), 0, app1Parameters, 6, baos.size());

            // Create the APP1 EXIF node to be added to native JPEG image metadata.
            app1Node = new IIOMetadataNode("unknown");
            app1Node.setAttribute("MarkerTag", (new Integer(0xE1)).toString());
            app1Node.setUserObject(app1Parameters);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (tiffWriter != null)
                tiffWriter.dispose();
        }

        return app1Node;

    }
1320999
public void forEach(final MetaData metaData)
    {
        int counterId = 0;

        final AtomicBuffer metaDataBuffer = this.metaDataBuffer;

        for (int i = 0, capacity = metaDataBuffer.capacity(); i < capacity; i += METADATA_LENGTH)
        {
            final int recordStatus = metaDataBuffer.getIntVolatile(i);
            if (RECORD_ALLOCATED == recordStatus)
            {
                final int typeId = metaDataBuffer.getInt(i + TYPE_ID_OFFSET);
                final String label = labelValue(metaDataBuffer, i);
                final DirectBuffer keyBuffer = new UnsafeBuffer(metaDataBuffer, i + KEY_OFFSET, MAX_KEY_LENGTH);

                metaData.accept(counterId, typeId, keyBuffer, label);
            }
            else if (RECORD_UNUSED == recordStatus)
            {
                break;
            }

            counterId++;
        }
    }
384084
private void CheckYCbCr(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 != 3) {
        validation.addError("Invalid Samples Per Pixel", "IFD" + n, spp);
      }
    }

    // BitsPerSample
    if (!metadata.containsTagId(TiffTags.getTagId("BitsPerSample"))) {
      validation.addErrorLoc("Missing BitsPerSample", "IFD" + n);
    } else {
      for (abstractTiffType vi : metadata.get(TiffTags.getTagId("BitsPerSample")).getValue()) {
        if (vi.toInt() != 8) {
          validation.addError("Invalid BitsPerSample", "IFD" + n, vi.toInt());
          break;
        }
      }
    }

    // Compression
    // long comp = metadata.get(TiffTags.getTagId("Compression")).getFirstNumericValue();
    // if (comp != 1 && comp != 5 && comp != 6)
    // validation.addError("Invalid Compression", comp);

    // if (!metadata.containsTagId(TiffTags.getTagId("ReferenceBlackWhite")))
    // validation.addError("Missing ReferenceBlackWhite");

    // if (!metadata.containsTagId(TiffTags.getTagId("YCbCrCoefficients")))
    // validation.addError("Missing YCbCr Coefficients");

    // if (!metadata.containsTagId(TiffTags.getTagId("YCbCrSubSampling")))
    // validation.addError("Missing YCbCr SubSampling");

    // if (!metadata.containsTagId(TiffTags.getTagId("YCbCrPositioning")))
    // validation.addError("Missing YCbCr Positioning");
  }
474481
private void checkMetadata() {
    if (!localMember.properties().equals(localProperties)) {
      localProperties = new Properties();
      localProperties.putAll(localMember.properties());
      post(new GroupMembershipEvent(GroupMembershipEvent.Type.METADATA_CHANGED, localMember));
    }
  }
240652
private IfdReader readIFD(int offset, boolean isImage, int n) {
    IFD ifd = new IFD(isImage);
    ifd.setOffset(offset);
    IfdReader ir = new IfdReader();
    ir.setIfd(ifd);
    int nextIfdOffset = 0;
    try {
      if (offset % 2 != 0) {
        validation.addErrorLoc("Bad word alignment in the offset of the IFD", "IFD" + n);
      }
      int index = offset;
      int directoryEntries = data.readShort(offset).toInt();
      if (directoryEntries < 1) {
        validation.addError("Incorrect number of IFD entries", "IFD" + n,
            directoryEntries);
        validation.setFatalError(true, "Incorrect number of IFD entries");
      } else if (directoryEntries > 500) {
        if (n < 0) {
          validation.addError("Incorrect number of IFD entries", "SubIFD" + (-n), directoryEntries);
          validation.setFatalError(true, "Incorrect number of IFD entries");
        } else {
          validation.addError("Incorrect number of IFD entries", "IFD" + n, directoryEntries);
          validation.setFatalError(true, "Incorrect number of IFD entries");
        }
      } else {
        index += 2;

        // Reads the tags
        for (int i = 0; i < directoryEntries; i++) {
          int tagid = 0;
          int tagType = -1;
          int tagN = -1;
          try {
            tagid = data.readShort(index).toInt();
            tagType = data.readShort(index + 2).toInt();
            tagN = data.readLong(index + 4).toInt();
            boolean ok = checkType(tagid, tagType, n);
            if (!ok && tagN > 1000) tagN = 1000;
            TagValue tv = getValue(tagType, tagN, tagid, index + 8, ifd, n);
            if (ifd.containsTagId(tagid)) {
              if (duplicateTagTolerance > 0)
                validation.addWarning("Duplicate tag", "" + tagid, "IFD" + n);
              else
                validation.addError("Duplicate tag", "IFD" + n, tagid);
            }
            ifd.addTag(tv);
          } catch (Exception ex) {
            validation.addErrorLoc("Parse error in tag #" + i + " (" + tagid + ")", "IFD" + n);
            TagValue tv = new TagValue(tagid, tagType);
            tv.setReadOffset(index + 8);
            tv.setReadLength(tagN);
            ifd.addTag(tv);
          }

          index += 12;
        }

        // Reads the position of the next IFD
        nextIfdOffset = 0;
        try {
          nextIfdOffset = data.readLong(index).toInt();
        } catch (Exception ex) {
          nextIfdOffset = 0;
          if (nextIFDTolerance > 0)
            validation.addWarning("Unreadable next IFD offset", "", "IFD" + n);
          else
            validation.addErrorLoc("Unreadable next IFD offset", "IFD" + n);
        }
        if (nextIfdOffset > 0 && nextIfdOffset < 7) {
          validation.addError("Invalid next IFD offset", "IFD" + n, nextIfdOffset);
          nextIfdOffset = 0;
        }
        ir.setNextIfdOffset(nextIfdOffset);

        ir.readImage();
        if (isImage && !ifd.hasStrips() && !ifd.hasTiles()) {
          validation.setFatalError(true, "Incorrect image");
        }
      }
    } catch (Exception ex) {
      validation.addErrorLoc("IO Exception", "IFD" + n);
      return null;
    }
    return ir;
  }
708679
private void writeChunkMetaData(final BAMIndexMetaData metaData) {
      codec.writeInt(GenomicIndexUtil.MAX_BINS);
      final int nChunk = 2;
      codec.writeInt(nChunk);
      codec.writeLong(metaData.getFirstOffset());
      codec.writeLong(metaData.getLastOffset());
      codec.writeLong(metaData.getAlignedRecordCount());
      codec.writeLong(metaData.getUnalignedRecordCount());

  }
1214172
public boolean metadataEquals(Map<String, byte[]> otherMetadata) {
    if (metadata == otherMetadata) {
      // Fast-path for common cases where the same actual default metadata instance may be used in
      // multiple different item infos.
      return true;
    }
    // No need to check if other `metadata` is not null,
    // because previous `if` checks if both of them are null.
    if (metadata == null || otherMetadata == null) {
      return false;
    }
    if (!metadata.keySet().equals(otherMetadata.keySet())) {
      return false;
    }

    // Compare each byte[] with Arrays.equals.
    for (Map.Entry<String, byte[]> metadataEntry : metadata.entrySet()) {
      if (!Arrays.equals(metadataEntry.getValue(), otherMetadata.get(metadataEntry.getKey()))) {
        return false;
      }
    }
    return true;
  }
138445
public static void checkReshape(ImageBase<?> imgA, ImageBase<?> imgB) {
		if( imgA == imgB )
			throw new IllegalArgumentException("Image's can't be the same instance");
		imgB.reshape(imgA.width,imgA.height);
	}
712717
public void setImaginary(T value, int m, int n)
    {
        setImaginary( value, getIndex(m,n) );
    }