Get the coverage data value for the "unsigned short" pixel value

@param griddedTile
gridded tile
@param pixelValue
pixel value as an unsigned short
@return coverage data value
170028
public Double getValue(GriddedTile griddedTile, short pixelValue) {
		int unsignedPixelValue = getUnsignedPixelValue(pixelValue);
		Double value = getValue(griddedTile, unsignedPixelValue);
		return value;
	}
831571
public static double[] tileBounds3857( int tx, int ty, int zoom, int tileSize ) {
        double[] min = pixelsToMeters(tx * tileSize, ty * tileSize, zoom, tileSize);
        double minx = min[0], miny = min[1];
        double[] max = pixelsToMeters((tx + 1) * tileSize, (ty + 1) * tileSize, zoom, tileSize);
        double maxx = max[0], maxy = max[1];
        return new double[]{minx, miny, maxx, maxy};
    }
791725
@Override
    public double getValue(double quantile) {
        if (quantile < 0.0 || quantile > 1.0 || Double.isNaN( quantile )) {
            throw new IllegalArgumentException(quantile + " is not in [0..1]");
        }

        if (values.length == 0) {
            return 0.0;
        }

        int posx = Arrays.binarySearch(quantiles, quantile);
        if (posx < 0)
            posx = ((-posx) - 1) - 1;

        if (posx < 1) {
            return values[0];
        }

        if (posx >= values.length) {
            return values[values.length - 1];
        }

        return values[posx];
    }
369965
public short[] getPixelValues(BufferedImage image) {
		validateImageType(image);
		WritableRaster raster = image.getRaster();
		short[] pixelValues = getPixelValues(raster);
		return pixelValues;
	}
82608
private Double[][] getValuesUnbounded(TileMatrix tileMatrix,
			TileResultSet tileResults, CoverageDataRequest request) {

		// Build a map of rows to maps of columns and values
		Map<Long, Map<Long, Double[][]>> rowsMap = new TreeMap<>();

		// Track the min and max row and column
		Long minRow = null;
		Long maxRow = null;
		Long minColumn = null;
		Long maxColumn = null;

		// Track count of tiles involved in the results
		int tileCount = 0;

		// Process each coverage data tile row
		while (tileResults.moveToNext()) {

			// Get the next coverage data tile
			TileRow tileRow = tileResults.getRow();

			// Get the bounding box of the coverage data
			BoundingBox tileBoundingBox = TileBoundingBoxUtils.getBoundingBox(
					coverageBoundingBox, tileMatrix, tileRow.getTileColumn(),
					tileRow.getTileRow());

			// Get the bounding box where the request and coverage data tile
			// overlap
			BoundingBox overlap = request.overlap(tileBoundingBox);

			// If the coverage data tile overlaps with the requested box
			if (overlap != null) {

				// Get the rectangle of the tile coverage data with matching
				// values
				ImageRectangle src = TileBoundingBoxJavaUtils.getRectangle(
						tileMatrix.getTileWidth(), tileMatrix.getTileHeight(),
						tileBoundingBox, overlap);

				if (src.isValidAllowEmpty()) {

					// Get the source dimensions
					int srcTop = Math.min(src.getTop(),
							(int) tileMatrix.getTileHeight() - 1);
					int srcBottom = Math.min(src.getBottom(),
							(int) tileMatrix.getTileHeight() - 1);
					int srcLeft = Math.min(src.getLeft(),
							(int) tileMatrix.getTileWidth() - 1);
					int srcRight = Math.min(src.getRight(),
							(int) tileMatrix.getTileWidth() - 1);

					// Get the gridded tile value for the tile
					GriddedTile griddedTile = getGriddedTile(tileRow.getId());

					// Get the coverage data tile image
					TImage image = createImage(tileRow);

					// Create the coverage data results for this tile
					Double[][] values = new Double[srcBottom - srcTop + 1][srcRight
							- srcLeft + 1];

					// Get or add the columns map to the rows map
					Map<Long, Double[][]> columnsMap = rowsMap.get(tileRow
							.getTileRow());
					if (columnsMap == null) {
						columnsMap = new TreeMap<Long, Double[][]>();
						rowsMap.put(tileRow.getTileRow(), columnsMap);
					}

					// Read and set the coverage data values
					for (int y = srcTop; y <= srcBottom; y++) {

						for (int x = srcLeft; x <= srcRight; x++) {

							// Get the coverage data value from the source pixel
							Double value = getValue(griddedTile, image, x, y);

							values[y - srcTop][x - srcLeft] = value;
						}
					}

					// Set the coverage data in the results map
					columnsMap.put(tileRow.getTileColumn(), values);

					// Increase the contributing tiles count
					tileCount++;

					// Track the min and max row and column
					minRow = minRow == null ? tileRow.getTileRow() : Math.min(
							minRow, tileRow.getTileRow());
					maxRow = maxRow == null ? tileRow.getTileRow() : Math.max(
							maxRow, tileRow.getTileRow());
					minColumn = minColumn == null ? tileRow.getTileColumn()
							: Math.min(minColumn, tileRow.getTileColumn());
					maxColumn = maxColumn == null ? tileRow.getTileColumn()
							: Math.max(maxColumn, tileRow.getTileColumn());
				}
			}
		}

		// Handle formatting the results
		Double[][] values = formatUnboundedResults(tileMatrix, rowsMap,
				tileCount, minRow, maxRow, minColumn, maxColumn);

		return values;
	}
494679
@Override
    public Tile getTile(int x, int y, int zoom)
    {
        return getTile(x, y, zoom, true);
    }
879943
public BufferedImage drawTile(int[][] unsignedPixelValues) {

		int tileWidth = unsignedPixelValues[0].length;
		int tileHeight = unsignedPixelValues.length;

		BufferedImage image = createImage(tileWidth, tileHeight);
		WritableRaster raster = image.getRaster();
		for (int x = 0; x < tileWidth; x++) {
			for (int y = 0; y < tileHeight; y++) {
				int unsignedPixelValue = unsignedPixelValues[y][x];
				setPixelValue(raster, x, y, unsignedPixelValue);
			}
		}

		return image;
	}
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);
        }
      }
    }
  }
749481
public int[] gridAt( double x, double y ) {
        if (isInRaster(x, y)) {
            GridGeometry2D gridGeometry = getGridGeometry();
            int[] colRowFromCoordinate = CoverageUtilities.colRowFromCoordinate(new Coordinate(x, y), gridGeometry, null);
            return colRowFromCoordinate;
        }
        return null;
    }
281830
public String getTile(int x, int y) {
        if ((x > getArrayWidth()) || (y > getArrayHeight()) || (x < 0) || (y < 0)) {
            throw new IllegalArgumentException();
        }
        return image[x][y];
    }
880800
public short getPixelValue(GriddedTile griddedTile, Double value) {
		int unsignedPixelValue = getUnsignedPixelValue(griddedTile, value);
		short pixelValue = getPixelValue(unsignedPixelValue);
		return pixelValue;
	}
31230
public int readBit( int row , int col ) {
		// todo use adjustments from near by alignment patterns

		float center = 0.5f;

//		if( pixel.x < -0.5 || pixel.y < -0.5 || pixel.x > imageWidth || pixel.y > imageHeight )
//			return -1;

		transformGrid.gridToImage(row+center-0.2f, col+center, pixel);
		float pixel01 = interpolate.get(pixel.x,pixel.y);
		transformGrid.gridToImage(row+center+0.2f, col+center, pixel);
		float pixel21 = interpolate.get(pixel.x,pixel.y);
		transformGrid.gridToImage(row+center, col+center-0.2f, pixel);
		float pixel10 = interpolate.get(pixel.x,pixel.y);
		transformGrid.gridToImage(row+center, col+center+0.2f, pixel);
		float pixel12 = interpolate.get(pixel.x,pixel.y);
		transformGrid.gridToImage(row+center, col+center, pixel);
		float pixel00 = interpolate.get(pixel.x,pixel.y);

//		float threshold = this.threshold*1.25f;

		int total = 0;
		if( pixel01 < threshold ) total++;
		if( pixel21 < threshold ) total++;
		if( pixel10 < threshold ) total++;
		if( pixel12 < threshold ) total++;
		if( pixel00 < threshold ) total++;

		if( total >= 3 )
			return 1;
		else
			return 0;

//		float value = (pixel01+pixel21+pixel10+pixel12)*0.25f;
//		value = value*0.5f + pixel00*0.5f;

		// in at least one situation this was found to improve the reading
//		float threshold;
//		if( qr  != null ) {
//			int N = qr.getNumberOfModules();
//			if( row > N/2 ) {
//				if( col < N/2 )
//					threshold = (float)qr.threshDown;
//				else {
//					threshold = (float)(qr.threshDown+qr.threshRight)/2f;
//				}
//			} else if( col < N/2 ) {
//				threshold = (float)qr.threshCorner;
//			} else {
//				threshold = (float)qr.threshRight;
//			}
//		} else {
//			threshold = this.threshold;
//		}

//		if( pixel00 < threshold )
//			return 1;
//		else
//			return 0;
	}
231524
public Double getValue(GriddedTile griddedTile, BufferedImage image, int x,
			int y) {
		short pixelValue = getPixelValue(image, x, y);
		Double value = getValue(griddedTile, pixelValue);
		return value;
	}
761820
public static long getTileColumn(BoundingBox totalBox, long matrixWidth,
			double longitude) {

		double minX = totalBox.getMinLongitude();
		double maxX = totalBox.getMaxLongitude();

		long tileId;
		if (longitude < minX) {
			tileId = -1;
		} else if (longitude >= maxX) {
			tileId = matrixWidth;
		} else {
			double matrixWidthMeters = totalBox.getMaxLongitude()
					- totalBox.getMinLongitude();
			double tileWidth = matrixWidthMeters / matrixWidth;
			tileId = (long) ((longitude - minX) / tileWidth);
		}

		return tileId;
	}
701148
private double valueToPixelValue(GriddedTile griddedTile, double value) {

		double pixelValue = value;

		if (griddedCoverage != null
				&& griddedCoverage.getDataType() == GriddedCoverageDataType.INTEGER) {

			pixelValue -= griddedCoverage.getOffset();
			pixelValue /= griddedCoverage.getScale();
			if (griddedTile != null) {
				pixelValue -= griddedTile.getOffset();
				pixelValue /= griddedTile.getScale();
			}

		}

		return pixelValue;
	}
161693
public static Point getPixelRelativeToTile(LatLong latLong, Tile tile) {
        return getPixelRelative(latLong, tile.mapSize, tile.getOrigin());
    }
886538
function getTile(e) {
        var g = grid();
        var regExp = new RegExp(gm.tileRegexp());
        for (var i = 0; i < g.length; i++) {
            if (e) {
                var isInside = ((g[i][0] <= e.y) &&
                     ((g[i][0] + 256) > e.y) &&
                      (g[i][1] <= e.x) &&
                     ((g[i][1] + 256) > e.x));
                if(isInside && regExp.exec(g[i][2].src)) {
                    return g[i][2];
                }
            }
        }
        return false;
    }