Post by nathanmyersc on Feb 20, 2024 17:02:17 GMT
Whilst im building my intention engine i have built a text to bitmap creator that will use your intentions.txt as the data for the pixels until it creates an image of your chosen size.
As always the code is free to anyone who wants it.
You can overlay the bitmap onto other images at low alpha like 300-400 times and it will have effect and i have other tools that put affirmations inside of jpg's metadata and stuff like that il release soon.
As always the code is free to anyone who wants it.
You can overlay the bitmap onto other images at low alpha like 300-400 times and it will have effect and i have other tools that put affirmations inside of jpg's metadata and stuff like that il release soon.
#include <iostream>
#include <fstream>
#include <cstdint>
#include <vector>
#include <algorithm>
using namespace std;
// Function to write the bitmap file header
void writeBitmapFileHeader(ofstream& file, uint32_t fileSize) {
const uint16_t bfType = 0x4D42; // "BM"
const uint32_t bfReserved = 0;
const uint32_t bfOffBits = 54; // Offset to pixel data (fixed for 24-bit RGB)
file.write(reinterpret_cast<const char*>(&bfType), sizeof(uint16_t)); // Signature
file.write(reinterpret_cast<const char*>(&fileSize), sizeof(uint32_t)); // File size
file.write(reinterpret_cast<const char*>(&bfReserved), sizeof(uint32_t)); // Reserved (unused)
file.write(reinterpret_cast<const char*>(&bfOffBits), sizeof(uint32_t)); // Offset to pixel data
}
// Function to write the bitmap information header
void writeBitmapInfoHeader(ofstream& file, uint32_t width, uint32_t height) {
const uint32_t biSize = 40; // Size of BITMAPINFOHEADER
const uint16_t biPlanes = 1; // Number of color planes
const uint16_t biBitCount = 24; // Bits per pixel (24-bit RGB)
const uint32_t biCompression = 0; // Compression method (BI_RGB for no compression)
const uint32_t biSizeImage = 0; // Image size (0 for BI_RGB)
const uint32_t biXPelsPerMeter = 0; // Horizontal resolution (pixels per meter)
const uint32_t biYPelsPerMeter = 0; // Vertical resolution (pixels per meter)
const uint32_t biClrUsed = 0; // Number of colors in the palette (0 for full color)
const uint32_t biClrImportant = 0; // Number of important colors (0 for all)
file.write(reinterpret_cast<const char*>(&biSize), sizeof(uint32_t)); // Header size
file.write(reinterpret_cast<const char*>(&width), sizeof(uint32_t)); // Image width
file.write(reinterpret_cast<const char*>(&height), sizeof(uint32_t)); // Image height
file.write(reinterpret_cast<const char*>(&biPlanes), sizeof(uint16_t)); // Color planes
file.write(reinterpret_cast<const char*>(&biBitCount), sizeof(uint16_t)); // Bits per pixel
file.write(reinterpret_cast<const char*>(&biCompression), sizeof(uint32_t)); // Compression
file.write(reinterpret_cast<const char*>(&biSizeImage), sizeof(uint32_t)); // Image size
file.write(reinterpret_cast<const char*>(&biXPelsPerMeter), sizeof(uint32_t)); // Horizontal resolution
file.write(reinterpret_cast<const char*>(&biYPelsPerMeter), sizeof(uint32_t)); // Vertical resolution
file.write(reinterpret_cast<const char*>(&biClrUsed), sizeof(uint32_t)); // Colors used
file.write(reinterpret_cast<const char*>(&biClrImportant), sizeof(uint32_t)); // Important colors
}
// Function to convert a character to its bit representation
vector<bool> charToBits(char c) {
vector<bool> bits;
for (int i = 0; i < 8; ++i) {
bits.push_back((c >> i) & 1);
}
return bits;
}
int main() {
uint32_t width = 1920; // Image width
uint32_t height = 1080; // Image height
std::string inputFileName;
std::cout << "INPUT WIDTH OF OUTPUT BIT MAP:";
std::cin >> width;
std::cout << "INPUT HEIGHT OF OUTPUT BIT MAP:";
std::cin >> height;
std::cout << "INPUT TEXT FILE NAME:";
std::cin >> inputFileName;
const uint32_t bytesPerPixel = 3; // Bytes per pixel
const uint32_t rowSize = width * bytesPerPixel; // Size of each row in bytes
const uint32_t rowPadding = (4 - (rowSize % 4)) % 4; // Padding bytes per row to ensure alignment
const uint32_t pixelDataSize = (rowSize + rowPadding) * height; // Total size of pixel data including padding
const uint32_t totalFileSize = 54 + pixelDataSize; // Total file size including header
// Open input text file
ifstream inputFile(inputFileName);
if (!inputFile) {
cerr << "Error: Unable to open input text file." << endl;
return 1;
}
// Read characters from input text file and convert to bits
vector<bool> allBits;
char c;
while (inputFile.get(c)) {
vector<bool> bits = charToBits(c);
allBits.insert(allBits.end(), bits.begin(), bits.end());
}
// Repeat the content of the input text file until it fills the required number of bits
while (allBits.size() < width * height * bytesPerPixel * 8) {
allBits.insert(allBits.end(), allBits.begin(), allBits.end());
}
// Truncate the bits vector if it exceeds the required number of bits
allBits.resize(width * height * bytesPerPixel * 8);
// Create output bitmap file
ofstream outputFile("output.bmp", ios::binary);
if (!outputFile) {
cerr << "Error: Unable to create output bitmap file." << endl;
return 1;
}
// Write bitmap file header
writeBitmapFileHeader(outputFile, totalFileSize);
// Write bitmap information header
writeBitmapInfoHeader(outputFile, width, height);
// Write pixel data (converted bits) with row padding
for (size_t i = 0; i < height; ++i) {
for (size_t j = 0; j < width; ++j) {
uint32_t pixel = 0;
for (size_t k = 0; k < bytesPerPixel * 8; ++k) {
pixel |= allBits[(i * width + j) * bytesPerPixel * 8 + k] << k;
}
outputFile.write(reinterpret_cast<const char*>(&pixel), bytesPerPixel);
}
// Write row padding
for (size_t k = 0; k < rowPadding; ++k) {
outputFile.put(0);
}
}
// Close output bitmap file
outputFile.close();
cout << "Bitmap created successfully." << endl;
return 0;
}