initial commit

This commit is contained in:
Ondrej Jamriska
2021-12-03 02:17:55 +01:00
commit 5775c6fa68
3 changed files with 80588 additions and 0 deletions

60
README.md Normal file
View File

@@ -0,0 +1,60 @@
# Mixbox: Practical Pigment Mixing for Digital Painting
<p align="center">
<img src="https://scrtwpns.com/mixbox/teaser.jpg"/>
</p>
Mixbox is a pigment mixing black-box. You pass RGB colors in and get the mixed RGB out.
Internally, Mixbox treats the colors as if they were made of actual real-world pigments.
It uses the Kubelka & Munk theory to predict the color of the resulting mixture.
This way, Mixbox achieves that blue and yellow mix to green, the same way real pigments do.
* Paper: https://scrtwpns.com/mixbox.pdf<br>
* Video: https://youtu.be/9egCAxhOHg4<br>
* Talk: https://youtu.be/k91cDhpCOpg<br>
## Usage
The simplest way to use Mixbox is with the *lerp* interface:
```c++
#include <stdio.h>
#include "mixbox.h"
int main()
{
unsigned char r1=252, g1=211, b1=0; // bright yellow
unsigned char r2=0, g2=0, b2=96; // deep blue
float t = 0.5;
unsigned char r,g,b;
mixbox_lerp_srgb8(r1,g1,b1, // first color
r2,g2,b2, // second color
t, // mixing ratio
&r,&g,&b); // result
printf("%d %d %d\n",r,g,b);
}
```
Alternatively, one can use the *latent* interface. This allows mixing multiple RGB colors at once using arbitrary weights:
```c++
float latent1[MIXBOX_NUMLATENTS];
float latent2[MIXBOX_NUMLATENTS];
float latentMix[MIXBOX_NUMLATENTS];
mixbox_srgb8_to_latent(r1,g1,b1,latent1);
mixbox_srgb8_to_latent(r2,g2,b2,latent2);
for(int i=0;i<MIXBOX_NUMLATENTS;i++)
{
latentMix[i] = (1.0f-t)*latent1[i] + t*latent2[i];
}
mixbox_latent_to_srgb8(latentMix,&r,&g,&b);
```
## License
Copyright (c) 2021, Secret Weapons. All rights reserved.<br>
This code is for non-commercial use only. It is provided for research and evaluation purposes.<br>
If you wish to obtain commercial license, please contact: mixbox@scrtwpns.com

80493
mixbox.cpp Normal file

File diff suppressed because it is too large Load Diff

35
mixbox.h Normal file
View File

@@ -0,0 +1,35 @@
// MIXBOX v1.2 (c) 2021 Secret Weapons
// This is for non-commercial use only.
// Contact: mixbox@scrtwpns.com
#ifndef MIXBOX_H_
#define MIXBOX_H_
#define MIXBOX_NUMLATENTS 7
void mixbox_lerp_srgb8(unsigned char r1,unsigned char g1,unsigned char b1,
unsigned char r2,unsigned char g2,unsigned char b2,
float t,
unsigned char* out_r,unsigned char* out_g,unsigned char* out_b);
void mixbox_lerp_srgb32f(float r1,float g1,float b1,
float r2,float g2,float b2,
float t,
float* out_r,float* out_g,float* out_b);
void mixbox_srgb8_to_latent(unsigned char r,unsigned char g,unsigned char b,float* out_latent);
void mixbox_latent_to_srgb8(float* latent,unsigned char* out_r,unsigned char* out_g,unsigned char* out_b);
void mixbox_srgb32f_to_latent(float r,float g,float b,float* out_latent);
void mixbox_latent_to_srgb32f(float* latent,float* out_r,float* out_g,float* out_b);
void mixbox_lerp_srgb8_dither(unsigned char r1,unsigned char g1,unsigned char b1,
unsigned char r2,unsigned char g2,unsigned char b2,
float t,
float dither_r,float dither_g,float dither_b,
unsigned char* out_r,unsigned char* out_g,unsigned char* out_b);
void mixbox_latent_to_srgb8_dither(float* latent,float dither_r,float dither_g,float dither_b,unsigned char* out_r,unsigned char* out_g,unsigned char* out_b);
#endif