Skip to content

Instantly share code, notes, and snippets.

View tralamazza's full-sized avatar

Daniel Tralamazza tralamazza

View GitHub Profile
// color1 and color2 are R4G4B4 12bit RGB color values, alpha is 0-255
uint16_t blend_12bit( uint16_t color1, uint16_t color2, uint8_t alpha ) {
uint64_t c1 = (uint64_t) color1;
uint64_t c2 = (uint64_t) color2;
uint64_t a = (uint64_t)( alpha >> 4 );
// bit magic to alpha blend R G B with single mul
c1 = ( c1 | ( c1 << 12 ) ) & 0x0f0f0f;
c2 = ( c2 | ( c2 << 12 ) ) & 0x0f0f0f;
uint32_t o = ( ( ( ( c2 - c1 ) * a ) >> 4 ) + c1 ) & 0x0f0f0f;
@tralamazza
tralamazza / sml.rs
Created October 3, 2023 10:06 — forked from kris-jusiak/sml.rs
//
// Copyright (c) 2022 Kris Jusiak (kris at jusiak dot net)
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
//
// Usage
// #![feature(specialization)]
// #![allow(incomplete_features)]
@tralamazza
tralamazza / cdc.rb
Last active December 23, 2015 18:29 — forked from corecode/cdc.rb
class CDCDesc < FunctionDesc
TypeName = "struct cdc_function_desc"
FunctionVarName = "cdc_function"
child_block :cdc
def initialize
super()
@ctrl_iface = interface(:ctrl_iface) {