add some helper functions

This commit is contained in:
jrkb 2023-02-21 11:00:43 +01:00
parent a25be7b41c
commit 9ad827c763
2 changed files with 42 additions and 0 deletions

31
src/ofxMsdfgen.cpp Normal file
View file

@ -0,0 +1,31 @@
#include "ofxMsdfgen.h"
#include "ofPixels.h"
void ofxMsdfgen::toOfImage(const msdfgen::Bitmap <float, 3> bitmap,
ofFloatImage & image){
image.allocate(bitmap.width(), bitmap.height(), OF_IMAGE_COLOR);
memcpy(image.getPixels().getData(), bitmap.getPixels(), bitmap.width() * bitmap.height() * 3 * sizeof(float));
image.update(); // float is slow here
}
void ofxMsdfgen::toOfImage(const msdfgen::Bitmap <float, 3> bitmap,
ofImage & image){
image.allocate(bitmap.width(), bitmap.height(), OF_IMAGE_COLOR);
ofPixels & pixels = image.getPixels();
int w = bitmap.width();
int h = bitmap.height();
for(int y = 0; y < h; y++){
for(int x = 0; x < w; x++){
const float * rgb = bitmap(x, y);
int index = 3 * (x + y * w);
pixels.getData()[index] = (unsigned char)std::clamp(rgb[0] * 256.0,
0.0, 255.0);
pixels.getData()[index + 1] = (unsigned char)std::clamp(rgb[1] * 256.0,
0.0, 255.0);
pixels.getData()[index + 2] = (unsigned char)std::clamp(rgb[2] * 256.0,
0.0, 255.0);
}
}
image.update();
}

11
src/ofxMsdfgen.h Normal file
View file

@ -0,0 +1,11 @@
#pragma once
#include "ofMain.h"
#include <msdf-atlas-gen/msdf-atlas-gen.h>
namespace ofxMsdfgen {
void toOfImage(const msdfgen::Bitmap <float, 3> bitmap,
ofFloatImage & image);
void toOfImage(const msdfgen::Bitmap <float, 3> bitmap,
ofImage & image);
}