Skip to content

Instantly share code, notes, and snippets.

@dennda
Created October 5, 2011 20:16
Show Gist options
  • Save dennda/1265556 to your computer and use it in GitHub Desktop.
Save dennda/1265556 to your computer and use it in GitHub Desktop.
char *dest = (char*) malloc(width * height * 4 * sizeof(char));
short *subscript = (short*) imgData;
for (size_t i = 0; i < width * height; ++i) {
unsigned short x = subscript[i] + 1000;
dest[i*4] = x >> 8;
dest[i*4+1] = x;
dest[i*4+2] = 255;
dest[i*4+3] = 255;
}
FILE *fp = fopen("/Users/dennda/Desktop/binary.buf", "wb");
size_t count;
if(fp == NULL) {
printf("failed to open sample.txt\n");
assert(0);
}
count = fwrite((const char*) dest, sizeof(char), width*height*4, fp);
printf("Wrote %zu char. fclose(fp) %s.\n", width*height*4, fclose(fp) == 0 ? "succeeded" : "failed");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment