Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,23 @@
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
const int dimx = 800, dimy = 800;
int i, j;
FILE *fp = fopen("first.ppm", "wb"); /* b - binary mode */
(void) fprintf(fp, "P6\n%d %d\n255\n", dimx, dimy);
for (j = 0; j < dimy; ++j)
{
for (i = 0; i < dimx; ++i)
{
static unsigned char color[3];
color[0] = i % 256; /* red */
color[1] = j % 256; /* green */
color[2] = (i * j) % 256; /* blue */
(void) fwrite(color, 1, 3, fp);
}
}
(void) fclose(fp);
return EXIT_SUCCESS;
}

View file

@ -0,0 +1,36 @@
#include <stdio.h>
int main()
{
const char *filename = "n.pgm";
int x, y;
/* size of the image */
const int x_max = 100; /* width */
const int y_max = 100; /* height */
/* 2D array for colors (shades of gray) */
unsigned char data[y_max][x_max];
/* color component is coded from 0 to 255 ; it is 8 bit color file */
const int MaxColorComponentValue = 255;
FILE * fp;
/* comment should start with # */
const char *comment = "# this is my new binary pgm file";
/* fill the data array */
for (y = 0; y < y_max; ++y) {
for (x = 0; x < x_max; ++x) {
data[y][x] = (x + y) & 255;
}
}
/* write the whole data array to ppm file in one step */
/* create new file, give it a name and open it in binary mode */
fp = fopen(filename, "wb");
/* write header to the file */
fprintf(fp, "P5\n %s\n %d\n %d\n %d\n", comment, x_max, y_max,
MaxColorComponentValue);
/* write image data bytes to the file */
fwrite(data, sizeof(data), 1, fp);
fclose(fp);
printf("OK - file %s saved\n", filename);
return 0;
}

View file

@ -0,0 +1 @@
void output_ppm(FILE *fd, image img);

View file

@ -0,0 +1,10 @@
#include "imglib.h"
void output_ppm(FILE *fd, image img)
{
unsigned int n;
(void) fprintf(fd, "P6\n%d %d\n255\n", img->width, img->height);
n = img->width * img->height;
(void) fwrite(img->buf, sizeof(pixel), n, fd);
(void) fflush(fd);
}