Skip to content

Instantly share code, notes, and snippets.

@shiyuugohirao
Last active April 13, 2019 04:31
Show Gist options
  • Save shiyuugohirao/2ac1ad1078f7d0abb052a798ae2d75a7 to your computer and use it in GitHub Desktop.
Save shiyuugohirao/2ac1ad1078f7d0abb052a798ae2d75a7 to your computer and use it in GitHub Desktop.
openFrameworks + simple Base64 encoder
//
// ofBase64.h
//
// Created by shugohirao on 2018/05/09.
//
#pragma once
#include "Poco/Base64Encoder.h"
namespace ofBase64 {
static void removeCRLF(string &targetStr){
const char CR = '\r';
const char LF = '\n';
string str;
for (const auto c : targetStr) {
if (c != CR && c != LF) {
str += c;
}
}
targetStr = std::move(str);
}
static string base64_encode(ofBuffer buffer){
stringstream ss;
ss.str("");
Poco::Base64Encoder encoder(ss);
encoder << buffer;
encoder.close();
string str = ss.str();
removeCRLF(str);
return str;
}
static string base64_encode(ofPixels pix) {
ofBuffer imageBuffer;
ofSaveImage(pix, imageBuffer);
return base64_encode(imageBuffer);
}
static string base64_encode(ofFbo fbo) {
ofPixels pix;
fbo.readToPixels(pix);
return base64_encode(pix);
}
static string base64_encode(ofImage image){
ofPixels pix = image.getPixels();
return base64_encode(pix);
}
/*
static string base64_encode(ofSoundBuffer soundBuffer){
// referrer to https://gist.github.com/shiyuugohirao/1cfd1bb5ec02cd135d4552c15c85cca2
ofBuffer wavBuffer = makeWavBuffer(soundBuffer);
return base64_encode(wavBuffer);
}
*/
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment