Skip to content

Instantly share code, notes, and snippets.

/**
* Windows Keyed Mutex Library
* @pabloko - [email protected] - 23/01/2024
* This file is a C / C++ wrapper for windows keyed mutex / events / condition variables.
**/
#include <D3dkmthk.h>
#include <windows.h>
#ifdef __cplusplus
@pabloko
pabloko / PoWCaptcha.md
Created December 25, 2024 00:20
PoWCaptcha - Proof of work captchas

PoWCaptcha - Proof of Work CAPTCHA

PoWCaptcha is a simple, transparent CAPTCHA system based on Proof of Work (PoW) that aims to stop bots with minimal user interaction. It leverages the same principles as cryptocurrencies and blockchain to validate human users without requiring image recognition or complex puzzles.

Why PoWCaptcha?

Captchas are getting less effective. OCR tools, AI, and captcha solving services are quicker than humans and cheap. At the same time, exposing a contact form without protection invites spam and bot traffic. PoWCaptcha offers a minimal wall to deter lazy bots—making the verification process computationally expensive for bots but invisible to humans.

Instead of bothering the user with complex tasks, PoWCaptcha shifts the burden to the computer, performing backend calculations involving:

  • User data
@pabloko
pabloko / Edge WebView2 on D3D11.md
Last active January 24, 2025 16:56
Rendering offscreen Edge (WebView2) to D3D11 texture for overlays (C++/win32)

Using Edge WebView2 is really straightforward, but using the Composition controller is poorly documented and only discussed on few issues in the WebView2 repo.

The browser itself is rendered on a separate process using DirectComposition API wich does not directly interoperate with DirectX, but can be readed using GraphicsCaptureItem WinRT apis. This means that a capture session must be setup into the host visual root, and it will provide accelerated GPU texture capture of the browser (with transparency)

There are few extra steps to setup this pipeline under win32 apps, apart of usual WebView2 setup:

  1. A DispatcherQueueController need to be created in the hosting thread in order to be able to use the Visual interfaces
  2. Use CreateCoreWebView2CompositionController instead CreateCoreWebView2Controller or its WithConfig equivalent.
  3. Create a WinRT DirectComposition IContainerVisual and IVisual as in the example
  4. Create a WinRT Direct3D11CaptureFramePool and start the session using `GraphicsC
@pabloko
pabloko / Angle on windows SDK.md
Last active July 28, 2024 23:40
There is a hidden distribution of ANGLE in windows that (now) you can use

There is an ANGLE driver in every windows 8-11 included in the system32 named edgeangle.dll that seems to be part of the former edge 11 (spartan) that briefly existed in windows (and still exists as in edgehtml.dll and will take a future post)

This distribution reports ANGLE version OpenGL ES 3.0 (ANGLE 2.1.0.d0cdd066eca2) and it seems only D3D11 backend is available. It reports the next extensions:

GL_ANGLE_client_arrays GL_ANGLE_depth_texture GL_ANGLE_framebuffer_blit GL_ANGLE_framebuffer_multisample GL_ANGLE_instanced_arrays GL_ANGLE_lossy_etc_decode GL_ANGLE_multiview GL_ANGLE_pack_reverse_row_order GL_ANGLE_program_cache_control GL_ANGLE_request_extension GL_ANGLE_robust_client_memory GL_ANGLE_texture_compression_dxt3 GL_ANGLE_texture_compression_dxt5 GL_ANGLE_texture_usage GL_ANGLE_translated_shader_source GL_CHROMIUM_bind_generates_resource GL_CHROMIUM_bind_uniform_location GL_CHROMIUM_color_buffer_float_rgb GL_CHROMIUM_color_buffer_float_rgba GL_CHROMIUM_copy_compressed_texture GL_CHROMIUM_c
@pabloko
pabloko / 1.Query information from NT Handles of shared D3D11 Textures.md
Last active May 11, 2023 11:28
Query information from NT Handles of shared D3D11 Textures

Query information from NT Handles of shared D3D11 Textures

tl;dr: you can't. Only D3D12 and Vulkan resources expose API to query it's physical size

Looking into using the gl extension EXT_external_objects_win32 stumbled upon this <size> parameter in glImportMemoryWin32HandleEXT when using a D3D11 resources

tl;dr: Use 0 as size when using HANDLE_TYPE_D3D11_IMAGE_EXT / HANDLE_TYPE_D3D11_IMAGE_KMT_EXT

the driver implmentation will figure out the internal size of the resource. This size would be alignedWidth * alignedHeight * Bpp where alignment varies depending of the graphics card vendor, model and driver version.

To give some context, here are some values from my NV card with updated drivers

@pabloko
pabloko / wicimagedecoder.hpp
Created February 22, 2022 08:39
Image Decoder based on WIC
/*
* Image decoder based on WIC
* ------------------------------------------------
* Provides synchronous loading of images and copy
* frames in ARGB format.
*
* Example of loading images:
* ImageDecoder::Init();
* ImageDecoder* img = ImageDecoder::FromFile("C:\\path\\to\\image.png");
* ImageDecoder* img = ImageDecoder::FromURL("http://example.com/img.jpg");
@pabloko
pabloko / ArtNet.cs
Last active September 1, 2021 01:15
[C#] Very simple Art-Net DMX sender-only class
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace ArtNetDmx
{
class ArtNet
{
//Udp socket object to make requests
@pabloko
pabloko / 0000-ffmpeg 4.4 with NDI support (updated SDK, fixed timestamps errors).md
Last active February 2, 2024 18:11
ffmpeg 4.4 with NDI support (updated SDK, fixed timestamps errors)

update: https://framagit.org/tytan652/ffmpeg-ndi-patch use this patch. this gist is outdated

ffmpeg 4.4 with NDI

This patch adds libndi_newtek to last ffmpeg version, and fix timecode related issues that produces wrong PTS/DTS timestamps that seems to happen with newer NDI SDKs.

changes

  • Updated libndi methods by newer versions (v2/v3)
@pabloko
pabloko / usbhid.cpp
Created April 28, 2021 16:22
Lua 5.1 / luajit - Usb HID library (hidapi) [win/mac/linux]
//using hidapi library: https://github.com/signal11/hidapi/ by Alan Ott
#include <stdio.h>
#include <malloc.h>
#include "hidapi.h"
#pragma comment(lib, "setupapi.lib")
#pragma comment(lib, "hidapi.lib")
#include <Windows.h>
#include <lua.hpp>
#pragma comment(lib, "lua5.1.lib")
unsigned char buffer[0xFFF] = { 0 };
@pabloko
pabloko / serial.cpp
Created April 27, 2021 19:09
Lua 5.1 / luajit - Serial port library (rs232) [win/mac/linux]
//Using rs232 library: https://github.com/mrh1997/rs232/ by Frédéric Meslin, Florent Touchard
#include <Windows.h>
#pragma comment(lib, "kernel32")
#pragma comment(lib, "lua5.1.lib")
#include <lua.hpp>
#include "rs232.h"
char buffer[0xFFF] = { 0 };
BOOL luaopen_serial (lua_State* L)
{