Home / Function/ bitmapToFloatBuffer() — pytorch Function Reference

bitmapToFloatBuffer() — pytorch Function Reference

Architecture documentation for the bitmapToFloatBuffer() function in TensorImageUtils.java from the pytorch codebase.

Function java AndroidRuntime JNILayer calls 3 called by 1

Entity Profile

Dependency Diagram

graph TD
  cb0ec3bf_804a_0d54_e6cf_c94ea97cada8["bitmapToFloatBuffer()"]
  c81bb7ae_2eee_9e76_fb40_f1e6bea8df1f["bitmapToFloat32Tensor()"]
  c81bb7ae_2eee_9e76_fb40_f1e6bea8df1f -->|calls| cb0ec3bf_804a_0d54_e6cf_c94ea97cada8
  985ac895_a665_e4e5_3d8c_817c2e044489["checkOutBufferCapacity()"]
  cb0ec3bf_804a_0d54_e6cf_c94ea97cada8 -->|calls| 985ac895_a665_e4e5_3d8c_817c2e044489
  09321404_5d8c_f9fd_739a_1be11da65720["checkNormMeanArg()"]
  cb0ec3bf_804a_0d54_e6cf_c94ea97cada8 -->|calls| 09321404_5d8c_f9fd_739a_1be11da65720
  23b436aa_d9b0_0abc_b9e8_a029e620d1de["checkNormStdArg()"]
  cb0ec3bf_804a_0d54_e6cf_c94ea97cada8 -->|calls| 23b436aa_d9b0_0abc_b9e8_a029e620d1de
  style cb0ec3bf_804a_0d54_e6cf_c94ea97cada8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

android/pytorch_android_torchvision/src/main/java/org/pytorch/torchvision/TensorImageUtils.java lines 70–114

  public static void bitmapToFloatBuffer(
      final Bitmap bitmap,
      final int x,
      final int y,
      final int width,
      final int height,
      final float[] normMeanRGB,
      final float[] normStdRGB,
      final FloatBuffer outBuffer,
      final int outBufferOffset,
      final MemoryFormat memoryFormat) {
    checkOutBufferCapacity(outBuffer, outBufferOffset, width, height);
    checkNormMeanArg(normMeanRGB);
    checkNormStdArg(normStdRGB);
    if (memoryFormat != MemoryFormat.CONTIGUOUS && memoryFormat != MemoryFormat.CHANNELS_LAST) {
      throw new IllegalArgumentException("Unsupported memory format " + memoryFormat);
    }

    final int pixelsCount = height * width;
    final int[] pixels = new int[pixelsCount];
    bitmap.getPixels(pixels, 0, width, x, y, width, height);
    if (MemoryFormat.CONTIGUOUS == memoryFormat) {
      final int offset_g = pixelsCount;
      final int offset_b = 2 * pixelsCount;
      for (int i = 0; i < pixelsCount; i++) {
        final int c = pixels[i];
        float r = ((c >> 16) & 0xff) / 255.0f;
        float g = ((c >> 8) & 0xff) / 255.0f;
        float b = ((c) & 0xff) / 255.0f;
        outBuffer.put(outBufferOffset + i, (r - normMeanRGB[0]) / normStdRGB[0]);
        outBuffer.put(outBufferOffset + offset_g + i, (g - normMeanRGB[1]) / normStdRGB[1]);
        outBuffer.put(outBufferOffset + offset_b + i, (b - normMeanRGB[2]) / normStdRGB[2]);
      }
    } else {
      for (int i = 0; i < pixelsCount; i++) {
        final int c = pixels[i];
        float r = ((c >> 16) & 0xff) / 255.0f;
        float g = ((c >> 8) & 0xff) / 255.0f;
        float b = ((c) & 0xff) / 255.0f;
        outBuffer.put(outBufferOffset + 3 * i + 0, (r - normMeanRGB[0]) / normStdRGB[0]);
        outBuffer.put(outBufferOffset + 3 * i + 1, (g - normMeanRGB[1]) / normStdRGB[1]);
        outBuffer.put(outBufferOffset + 3 * i + 2, (b - normMeanRGB[2]) / normStdRGB[2]);
      }
    }
  }

Subdomains

Frequently Asked Questions

What does bitmapToFloatBuffer() do?
bitmapToFloatBuffer() is a function in the pytorch codebase.
What does bitmapToFloatBuffer() call?
bitmapToFloatBuffer() calls 3 function(s): checkNormMeanArg, checkNormStdArg, checkOutBufferCapacity.
What calls bitmapToFloatBuffer()?
bitmapToFloatBuffer() is called by 1 function(s): bitmapToFloat32Tensor.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free