KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
Karma::KarmaUtilities Class Reference

The basic utilities class. More...

#include <KarmaUtilities.h>

Static Public Member Functions

static std::string ReadFileToSpitString (const std::string &filePath)
 Generates a sting of text contained within a file.
 
static std::string GetFilePath (const std::string &str)
 Extracts the file path from file source string (filepath + filename.extention)
 
static unsigned char * GetImagePixelData (char const *fileName, int *width, int *height, int *channels, int req_comp)
 Gathers image pixel data, arranged left-to-right, top-to-bottom, for the supplied image file.
 

Detailed Description

The basic utilities class.

Member Function Documentation

◆ GetFilePath()

std::string Karma::KarmaUtilities::GetFilePath ( const std::string & str)
static

Extracts the file path from file source string (filepath + filename.extention)

Parameters
strfilepath + filename.extention string
Since
Karma 1.0.0

◆ GetImagePixelData()

unsigned char * Karma::KarmaUtilities::GetImagePixelData ( char const * fileName,
int * width,
int * height,
int * channels,
int req_comp )
static

Gathers image pixel data, arranged left-to-right, top-to-bottom, for the supplied image file.

Few things to note:

  1. Limitations:
    • no 12-bit-per-channel JPEG
    • no JPEGs with arithmetic coding
    • GIF always returns *comp (or *channels) = 4
  2. The return value is an 'unsigned char *' which points to the pixel data, or NULL on an allocation failure or if the image is corrupt or invalid. The pixel data consists of *height scanlines of *width pixels, with each pixel consisting of N interleaved 8-bit components; the first pixel pointed to is top-left-most in the image. There is no padding between image scanlines or between pixels, regardless of format. The number of components N is 'desired_channels' if desired_channels is non-zero, or channels otherwise. If desired_channels is non-zero, channels has the number of components that would have been output otherwise. E.g. if you set desired_channels to 4, you will always get RGBA output, but you can check *channels to see if it's trivially opaque because e.g. there were only 3 channels in the source image.
Parameters
fileNameThe relative path to the file location
widthoutputs image width in pixels
heightoutputs image height in pixels
channelsoutputs number of image components in image file
req_comp(also desired_channels), if non-zero, are number of image components requested in result (rgba?)
Since
Karma 1.0.0

◆ ReadFileToSpitString()

std::string Karma::KarmaUtilities::ReadFileToSpitString ( const std::string & filePath)
static

Generates a sting of text contained within a file.

Parameters
filePathThe relative path of the location of the file to be read
See also
Input::SetGamepadMapping()
Since
Karma 1.0.0

The documentation for this class was generated from the following files: