This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Context context = getApplicationContext(); | |
ContentResolver contentResolver = context.getContentResolver(); | |
try (AssetFileDescriptor assetFileDescriptor | |
= contentResolver.openAssetFileDescriptor(imageUri, "r")) { | |
ParcelFileDescriptor parcelFileDescriptor = assetFileDescriptor.getParcelFileDescriptor(); | |
int fd = parcelFileDescriptor.getFd(); | |
// TODO: Read file using the fd in native layer. | |
// Important: Native layer shouldn't assume ownership of this fd and close it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
private final ActivityResultLauncher<String[]> galleryActivityLauncher | |
= registerForActivityResult(new ActivityResultContracts.OpenDocument(), | |
this::onPickImage); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let constraints: MediaTrackConstraints = { | |
"torch": true, | |
"advanced": [{ "torch": true }] | |
}; | |
await html5Qrcode.applyVideoConstraints(constraints); | |
let settings = html5Qrcode.getRunningTrackSettings(); | |
if (settings.torch === true) { | |
// Torch was indeed enabled, succeess. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Returns {@code true} if torch is supported. */ | |
function isTorchSupported(html5Qrcode: Html5Qrcode): boolean { | |
let settings = html5Qrcode.getRunningTrackSettings(); | |
return "torch" in settings; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let html5QrcodeScanner = new Html5QrcodeScanner( | |
"reader", | |
{ | |
fps: 10, | |
qrbox: {width: 250, height: 250}, | |
rememberLastUsedCamera: true, | |
aspectRatio: 1.7777778, | |
showTorchButtonIfSupported: true | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float a = 100.151f + 0.151f; | |
float b = 100.101f + 0.201f; | |
std::cout << "a = " << a << "; b = " << b << "\n"; | |
float diff = a - b; | |
std::cout << "Diff = " << diff << "\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline bool isNearlyEqual(float val_a, float val_b, float max_relative_diff = FLT_EPSILON) { | |
float abs_diff = abs(val_a - val_b); | |
val_a = fabs(val_a); | |
val_b = fabs(val_b); | |
float scaled_epsilon = max_relative_diff * max(val_a, val_b); | |
return abs_diff <= scaled_epsilon; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float a = 100.151f + 0.151f; | |
float b = 100.101f + 0.201f; | |
bool d = isNearlyEqual(a, b); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <math.h> | |
#include <float.h> | |
using namespace std; | |
inline bool isNearlyEqual(float val_a, float val_b) { | |
return fabs(val_a - val_b) < FLT_EPSILON; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constexpr int kIterations = 10000000; | |
int counter = 0; | |
for (int i = 0; i < kIterations; ++i) { | |
float a = 0.151f + 0.151f; | |
float b = 0.101f + 0.201f; | |
bool d = (a == b); | |
if (d) { |