Created
September 15, 2012 02:41
-
-
Save kennberg/3726147 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void writeBuffer(char *pPath, uint8_t *pBuffer, int width, int height, int channels) { | |
int x, y, j, c; | |
FILE *p = fopen(pPath, "wb"); | |
for (y = 0; y < height; y++) { | |
for (x = 0; x < width; x++) { | |
for (c = 0; c < channels; c++) { | |
uint8_t buf[1]; | |
j = (y * width + x) * channels + c; | |
buf[0] = pBuffer[j]; | |
fwrite(buf, 1, sizeof(buf), p); | |
} | |
} | |
} | |
fclose(p); | |
} | |
void readBuffer(char *pPath, uint8_t *pBuffer, int width, int height, int channels) { | |
int x, y, j, c; | |
FILE *p = fopen(pPath, "rb"); | |
for (y = 0; y < height; y++) { | |
for (x = 0; x < width; x++) { | |
for (c = 0; c < channels; c++) { | |
uint8_t buf[1]; | |
fread(buf, 1, sizeof(buf), p); | |
j = (y * width + x) * channels + c; | |
pBuffer[j] = buf[0]; | |
} | |
} | |
} | |
fclose(p); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment