### Cimbar File Transfer Command-Line Sender Example Source: https://context7.com/sz3/cfc/llms.txt Demonstrates how to use the native `cimbar_send` command-line tool to transfer a file. It includes steps for cloning the libcimbar repository, building the tool using CMake, and executing the send command with the file path. This is an alternative to the web-based sender. ```bash # Sender side (desktop/laptop) # 1. Navigate to https://cimbar.org in a web browser # 2. Select a file to transfer (e.g., document.pdf, max 33MB) # 3. Animated cimbar barcode appears on screen at 30-60 FPS # Receiver side (Android phone) # 1. Install CameraFileCopy from F-Droid or Google Play # 2. Grant camera permission when prompted # 3. Point phone camera at the animated barcode on screen # 4. Align corners with on-screen guides (guides turn yellow, then green) # 5. Progress bars appear at bottom showing per-file completion # 6. When complete, save dialog appears - choose destination # 7. File is saved with original filename # Performance characteristics: # - Transfer speed: 850 kbps (~106 KB/s) typical # - Frame rate: 30-60 FPS # - Error rate: <1% with Reed-Solomon ECC # - File size limit: 33MB (after compression) # - Modes: 4C (4-color), B/68 (default), BM/67 (alternate) # - Auto-detection: Automatically detects encoding mode # Alternative sender (native command-line tool): git clone https://github.com/sz3/libcimbar.git cd libcimbar cmake -B build -DCMAKE_BUILD_TYPE=Release cmake --build build ./build/cimbar_send /path/to/file.pdf # Point camera at terminal window displaying animated barcode ``` -------------------------------- ### Wirehair Encoder/Decoder Example in C++ Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/wirehair/README.md This C++ example demonstrates the core functionality of Wirehair, including creating an encoder and a decoder, encoding message blocks, and decoding received blocks. It simulates packet loss and recovers the original message, showcasing the library's resilience. It requires the Wirehair library to be included. ```cpp #include static bool ReadmeExample() { // Size of packets to produce static const int kPacketSize = 1400; // Note: Does not need to be an even multiple of packet size or 16 etc static const int kMessageBytes = 1000 * 1000 + 333; vector message(kMessageBytes); // Fill message contents memset(&message[0], 1, message.size()); // Create encoder WirehairCodec encoder = wirehair_encoder_create(nullptr, &message[0], kMessageBytes, kPacketSize); if (!encoder) { cout << "!!! Failed to create encoder" << endl; return false; } // Create decoder WirehairCodec decoder = wirehair_decoder_create(nullptr, kMessageBytes, kPacketSize); if (!decoder) { // Free memory for encoder wirehair_free(encoder); cout << "!!! Failed to create decoder" << endl; return false; } unsigned blockId = 0, needed = 0; for (;;) { // Select which block to encode. // Note: First N blocks are the original data, so it's possible to start // sending data while wirehair_encoder_create() is getting started. blockId++; // Simulate 10% packetloss if (blockId % 10 == 0) { continue; } // Keep track of how many pieces were needed ++needed; vector block(kPacketSize); // Encode a packet uint32_t writeLen = 0; WirehairResult encodeResult = wirehair_encode( encoder, // Encoder object blockId, // ID of block to generate &block[0], // Output buffer kPacketSize, // Output buffer size &writeLen); // Returned block length if (encodeResult != Wirehair_Success) { cout << "wirehair_encode failed: " << encodeResult << endl; return false; } // Attempt decode WirehairResult decodeResult = wirehair_decode( decoder, // Decoder object blockId, // ID of block that was encoded &block[0], // Input block writeLen); // Block length // If decoder returns success: if (decodeResult == Wirehair_Success) { // Decoder has enough data to recover now break; } if (decodeResult != Wirehair_NeedMore) { cout << "wirehair_decode failed: " << decodeResult << endl; return false; } } vector decoded(kMessageBytes); // Recover original data on decoder side WirehairResult decodeResult = wirehair_recover( decoder, &decoded[0], kMessageBytes); if (decodeResult != Wirehair_Success) { cout << "wirehair_recover failed: " << decodeResult << endl; return false; } // Free memory for encoder and decoder wirehair_free(encoder); wirehair_free(decoder); return true; } int main() { const WirehairResult initResult = wirehair_init(); if (initResult != Wirehair_Success) { SIAMESE_DEBUG_BREAK(); cout << "!!! Wirehair initialization failed: " << initResult << endl; return -1; } if (!ReadmeExample()) { SIAMESE_DEBUG_BREAK(); cout << "!!! Example usage failed" << endl; return -2; } ``` -------------------------------- ### CMake Project Configuration and Dependencies Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/CMakeLists.txt Configures the CMake build for the libcimbar project. Sets the minimum version, project name, installation prefix, C++ standard, and defines OpenCV library dependencies. It also handles the CPPFILESYSTEM variable. ```cmake cmake_minimum_required(VERSION 3.10) project ( libcimbar ) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${libcimbar_SOURCE_DIR}/dist" CACHE PATH "..." FORCE) endif() set(CMAKE_CXX_STANDARD 17) if(NOT DEFINED OPENCV_LIBS) set(OPENCV_LIBS "opencv_imgcodecs" "opencv_imgproc" "opencv_photo" "opencv_core") endif() if(NOT DEFINED CPPFILESYSTEM) set(CPPFILESYSTEM "stdc++fs") endif() ``` -------------------------------- ### Create Correct Static Library Target Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/libcorrect/CMakeLists.txt Defines a static library target named 'correct_static'. It conditionally includes object files from SSE-optimized or non-SSE versions based on `HAVE_SSE`. Also manages header file installation and custom targets for headers. ```cmake set(INSTALL_HEADERS "${PROJECT_BINARY_DIR}/include/correct.h") add_custom_target(correct-h ALL COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/include/correct.h ${PROJECT_BINARY_DIR}/include/correct.h) if(HAVE_SSE) set(correct_obj_files $ $ $) set(INSTALL_HEADERS ${INSTALL_HEADERS} ${PROJECT_BINARY_DIR}/include/correct-sse.h) add_custom_target(correct-sse-h ALL COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/include/correct-sse.h ${PROJECT_BINARY_DIR}/include/correct-sse.h) else() set(correct_obj_files $ $) endif() add_library(correct_static ${correct_obj_files}) set_target_properties(correct_static PROPERTIES OUTPUT_NAME "correct") if(HAVE_SSE) target_compile_definitions(correct_static PUBLIC HAVE_SSE=1) endif() ``` -------------------------------- ### Emscripten Canvas Initialization JavaScript Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/web/index.html This JavaScript code initializes an Emscripten-generated application on an HTML canvas element. It retrieves the canvas element by its ID and sets up an event handler for when the Emscripten runtime is ready. Once initialized, it calls the 'init' and 'nextFrame' functions of the 'Main' object, likely to start the application's rendering loop. ```javascript var canvas = document.getElementById('canvas'); var Module = {}; Module.canvas = canvas; Module.onRuntimeInitialized = () => { Main.init(canvas); Main.nextFrame(); }; ``` -------------------------------- ### Initialize Camera2 API for Barcode Scanning - Java Source: https://context7.com/sz3/cfc/llms.txt This Java code initializes the Camera2 API, selecting the back camera by default and setting up listeners for camera device state changes. It includes error handling for camera access and ensures manual control for exposure and focus. ```java protected boolean initializeCamera() { Log.i(LOGTAG, "initializeCamera"); CameraManager manager = (CameraManager) getContext() .getSystemService(Context.CAMERA_SERVICE); try { String camList[] = manager.getCameraIdList(); if (camList.length == 0) { Log.e(LOGTAG, "Error: camera isn't detected."); return false; } // Select back camera by default if (mCameraIndex == CameraBridgeViewBase.CAMERA_ID_ANY) { mCameraID = camList[0]; } else { for (String cameraID : camList) { CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraID); if ((mCameraIndex == CameraBridgeViewBase.CAMERA_ID_BACK && characteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_BACK) || (mCameraIndex == CameraBridgeViewBase.CAMERA_ID_FRONT && characteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT)) { mCameraID = cameraID; break; } } } if (mCameraID != null) { Log.i(LOGTAG, "Opening camera: " + mCameraID); manager.openCamera(mCameraID, mStateCallback, mBackgroundHandler); } return true; } catch (CameraAccessException | IllegalArgumentException | SecurityException e) { Log.e(LOGTAG, "OpenCamera - Exception", e); } return false; } private final CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() { @Override public void onOpened(CameraDevice cameraDevice) { mCameraDevice = cameraDevice; createCameraPreviewSession(); } @Override public void onDisconnected(CameraDevice cameraDevice) { cameraDevice.close(); mCameraDevice = null; } @Override public void onError(CameraDevice cameraDevice, int error) { cameraDevice.close(); mCameraDevice = null; } }; ``` -------------------------------- ### Initialize Android Activity with Camera Permissions and OpenCV - Java Source: https://context7.com/sz3/cfc/llms.txt This Java code initializes the Android activity, requests camera permissions, and sets up the OpenCV Camera View. It configures the screen to stay on and be fullscreen, and handles the mode switching for the camera view. ```java @Override public void onCreate(Bundle savedInstanceState) { Log.i(TAG, "called onCreate"); super.onCreate(savedInstanceState); // Keep screen on and fullscreen for continuous scanning getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); // Request camera permission (Android 6+) ActivityCompat.requestPermissions( this, new String[]{Manifest.permission.CAMERA}, CAMERA_PERMISSION_REQUEST ); this.dataPath = this.getFilesDir().getPath(); // Initialize UI setContentView(R.layout.activity_main); mOpenCvCameraView = findViewById(R.id.main_surface); mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE); mOpenCvCameraView.setCvCameraViewListener(this); // Setup mode toggle (auto/locked mode switching) mModeSwitch = (ModeSelToggle) findViewById(R.id.mode_switch); mModeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { modeVal = detectedMode; // Lock to detected mode } else { modeVal = 0; // Auto-detect mode } } }); } private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @Override public void onManagerConnected(int status) { if (status == LoaderCallbackInterface.SUCCESS) { Log.i(TAG, "OpenCV loaded successfully"); // Load native library AFTER OpenCV initialization System.loadLibrary("cfc-cpp"); mOpenCvCameraView.enableView(); } else { super.onManagerConnected(status); } } }; ``` -------------------------------- ### Set Build Output Paths and Include Directories Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/libcorrect/CMakeLists.txt Configures the output paths for libraries and executables, and adds a directory to the include path. This helps organize build artifacts and makes headers accessible. ```cmake set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) include_directories(${PROJECT_SOURCE_DIR}/include) ``` -------------------------------- ### CMake Build Configuration for encoder_test Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/lib/encoder/test/CMakeLists.txt Defines the build process for the encoder_test executable. It specifies the minimum required CMake version, project name, source files, include directories, the executable target, and the libraries it depends on. Dependencies include 'cimb_translator', 'extractor', 'correct_static', 'wirehair', 'zstd', OpenCV libraries, and C++ filesystem library. ```cmake cmake_minimum_required(VERSION 3.10) project(encoder_test) set (SOURCES test.cpp DecoderTest.cpp EncoderTest.cpp EncoderRoundTripTest.cpp aligned_streamTest.cpp escrow_buffer_writerTest.cpp reed_solomon_streamTest.cpp ) include_directories( ${libcimbar_SOURCE_DIR}/test ${libcimbar_SOURCE_DIR}/test/lib ${CMAKE_CURRENT_SOURCE_DIR}/.. ) add_executable ( encoder_test ${SOURCES} ) add_test(encoder_test encoder_test) target_link_libraries(encoder_test cimb_translator extractor correct_static wirehair zstd ${OPENCV_LIBS} ${CPPFILESYSTEM} ) ``` -------------------------------- ### CMake Build Configuration for extractor_test Executable Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/lib/extractor/test/CMakeLists.txt This CMakeLists.txt file defines the build process for the 'extractor_test' executable. It specifies the required CMake version, project name, source files, include directories, and the libraries to link against, including 'extractor' and OpenCV libraries. It also registers the executable as a test. ```cmake cmake_minimum_required(VERSION 3.10) project(extractor_test) set (SOURCES test.cpp CornersTest.cpp DeskewerTest.cpp ExtractorTest.cpp ScanStateTest.cpp ScannerTest.cpp SimpleCameraCalibrationTest.cpp UndistortTest.cpp ) include_directories( ${libcimbar_SOURCE_DIR}/test ${libcimbar_SOURCE_DIR}/test/lib ${CMAKE_CURRENT_SOURCE_DIR}/.. ) add_executable ( extractor_test ${SOURCES} ) add_test(extractor_test extractor_test) target_link_libraries(extractor_test extractor ${OPENCV_LIBS} ${CPPFILESYSTEM} ) ``` -------------------------------- ### Android App Gradle Build Configuration with NDK Source: https://context7.com/sz3/cfc/llms.txt Configures the Android application's build process, including compilation SDK, build tools, NDK version, default configuration, build types, and external native builds. It specifies C++ flags, ABI filters, and points to the OpenCV SDK. Dependencies include AppCompat, ConstraintLayout, and a local OpenCV project. ```gradle apply plugin: 'com.android.application' android { compileSdkVersion 34 buildToolsVersion "30.0.3" ndkVersion "25.2.9519653" defaultConfig { applicationId "org.cimbar.camerafilecopy" minSdkVersion 21 // Android 5.0+ targetSdkVersion 35 // Android 15 versionCode 21 versionName "0.6.3" // ARM64 only for performance ndk { abiFilters "arm64-v8a" } externalNativeBuild { cmake { cppFlags "-frtti -fexceptions -std=c++17" abiFilters 'arm64-v8a' // Point to OpenCV SDK (set in gradle.properties) arguments "-DOpenCV_DIR=" + opencvsdk + "/sdk/native" } } setProperty("archivesBaseName", "CameraFileCopy") } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } externalNativeBuild { cmake { path "src/cpp/CMakeLists.txt" version "3.16.3+" } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation project(path: ':opencv') } ``` -------------------------------- ### Configure Reed-Solomon Test Runner (CMake) Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/libcorrect/tests/CMakeLists.txt Defines a CMake executable for the Reed-Solomon test runner. It links against 'correct_static' and 'LIBM', specifies the runtime output directory, and registers the test. ```cmake add_executable(reed_solomon_test_runner EXCLUDE_FROM_ALL reed-solomon.c rs_tester.c) target_link_libraries(reed_solomon_test_runner correct_static "${LIBM}") set_target_properties(reed_solomon_test_runner PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests") add_test(NAME reed_solomon_test WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests" COMMAND reed_solomon_test_runner) set(all_test_runners ${all_test_runners} reed_solomon_test_runner) ``` -------------------------------- ### Configure Reed-Solomon Shim Interop Test Runner (CMake) Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/libcorrect/tests/CMakeLists.txt Defines a CMake executable for an interoperability test runner between Reed-Solomon and its shim. It links against 'correct_static', 'fec_shim_static', and 'LIBM', sets the runtime output directory, and registers the test. ```cmake add_executable(reed_solomon_shim_interop_test_runner EXCLUDE_FROM_ALL reed-solomon-shim-interop.c rs_tester.c rs_tester_fec_shim.c) target_link_libraries(reed_solomon_shim_interop_test_runner correct_static fec_shim_static "${LIBM}") set_target_properties(reed_solomon_shim_interop_test_runner PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests") add_test(NAME reed_solomon_shim_interop_test WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests" COMMAND reed_solomon_shim_interop_test_runner) set(all_test_runners ${all_test_runners} reed_solomon_shim_interop_test_runner) ``` -------------------------------- ### Unit Test Source Files Definition (CMake) Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/wirehair/CMakeLists.txt Lists the source files required for compiling the unit tests for the Wirehair library. These files include test utilities and the main test runner. ```cmake set(UNIT_TEST_SOURCE_FILES test/SiameseTools.cpp test/SiameseTools.h test/UnitTest.cpp ) ``` -------------------------------- ### Basic CSS Reset and Fullscreen Layout Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/web/index.html This CSS snippet sets basic margin and padding to zero for all elements and ensures the html and body elements take up the full viewport height. It also defines a white background with complex linear gradients for the body, center-aligns content, and applies a transition for opacity changes. ```css /* margin: 0; padding: 0; */ html, body { height: 100vh; } body { background-color: white; background-image: linear-gradient(135deg, rgb(0, 0, 0) 65px, transparent 130px), repeating-linear-gradient(135deg, rgb(0, 0, 0) 0px, rgb(153, 197, 206) 1px, transparent 1px, transparent 30px), repeating-linear-gradient(45deg, rgb(0, 0, 0) 0px, rgb(153, 197, 206) 1px, transparent 1px, transparent 30px); background-size: cover; color: gray; display: grid; align-items: center; transition: opacity 0.4s ease-in; } ``` -------------------------------- ### Wirehair Library Definition (CMake) Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/wirehair/CMakeLists.txt Defines the main Wirehair library using a list of source files and sets versioning information. It also configures public include directories. ```cmake cmake_minimum_required(VERSION 3.5) project(wirehair) set(CMAKE_CXX_STANDARD 11) set(LIB_SOURCE_FILES wirehair.cpp include/wirehair/wirehair.h gf256.cpp gf256.h WirehairCodec.cpp WirehairCodec.h WirehairTools.cpp WirehairTools.h ) add_library(wirehair ${LIB_SOURCE_FILES}) set_target_properties(wirehair PROPERTIES VERSION 2) set_target_properties(wirehair PROPERTIES SOVERSION 2) target_include_directories(wirehair PUBLIC ${PROJECT_SOURCE_DIR}/include) include(GNUInstallDirs) ``` -------------------------------- ### CMake Project Configuration Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/lib/cimb_translator/test/CMakeLists.txt Configures the CMake build for the cimb_translator_test project. It sets the minimum required CMake version, project name, and defines the executable target along with its source files and dependencies. ```cmake cmake_minimum_required(VERSION 3.10) project(cimb_translator_test) set (SOURCES test.cpp AdjacentCellFinderTest.cpp CellTest.cpp CellDriftTest.cpp CellPositionsTest.cpp CimbDecoderTest.cpp CimbEncoderTest.cpp CimbReaderTest.cpp CimbWriterTest.cpp FloodDecodePositionsTest.cpp InterleaveTest.cpp LinearDecodePositionsTest.cpp ) include_directories( ${libcimbar_SOURCE_DIR}/test ${libcimbar_SOURCE_DIR}/test/lib ${CMAKE_CURRENT_SOURCE_DIR}/.. ) add_executable ( cimb_translator_test ${SOURCES} ) add_test(cimb_translator_test cimb_translator_test) target_link_libraries(cimb_translator_test cimb_translator ${OPENCV_LIBS} ) ``` -------------------------------- ### Android Main Layout XML with Camera View and Toggle Source: https://context7.com/sz3/cfc/llms.txt Defines the main user interface layout for the Android application using ConstraintLayout. It includes a full-screen camera preview implemented by `OpencvCameraView` and a mode selector toggle button (`ModeSelToggle`) positioned in the bottom-right corner. ```xml ``` -------------------------------- ### Build Zstd Compression Library Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/zstd/compress/CMakeLists.txt Configures the build process for the zstd compression library by defining a list of source files. This CMake command creates an object library named 'zstd-compress' from the specified C and header files. ```cmake set(SRCFILES clevels.h huf_compress.c zstd_compress_sequences.c zstd_double_fast.c zstd_lazy.h zstdmt_compress.h zstd_compress.c zstd_compress_sequences.h zstd_double_fast.h zstd_ldm.c zstd_opt.c fse_compress.c zstd_compress_internal.h zstd_compress_superblock.c zstd_fast.c zstd_ldm_geartab.h zstd_opt.h hist.c zstd_compress_literals.c zstd_compress_superblock.h zstd_fast.h zstd_ldm.h hist.h zstd_compress_literals.h zstd_cwksp.h zstd_lazy.c zstdmt_compress.c) add_library(zstd-compress OBJECT ${SRCFILES}) ``` -------------------------------- ### Configure Convolutional Shim Test Runner (CMake) Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/libcorrect/tests/CMakeLists.txt Defines a CMake executable for a convolutional shim test runner. It links against 'correct_static', 'fec_shim_static', and 'LIBM', sets the runtime output directory, and registers the test. ```cmake add_executable(convolutional_shim_test_runner EXCLUDE_FROM_ALL convolutional-shim.c $) target_link_libraries(convolutional_shim_test_runner correct_static fec_shim_static "${LIBM}") set_target_properties(convolutional_shim_test_runner PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests") add_test(NAME convolutional_shim_test WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests" COMMAND convolutional_shim_test_runner) set(all_test_runners ${all_test_runners} convolutional_shim_test_runner) ``` -------------------------------- ### Table Generation Source Files (CMake) Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/wirehair/CMakeLists.txt Defines sets of source files used for generating various lookup tables required by the Wirehair library. Each set targets a specific type of table generation. ```cmake set(GEN_SMALL_DSEEDS test/SiameseTools.cpp test/SiameseTools.h tables/GenerateSmallDenseSeeds.cpp ) set(GEN_PEEL_SEEDS test/SiameseTools.cpp test/SiameseTools.h tables/GeneratePeelSeeds.cpp ) set(GEN_MOST_DSEEDS test/SiameseTools.cpp test/SiameseTools.h tables/GenerateMostDenseSeeds.cpp ) set(GEN_DCOUNTS test/SiameseTools.cpp test/SiameseTools.h tables/GenerateDenseCount.cpp ) set(GEN_TABLES test/SiameseTools.cpp test/SiameseTools.h tables/TableGenerator.cpp tables/HeavyRowGenerator.cpp tables/HeavyRowGenerator.h gf256.cpp gf256.h ) ``` -------------------------------- ### Define Executable: rs_find_primitive_poly (CMake) Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/libcorrect/tools/CMakeLists.txt Defines the 'rs_find_primitive_poly' executable, linking it against the 'correct_static' library. This is a standard build target within the project. ```cmake add_executable(rs_find_primitive_poly EXCLUDE_FROM_ALL find_rs_primitive_poly.c) target_link_libraries(rs_find_primitive_poly correct_static) set(all_tools ${all_tools} rs_find_primitive_poly) ``` -------------------------------- ### JavaScript for Service Worker and Video Initialization Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/web/recv.html Initializes the service worker for the application and sets up the video element. It registers a service worker located at './recv-sw.js' and waits for the WebAssembly module to be ready before initializing the video. ```javascript Recv.init_ww(2); if ('serviceWorker' in navigator) { navigator.serviceWorker.register('./recv-sw.js'); } var video = document.querySelector('#video'); var Module = {}; Module.onRuntimeInitialized = () => { Recv.init_video(video); }; ``` -------------------------------- ### CMake Subdirectory Inclusion Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/CMakeLists.txt Defines a list of projects and their corresponding subdirectories. It then includes each of these subdirectories into the build process, allowing for modular project structuring. ```cmake set (PROJECTS src/lib/bit_file src/lib/chromatic_adaptation src/lib/cimb_translator src/lib/cimbar_js src/lib/compression src/lib/encoder src/lib/extractor src/lib/fountain src/lib/gui src/lib/image_hash src/lib/serialize src/lib/util src/third_party_lib/base91 src/third_party_lib/cxxopts src/third_party_lib/intx src/third_party_lib/libcorrect src/third_party_lib/libpopcnt src/third_party_lib/wirehair src/third_party_lib/zstd ) include_directories( ${libcimbar_SOURCE_DIR}/src/lib ${libcimbar_SOURCE_DIR}/src/third_party_lib ) foreach(proj ${PROJECTS}) add_subdirectory(${proj} build/${proj}) endforeach() ``` -------------------------------- ### Define Executable: conv_find_libfec_poly (CMake) Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/libcorrect/tools/CMakeLists.txt Conditionally defines the 'conv_find_libfec_poly' executable if HAVE_LIBFEC is enabled. It links against 'correct_static' and 'fec'. ```cmake if(HAVE_LIBFEC) add_executable(conv_find_libfec_poly EXCLUDE_FROM_ALL find_conv_libfec_poly.c) target_link_libraries(conv_find_libfec_poly correct_static fec) set(all_tools ${all_tools} conv_find_libfec_poly) endif() ``` -------------------------------- ### Define Executable: conv_find_optim_poly_annealing (CMake) Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/libcorrect/tools/CMakeLists.txt Conditionally defines the 'conv_find_optim_poly_annealing' executable based on the HAVE_SSE flag. It links against 'correct_static' and either SSE-optimized objects or standard objects. ```cmake if(HAVE_SSE) add_executable(conv_find_optim_poly_annealing EXCLUDE_FROM_ALL find_conv_optim_poly_annealing.c $) target_link_libraries(conv_find_optim_poly_annealing correct_static) set(all_tools ${all_tools} conv_find_optim_poly_annealing) else() add_executable(conv_find_optim_poly_annealing EXCLUDE_FROM_ALL find_conv_optim_poly_annealing.c $) target_link_libraries(conv_find_optim_poly_annealing correct_static) set(all_tools ${all_tools} conv_find_optim_poly_annealing) endif() ``` -------------------------------- ### Define Executable: conv_find_optim_poly (CMake) Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/libcorrect/tools/CMakeLists.txt Conditionally defines the 'conv_find_optim_poly' executable based on the HAVE_SSE flag. It links against 'correct_static' and either SSE-optimized objects or standard objects. ```cmake if(HAVE_SSE) add_executable(conv_find_optim_poly EXCLUDE_FROM_ALL find_conv_optim_poly.c $) target_link_libraries(conv_find_optim_poly correct_static) set(all_tools ${all_tools} conv_find_optim_poly) else() add_executable(conv_find_optim_poly EXCLUDE_FROM_ALL find_conv_optim_poly.c $) target_link_libraries(conv_find_optim_poly correct_static) set(all_tools ${all_tools} conv_find_optim_poly) endif() ``` -------------------------------- ### Page Layout and Background Styling (CSS) Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/web/recv.html Sets up the full-page viewport height and applies a complex, animated gradient background to the body. It also includes a media query to adjust background and text color for dark mode preferences. ```css html, body { height: 100vh; } body { background-color: white; background-image: linear-gradient(135deg, rgb(0, 0, 0) 65px, transparent 130px), repeating-linear-gradient(135deg, rgb(0, 0, 0) 0px, rgb(153, 197, 206) 1px, transparent 1px, transparent 30px), repeating-linear-gradient(45deg, rgb(0, 0, 0) 0px, rgb(153, 197, 206) 1px, transparent 1px, transparent 30px); background-size: cover; } @media (prefers-color-scheme: dark) { body { background-color: black; color: white; } } ``` -------------------------------- ### CSS Styling for Navigation and Debug Menus Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/web/recv.html Provides CSS rules for styling the navigation menu (#nav-content) and a debug menu (#debug_menu). It includes transitions, animations, and responsive adjustments for different screen elements. This CSS is essential for the project's user interface. ```css #nav-content ul { height: calc(100% - 60px); display: flex; flex-direction: column; list-style: none; } #nav-content hr { border: 1px solid #444; } #nav-content li a { display: block; padding: 10px 5px; color: #9fa6b2; text-decoration: none; transition: color .1s; } #nav-content li a.attention { animation: glowing 1.5s infinite alternate; } #nav-content li a { font-variant: small-caps; font-size: 2em; } #nav-content h4 { color: gray; font-variant: small-caps; padding-top: 1em; } #nav-content li.modesel a { display: inline-block; width: 2em; } #nav-content li:hover { background-color: #2c323c; } #nav-content li:not(.small)+.small { margin-top: auto; } #nav-content li.small { display: flex; align-self: center; } #nav-content li.small a { font-size: 1em; } #nav-container:focus-within #nav-content, #debug_menu:focus-within { transform: none; } #debug_menu { transform: translateX(100%); margin-top: 60px; right: 0; padding: 20px; position: absolute; top: 0; max-width: 95%; z-index: 2; transition: transform .3s; opacity: 95%; background-color: black; } .invisible { display: none; } @keyframes glowing { 0% { color: #00ffff; } } ``` -------------------------------- ### Process Camera Frame with JNI - C++ Source: https://context7.com/sz3/cfc/llms.txt The core JNI method `processImageJNI` in C++ processes camera frames. It initializes or reuses a `MultiThreadedDecoder`, clones the input frame, adds it to the decoder's thread pool, draws visual feedback, and returns the completed file path or a mode detection string. ```cpp // app/src/cpp/cfc-cpp/jni.cpp extern "C" { jstring JNICALL Java_org_cimbar_camerafilecopy_MainActivity_processImageJNI( JNIEnv *env, jobject instance, jlong matAddr, jstring dataPathObj, jint modeInt) { // Get OpenCV Mat from native address Mat &mat = *(Mat *) matAddr; string dataPath = jstring_to_cppstr(env, dataPathObj); int modeVal = (int)modeInt; // Initialize or reuse decoder with thread safety std::shared_ptr proc; { std::lock_guard lock(_mutex); if (!_proc or !_proc->set_mode(modeVal)) _proc = std::make_shared(dataPath, modeVal); proc = _proc; } // Clone frame and submit to thread pool cv::Mat img = mat.clone(); proc->add(img); // Draw visual feedback on preview frame drawProgress(mat, proc->get_progress()); drawGuidance(mat, _transferStatus); // Return completed file path for user save prompt string result; if (proc->detected_mode()) result = fmt::format("/modern{}", proc->detected_mode()); std::vector all_decodes = proc->get_done(); for (string& s : all_decodes) if (_completed.find(s) == _completed.end()) { _completed.insert(s); result = s; // Filename to save } return env->NewStringUTF(result.c_str()); } } ``` -------------------------------- ### Handle File Save Location and Copy File - Java Source: https://context7.com/sz3/cfc/llms.txt This Java code handles the result of a file save location picker, copying a temporary file to the user-selected destination. It uses input and output streams for efficient file transfer and includes cleanup for the temporary file. Dependencies include standard Java IO and Android Intent handling. ```java // app/src/main/java/org/cimbar/camerafilecopy/MainActivity.java @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { if (resultCode == RESULT_OK && requestCode == CREATE_FILE) { if (this.activePath == null) return; // Copy temporary file to user-specified location try (InputStream istream = new FileInputStream(this.activePath); OutputStream ostream = getContentResolver().openOutputStream(data.getData())) { byte[] buf = new byte[8192]; int length; while ((length = istream.read(buf)) > 0) { ostream.write(buf, 0, length); } ostream.flush(); } catch (Exception e) { Log.e(TAG, "failed to write file " + e.toString()); } finally { // Clean up temporary file try { new File(this.activePath).delete(); } catch (Exception e) {} this.activePath = null; } } } ``` -------------------------------- ### Define Custom Target: tools (CMake) Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/libcorrect/tools/CMakeLists.txt Defines a custom target named 'tools' that depends on all executables listed in the 'all_tools' variable. This allows building all defined tools together. ```cmake add_custom_target(tools DEPENDS ${all_tools}) ``` -------------------------------- ### Create Test Runner Aggregation and Check Targets (CMake) Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/libcorrect/tests/CMakeLists.txt Creates CMake custom targets. 'test_runners' depends on all individual test runner executables, ensuring they are built. 'check' depends on 'test_runners' and uses CTest to run all registered tests. ```cmake add_custom_target(test_runners DEPENDS ${all_test_runners}) add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS test_runners) enable_testing() ``` -------------------------------- ### Check FEC Library Existence Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/libcorrect/CMakeLists.txt Checks if the 'fec' library is available on the system. It uses CMake's built-in module `CheckLibraryExists` and `CheckIncludeFiles` for this purpose. The result is stored in the `HAVE_LIBFEC` variable. ```cmake find_library(FEC fec) CHECK_LIBRARY_EXISTS(FEC dotprod "" HAVE_LIBFEC) ``` -------------------------------- ### Navigation Bar and Button CSS Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/web/index.html This CSS code styles the navigation button and its associated icon bars, as well as the navigation content panel. It includes styles for hover effects, focus states, and transitions to create a dynamic user interface. The styles are designed to work with a container that toggles the navigation's visibility and transforms its elements. ```css #nav-button { position: relative; display: flex; flex-direction: column; justify-content: center; height: 60px; width: 30px; margin-left: 15px; cursor: pointer; pointer-events: auto; touch-action: manipulation; border: 0; outline: 0; background-image: linear-gradient(180deg, rgb(0, 0, 0, 0) 10%, rgb(0, 0, 0) 40%, rgb(0, 0, 0) 60%, rgb(0, 0, 0, 0) 90%); background-color: initial; } #nav-button.hide { opacity: 0; transition: .3s; } #nav-container:focus-within #nav-button.hide { opacity: 1; } .icon-bar { display: block; width: 100%; height: 3px; transition: .3s; } .icon-bar+.icon-bar { margin-top: 3px; } #nav-container .icon-bar:nth-of-type(1) { background-color: #00ff00; box-shadow: 0px 0px 5px #00ff00, 0px 0px 2px #00ff00; } #nav-container .icon-bar:nth-of-type(2) { background-color: #ffff00; box-shadow: 0px 0px 5px #ffff00, 0px 0px 2px #ffff00; } #nav-container .icon-bar:nth-of-type(3) { background-color: #00ffff; box-shadow: 0px 0px 5px #00ffff, 0px 0px 2px #00ffff; } #nav-container .icon-bar:nth-of-type(4) { background-color: #ff00ff; box-shadow: 0px 0px 5px #ff00ff, 0px 0px 2px #ff00ff; } #nav-container.mode-4c .icon-bar:nth-of-type(1) { background-color: #00ffff; box-shadow: 0px 0px 5px #00ffff, 0px 0px 2px #00ffff; } #nav-container.mode-4c .icon-bar:nth-of-type(2) { background-color: #ffff00; box-shadow: 0px 0px 5px #ffff00, 0px 0px 2px #ffff00; } #nav-container.mode-4c .icon-bar:nth-of-type(3) { background-color: #00ff00; box-shadow: 0px 0px 5px #00ff00, 0px 0px 2px #00ff00; } #nav-container.mode-4c .icon-bar:nth-of-type(4) { background-color: #ff00ff; box-shadow: 0px 0px 5px #ff00ff, 0px 0px 2px #ff00ff; } #nav-container:focus-within #nav-button { pointer-events: none; } #nav-container:focus-within .icon-bar { background-color: #aaa; background-image: none !important; box-shadow: none !important; } #nav-button.attention:focus-within .icon-bar { background-color: #00ffff; } #nav-container:focus-within .icon-bar:nth-of-type(1) { transform: translate3d(0, 9px, 0) rotate(45deg); } #nav-container:focus-within .icon-bar:nth-of-type(2), #nav-container:focus-within .icon-bar:nth-of-type(3) { opacity: 0; } #nav-container:focus-within .icon-bar:nth-of-type(4) { transform: translate3d(0, -9px, 0) rotate(-45deg); } #nav-content { margin-top: 60px; padding: 20px; position: absolute; top: 0; left: 0; height: calc(100% - 60px); overflow-x: clip; background-color: #282C34; text-align: center; pointer-events: auto; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); transform: translateX(-100%); transition: transform .3s; } #nav-content ul { height: calc(100% - 60px); display: flex; flex-direction: column; list-style: none; } #nav-content hr { border: 1px solid #444; } #nav-content li a { display: block; padding: 10px 5px; color: #9fa6b2; text-decoration: none; transition: color .1s; } #nav-content li a.attention { animation: glowing 1.5s infinite alternate; } #nav-content li a { font-variant: small-caps; font-size: 2em; } #nav-content h4 { font-variant: small-caps; padding-top: 1em; } #nav-content li.modesel a { display: inline-block; width: 2em; } #nav-content li:hover { background-color: #2c323c; } #nav-content li:not(.small)+.small { margin-top: auto; } #nav-content li.small { display: flex; align-self: center; } #nav-content li.small a { font-size: 1em; } #nav-container:focus-within #nav-content { transform: none; } @keyframes glowing { 0% { color: #00ffff; } } ``` -------------------------------- ### Configure Convolutional Code Test Runner (CMake) Source: https://github.com/sz3/cfc/blob/master/app/src/cpp/libcimbar/src/third_party_lib/libcorrect/tests/CMakeLists.txt Defines a CMake executable for the convolutional code test runner. It links against 'correct_static' and 'LIBM' libraries and sets the runtime output directory to the test build folder. This runner is automatically registered as a CMake test. ```cmake add_executable(convolutional_test_runner EXCLUDE_FROM_ALL convolutional.c $) target_link_libraries(convolutional_test_runner correct_static "${LIBM}") set_target_properties(convolutional_test_runner PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests") add_test(NAME convolutional_test WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/tests" COMMAND convolutional_test_runner) set(all_test_runners ${all_test_runners} convolutional_test_runner) ```