Encodes pixel data from a Ruby Array or NArray, and writes it to the pixel data element (7FE0,0010).

 @param [Array<Integer>, NArray] values an Array (or NArray) containing integer pixel values
492664
def pixels=(values)
      raise ArgumentError, "The given argument does not respond to #to_a (got an argument of class #{values.class})" unless values.respond_to?(:to_a)
      if values.class.ancestors.to_s.include?('NArray')
        # With an NArray argument, make sure that it gets properly converted to an Array:
        if values.shape.length > 2
          # For a 3D NArray we need to rearrange to ensure that the pixels get their
          # proper order when converting to an ordinary Array instance:
          narr = Numo::Int16.zeros(values.shape[0], values.shape[1] * values.shape[2])
          values.shape[0].times do |i|
            narr[i, true] = values[i, true, true].reshape(values.shape[1] * values.shape[2])
          end
          values = narr
        end
      end
      # Encode the pixel data:
      bin = encode_pixels(values.to_a.flatten)
      # Write the binary data to the Pixel Data Element:
      write_pixels(bin)
    end
36805
public void writeSmallDoubleArray( double[] values ) {
        int byteSize = values.length * 8 + 1;
        this.addUnsignedByte( ( short ) values.length );
        doWriteDoubleArray( values, byteSize );

    }
991441
public void writeMediumDoubleArray( double[] values ) {
        int byteSize = values.length * 8 + 2;
        this.addUnsignedShort( values.length );
        doWriteDoubleArray( values, byteSize );

    }
131000
public void writeUnscaledValue(Slice slice)
    {
        BigInteger value = Decimals.decodeUnscaledValue(slice);

        // encode the signed number as a positive integer
        value = value.shiftLeft(1);
        int sign = value.signum();
        if (sign < 0) {
            value = value.negate();
            value = value.subtract(BigInteger.ONE);
        }
        int length = value.bitLength();
        while (true) {
            long lowBits = value.longValue() & 0x7fff_ffff_ffff_ffffL;
            length -= 63;
            // write out the next 63 bits worth of data
            for (int i = 0; i < 9; ++i) {
                // if this is the last byte, leave the high bit off
                if (length <= 0 && (lowBits & ~0x7f) == 0) {
                    buffer.write((byte) lowBits);
                    return;
                }
                else {
                    buffer.write((byte) (0x80 | (lowBits & 0x7f)));
                    lowBits >>>= 7;
                }
            }
            value = value.shiftRight(63);
        }
    }
950550
public void setPixelValue(WritableRaster raster, int x, int y,
			int unsignedPixelValue) {
		short pixelValue = getPixelValue(unsignedPixelValue);
		setPixelValue(raster, x, y, pixelValue);
	}
747606
public static final void writeInt(int value, byte[] array, int offset)
    {
        if (array.length < offset + 4)
        {
            throw new IllegalArgumentException("no room in array");
        }
        array[offset] = (byte) (value >> 24);
        array[offset + 1] = (byte) ((value >> 16) & 0xff);
        array[offset + 2] = (byte) ((value >> 8) & 0xff);
        array[offset + 3] = (byte) (value & 0xff);
    }
220362
public void writeNullableByteArray( byte[] value )
    {
        if (value == null)
            write(NULL_VALUE);
        else
        {
            write(NOT_NULL_VALUE);
            writeInt(value.length);
            write(value);
        }
    }
387659
public static final void writeDouble(double value, byte[] array, int offset)
    {
        writeLong(Double.doubleToRawLongBits(value), array, offset);
    }
236954
public void writeLargeDoubleArray( double[] values ) {
        int byteSize = values.length * 8 + 4;
        this.add( values.length );
        doWriteDoubleArray( values, byteSize );


    }
114168
static private void encodeBytes(byte previous, byte current, int byteIndex, StringBuilder output) {
        int chunk;
        int offset = byteIndex % 5;
        switch (offset) {
            case 0:
                chunk = ((current & 0xF8) >>> 3);
                output.append(lookupTable.charAt(chunk));
                break;
            case 1:
                chunk = (((previous & 0x07) << 2) | ((current & 0xC0) >>> 6));
                output.append(lookupTable.charAt(chunk));
                chunk = ((current & 0x3E) >>> 1);
                output.append(lookupTable.charAt(chunk));
                break;
            case 2:
                chunk = (((previous & 0x01) << 4) | ((current & 0xF0) >>> 4));
                output.append(lookupTable.charAt(chunk));
                break;
            case 3:
                chunk = (((previous & 0x0F) << 1) | ((current & 0x80) >>> 7));
                output.append(lookupTable.charAt(chunk));
                chunk = ((current & 0x7C) >>> 2);
                output.append(lookupTable.charAt(chunk));
                break;
            case 4:
                chunk = (((previous & 0x03) << 3) | ((current & 0xE0) >>> 5));
                output.append(lookupTable.charAt(chunk));
                chunk = (current & 0x1F);
                output.append(lookupTable.charAt(chunk));
                break;
        }
    }
442721
function encodeArray_NUM_DELTA_INT( encoder, data, n_from, n_to ) {

	//
	// Delta Numeric Array (NUM_DELTA_INT)
	//
	// ...  ....       .   +   Data Length   +   Initial Value
	// 001 [DWS_TYPE] [LN]    [16bit/32bit]    [8bit/16bit/32bit]
	//

	// Get downscale type
	var n_delta_type = deltaEncTypeInt( n_from, n_to );
	if (n_delta_type === undefined) {
		throw new Errors.EncodeError('Non-viable integer delta value from '+_NUMTYPE[n_from]+' to '+_NUMTYPE[n_to]+'!');
	}

	encoder.counters.arr_delta_int+=1;
	encoder.log(LOG.ARR, "array.numeric.delta.int, len="+data.length+
		", from="+_NUMTYPE[n_from]+", to="+_NUMTYPE[n_to]+
		", type="+_NUMTYPE_DOWNSCALE_DELTA_INT[n_delta_type]+" ("+n_delta_type+")");


	if (data.length < UINT16_MAX) { // 16-bit length prefix
		encoder.stream8.write( pack1b( ARR_OP.NUM_DELTA_INT | NUMTYPE_LN.UINT16 | (n_delta_type << 1) ) );
		encoder.stream16.write( pack2b( data.length, false ) );
		encoder.counters.arr_hdr+=3;
	} else { // 32-bit length prefix
		encoder.stream8.write( pack1b( ARR_OP.NUM_DELTA_INT | NUMTYPE_LN.UINT32 | (n_delta_type << 1) ) );
		encoder.stream32.write( pack4b( data.length, false ) );
		encoder.counters.arr_hdr+=5;
	}

	// Write initial value
	pickStream( encoder, n_from )
		.write( packByNumType[n_from]( data[0] ) );

	// Delta-encode integers
	pickStream( encoder, n_to)
		.write( packTypedArray( deltaEncodeIntegers( data, n_to ) ) );

}
603542
function(pixels, data) {
    const pixel = pixels[0];
    const value = vgi(pixel);
    summarize(value, data.counts);
    if (value >= data.threshold) {
      pixel[0] = 0;
      pixel[1] = 255;
      pixel[2] = 0;
      pixel[3] = 128;
    } else {
      pixel[3] = 0;
    }
    return pixel;
  }
120437
function encodeArray_NUM_RAW( encoder, data, n_type ) {

	//
	// RAW Numeric Array (NUM_RAW)
	//
	// ....  ...    .   +   Data Length
	// 0101 [TYPE] [LN]    [16bit/32bit]
	//

	encoder.counters.arr_num_raw+=1;
	encoder.log(LOG.ARR, "array.numeric.raw, len="+data.length+
		", type="+_NUMTYPE[n_type]+" ("+n_type+")");

	if (data.length < UINT16_MAX) { // 16-bit length prefix
		encoder.stream8.write( pack1b( ARR_OP.NUM_RAW | NUMTYPE_LN.UINT16 | (n_type << 1) ) );
		encoder.stream16.write( pack2b( data.length, false ) );
		encoder.counters.arr_hdr+=3;
	} else { // 32-bit length prefix
		encoder.stream8.write( pack1b( ARR_OP.NUM_RAW | NUMTYPE_LN.UINT32 | (n_type << 1) ) );
		encoder.stream32.write( pack4b( data.length, false ) );
		encoder.counters.arr_hdr+=5;
	}

	// Encode the short array
	pickStream( encoder, n_type )
		.write( packTypedArray( convertArray( data, n_type ) ) );

}
37829
function getPixelValues (pixelData) {
  let minPixelValue = Number.MAX_VALUE;
  let maxPixelValue = Number.MIN_VALUE;
  const len = pixelData.length;
  let pixel;

  for (let i = 0; i < len; i++) {
    pixel = pixelData[i];
    minPixelValue = minPixelValue < pixel ? minPixelValue : pixel;
    maxPixelValue = maxPixelValue > pixel ? maxPixelValue : pixel;
  }

  return {
    minPixelValue,
    maxPixelValue
  };
}
1355858
public static void longToByteArray(long lValue, byte[] buffer, int nStartIndex) {
	buffer[nStartIndex] = (byte) (lValue >>> 56);
	buffer[nStartIndex + 1] = (byte) ((lValue >>> 48) & 0x0ff);
	buffer[nStartIndex + 2] = (byte) ((lValue >>> 40) & 0x0ff);
	buffer[nStartIndex + 3] = (byte) ((lValue >>> 32) & 0x0ff);
	buffer[nStartIndex + 4] = (byte) ((lValue >>> 24) & 0x0ff);
	buffer[nStartIndex + 5] = (byte) ((lValue >>> 16) & 0x0ff);
	buffer[nStartIndex + 6] = (byte) ((lValue >>> 8) & 0x0ff);
	buffer[nStartIndex + 7] = (byte) lValue;
    }
815825
private static void encodeInteger(ByteBuf out, int mask, int n, long i) {
        assert n >= 0 && n <= 8 : "N: " + n;
        int nbits = 0xFF >>> (8 - n);
        if (i < nbits) {
            out.writeByte((int) (mask | i));
        } else {
            out.writeByte(mask | nbits);
            long length = i - nbits;
            for (; (length & ~0x7F) != 0; length >>>= 7) {
                out.writeByte((int) ((length & 0x7F) | 0x80));
            }
            out.writeByte((int) length);
        }
    }
244626
void encode(Bitmap bitmap, BufferedSink sink) throws IOException {
    int height = bitmap.height();
    int width = bitmap.width();

    int bytesPerPixel = 3;
    int rowByteCountWithoutPadding = (bytesPerPixel * width);
    int rowByteCount = ((rowByteCountWithoutPadding + 3) / 4) * 4;
    int pixelDataSize = rowByteCount * height;
    int bmpHeaderSize = 14;
    int dibHeaderSize = 40;

    // BMP Header
    sink.writeUtf8("BM"); // ID.
    sink.writeIntLe(bmpHeaderSize + dibHeaderSize + pixelDataSize); // File size.
    sink.writeShortLe(0); // Unused.
    sink.writeShortLe(0); // Unused.
    sink.writeIntLe(bmpHeaderSize + dibHeaderSize); // Offset of pixel data.

    // DIB Header
    sink.writeIntLe(dibHeaderSize);
    sink.writeIntLe(width);
    sink.writeIntLe(height);
    sink.writeShortLe(1);  // Color plane count.
    sink.writeShortLe(bytesPerPixel * Byte.SIZE);
    sink.writeIntLe(0);    // No compression.
    sink.writeIntLe(16);   // Size of bitmap data including padding.
    sink.writeIntLe(2835); // Horizontal print resolution in pixels/meter. (72 dpi).
    sink.writeIntLe(2835); // Vertical print resolution in pixels/meter. (72 dpi).
    sink.writeIntLe(0);    // Palette color count.
    sink.writeIntLe(0);    // 0 important colors.

    // Pixel data.
    for (int y = height - 1; y >= 0; y--) {
      for (int x = 0; x < width; x++) {
        sink.writeByte(bitmap.blue(x, y));
        sink.writeByte(bitmap.green(x, y));
        sink.writeByte(bitmap.red(x, y));
      }

      // Padding for 4-byte alignment.
      for (int p = rowByteCountWithoutPadding; p < rowByteCount; p++) {
        sink.writeByte(0);
      }
    }
  }