Skip to content

Instantly share code, notes, and snippets.

pabloko / wicimagedecoder.hpp
Created Feb 22, 2022
Image Decoder based on WIC
View wicimagedecoder.hpp
* 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("");
pabloko / ArtNet.cs
Last active Sep 1, 2021
[C#] Very simple Art-Net DMX sender-only class
View ArtNet.cs
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace ArtNetDmx
class ArtNet
//Udp socket object to make requests
pabloko / 0000-ffmpeg 4.4 with NDI support (updated SDK, fixed timestamps errors).md
Last active Mar 18, 2022
ffmpeg 4.4 with NDI support (updated SDK, fixed timestamps errors)
View 0000-ffmpeg 4.4 with NDI support (updated SDK, fixed timestamps errors).md

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.


  • Updated libndi methods by newer versions (v2/v3)
  • Calculating PTS/DTS from timestamp instead of timecode, that is optionally sent by the sender.
pabloko / usbhid.cpp
Created Apr 28, 2021
Lua 5.1 / luajit - Usb HID library (hidapi) [win/mac/linux]
View usbhid.cpp
//using hidapi library: 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 / serial.cpp
Created Apr 27, 2021
Lua 5.1 / luajit - Serial port library (rs232) [win/mac/linux]
View serial.cpp
//Using rs232 library: 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)
pabloko /
Last active Apr 24, 2022
D3D9 Overlay with IE and alpha

D3D9 Overlay with IE and alpha

Many times working with Direct3D9, you want to build a simple GUI to overlay over your graphics, many libraries does this in some way but at some point you may want to use a web browser and options are much more limited. CEF is great, but heavy and IPC can be a real pain to handle, ultralight stopped supporting x86 arch... few other webui libs out there, they all have its pros and cons but we lost the sense of simplicity we wanted on first hand.

Then theres MSHTML (Internet Explorer) that is shipped on every windows os, enough versatile and fast to be used as overlay. Shamefully for Microsoft, this control never supported transparent background, even on .net webforms/WPF webbrowser depends from MSHTML and always cast a background.

This demo explores two ways to overcome this long standing issue and get 1bit alpha or 255bit alpha by color difference interpolation.

  • 1bit alpha: Uses green rgb(0,255,0) background that is simply keyed, can be used on boxed UI with less re
pabloko /
Last active May 16, 2020
(C) ChooseFont color picker with extended color dialog

The ChooseFont dialog color picker extended

Using ChooseFont you will notice it only support 15 predefined an ugly colors. The color palette is very limited and theres no way to use more colors without subclassing it. Here is a good start point to subclass it, this mod will:

  • Display the color in HTML format
  • Display a full featured ChooseColor dialog when color ComboBox is clicked

pabloko / functions.php
Created Apr 20, 2020
[PHP/Wordpress] Define a default post password with filters and hooks
View functions.php
add_filter( 'post_password_required', function( $returned, $post )
//Define here your conditional logic, example filter posts without password from custom post type "photo_gallery"
if (empty($post->post_password) && $post->post_type=="photo_galery")
//End of conditional logic. Returning true will ask for password, false will display the content.
require_once ABSPATH . WPINC . '/class-phpass.php';
$hasher = new PasswordHash( 8, true );
pabloko /
Created Mar 18, 2020
(C/C++) Embed file assets into binaries automaticly with VisualStudio build tasks

(C/C++) Embed file assets into binaries automaticly with VisualStudio build tasks

Sometimes developing apps, we need to reduce the build to a single exe containing handful of asset files, in this scenario, you can use the great library PhysFS that will let you zip everithing and load those files on runtime. We can further automatize this process by adding a VisualStudio Pre-build event that zips a custom folder, but also packs it on the final executable.

To start, locate your project folder and add a www asset directory and vendor directory, where we will put neccessary files 7z.exe, 7z.dll, objcopy.exe, www.bat 7zip will pack the files on a generated "" this can be edited or even removed, it may even include the usage of zip password as PhysFS supports it. Objcopy, its part of some VS distributions and generated a .lib static library with the asset, exporting its start and end address.

Pre-build event: call "$(MSBuildProjectDirectory)\vendor\www.bat"

/vendor/www.bat (notice you w

pabloko / 01.(PHP) Pre-processing MP3 Audio waveforms with big
Created Dec 14, 2019
(PHP) Pre-processing MP3 Audio waveforms with big size
View 01.(PHP) Pre-processing MP3 Audio waveforms with big


When want to display audio waveform from audio file, you can find browser libraries like WavesurferJs, Squiggl, or whatever, everyone works the same:

  1. Load audio (in full) file and get its AudioContext
  2. Get all the raw PCM samples from one channel in Float32Array (huge) with something like ctx.decodeAudioData().getChannelData(0)
  3. Use drawing routine and average samples

Doing this process on the users browser is quite slow and wasteful in a magnitude proportional to the audio file size, as you have to fully load it then get huge amount of samples calculated in the drawing stage.

So one option to overcome this is to dump a shorter version of PCM data on a static file with an amount of samples enough to render the waveform and having a reasonable size by averaging the samples.