MCPcopy Create free account
hub / github.com/Snapchat/Valdi / rasterInto

Method rasterInto

valdi/src/valdi/android/AndroidViewHolder.cpp:76–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76Valdi::Result<Valdi::Void> AndroidViewHolder::rasterInto(const Valdi::Ref<Valdi::IBitmap>& bitmap,
77 const Valdi::Frame& frame,
78 const Valdi::Matrix& transform,
79 float rasterScaleX,
80 float rasterScaleY) {
81 auto androidBitmap = Valdi::castOrNull<AndroidBitmap>(bitmap);
82 SC_ASSERT_NOTNULL(androidBitmap);
83 if (androidBitmap == nullptr) {
84 return Valdi::Error("Invalid bitmap");
85 }
86
87 Valdi::CoordinateResolver resolver(_viewManager.getPointScale());
88 auto left = resolver.toPixels(frame.getLeft());
89 auto top = resolver.toPixels(frame.getTop());
90 auto right = resolver.toPixels(frame.getRight());
91 auto bottom = resolver.toPixels(frame.getBottom());
92
93 auto javaTransform = JavaObject(JavaEnv());
94 if (!transform.isIdentity()) {
95 auto affineValues = transform.values;
96 const float a = affineValues[0];
97 const float b = affineValues[1];
98 const float c = affineValues[2];
99 const float d = affineValues[3];
100 const float tx = resolver.toPixelsF(affineValues[4]);
101 const float ty = resolver.toPixelsF(affineValues[5]);
102
103 // Android Matrix.setValues expects 9 floats in row-major order:
104 // [ MSCALE_X, MSKEW_X, MTRANS_X,
105 // MSKEW_Y, MSCALE_Y, MTRANS_Y,
106 // MPERSP_0, MPERSP_1, MPERSP_2 ]
107 // Map from affine [a, b, c, d, tx, ty]
108 float matrix9[9] = {a, c, tx, b, d, ty, 0.f, 0.f, 1.f};
109 javaTransform = toJavaFloatArray(JavaEnv(), matrix9, 9);
110 }
111
112 auto errorMessage = JavaEnv::getCache().getViewRefRasterMethod().call(toObject(),
113 androidBitmap->getJavaBitmap(),
114 left,
115 top,
116 right,
117 bottom,
118 rasterScaleX,
119 rasterScaleY,
120 javaTransform);
121
122 if (errorMessage.isNull()) {
123 return Valdi::Void();
124 }
125
126 return Valdi::Error(toInternedString(JavaEnv(), errorMessage));
127}
128
129VALDI_CLASS_IMPL(AndroidViewHolder)
130

Callers

nothing calls this directly

Calls 15

toJavaFloatArrayFunction · 0.85
toObjectFunction · 0.85
toInternedStringFunction · 0.85
toPixelsMethod · 0.80
getTopMethod · 0.80
getRightMethod · 0.80
getBottomMethod · 0.80
toPixelsFMethod · 0.80
getJavaBitmapMethod · 0.80
callMethod · 0.65
ErrorInterface · 0.50
JavaObjectClass · 0.50

Tested by

no test coverage detected