Skip to content

Instantly share code, notes, and snippets.

@kennberg
Created September 15, 2012 02:41
Show Gist options
  • Save kennberg/3726147 to your computer and use it in GitHub Desktop.
Save kennberg/3726147 to your computer and use it in GitHub Desktop.
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