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

Function bitmapToData

snap_drawing/src/snap_drawing/cpp/Utils/BitmapUtils.cpp:102–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102Valdi::Result<sk_sp<SkData>> bitmapToData(const Valdi::Ref<Valdi::IBitmap>& bitmap,
103 const Valdi::BitmapInfo& info,
104 bool copy) {
105 auto* bytes = bitmap->lockBytes();
106 if (bytes == nullptr) {
107 return Valdi::Error("Failed to lock bytes");
108 }
109
110 auto size = info.rowBytes * static_cast<size_t>(info.height);
111
112 if (copy) {
113 auto data = SkData::MakeWithCopy(bytes, size);
114 bitmap->unlockBytes();
115 return data;
116 } else {
117 return SkData::MakeWithProc(bytes, size, &releaseBitmap, Valdi::unsafeBridgeRetain(bitmap.get()));
118 }
119}
120
121} // namespace snap::drawing

Callers 1

makeFromBitmapMethod · 0.85

Calls 5

unsafeBridgeRetainFunction · 0.85
getMethod · 0.65
ErrorInterface · 0.50
lockBytesMethod · 0.45
unlockBytesMethod · 0.45

Tested by

no test coverage detected