Skip to content

Instantly share code, notes, and snippets.

@TotallyNotChase
Created January 1, 2020 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TotallyNotChase/df5910accaf700c60801633c821cc26d to your computer and use it in GitHub Desktop.
Save TotallyNotChase/df5910accaf700c60801633c821cc26d to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
#define COLORS_SIZE 256
struct PixelTuple
{
int red;
int green;
int blue;
};
typedef struct PixelTuple pxtup;
void main()
{
int i, j, k, l, pxindex = 0, valuearray[COLORS_SIZE];
FILE* pxF;
static pxtup pxarray[COLORS_SIZE * COLORS_SIZE * COLORS_SIZE];
for (i = 0; i < COLORS_SIZE; i++)
{
valuearray[i] = i;
}
for (i = 0; i < COLORS_SIZE; i++)
{
for (j = 0; j < COLORS_SIZE; j++)
{
for (k = 0; k < COLORS_SIZE; k++)
{
pxarray[pxindex].red = valuearray[i];
pxarray[pxindex].green = valuearray[j];
pxarray[pxindex++].blue = valuearray[k];
}
}
}
pxF= fopen("PixelTuple.bin", "wb");
if (pxF == NULL)
{
printf("Error opening file\n");
return;
}
fwrite(&pxarray, sizeof(pxtup), COLORS_SIZE * COLORS_SIZE * COLORS_SIZE, pxF);
fclose(pxF);
printf("Done\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment