using gitea now
This commit is contained in:
parent
61f02f3b1d
commit
d09c4d9d68
|
@ -0,0 +1,90 @@
|
|||
#include <stdio.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define RGB_COLOR 255
|
||||
|
||||
typdef struct{
|
||||
unsigned char red, green, blue;
|
||||
} colorChannel_t;
|
||||
|
||||
typdef struct{
|
||||
int x,y;
|
||||
colorChannel *data;
|
||||
} imagePixel_t;
|
||||
|
||||
static imagePixel_t *readPPM( const char *fileName ) {
|
||||
char buffer[16];
|
||||
imagePixel_t *image;
|
||||
int c, rgbColor;
|
||||
|
||||
FILE *fp = fopen(fileName, "r");
|
||||
if( !fp ) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if( !fgets(buffer, sizeof(buffer), fp);
|
||||
perror(filename);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if( buffer[0] != 'P' || buffer[1] != '6' ) {
|
||||
fprintf(stderr, "Invalid file format \n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
image = (imagePixel_t *) malloc(sizeof(imagePixel_t));
|
||||
if( !image ) {
|
||||
fprintf(stderr, "malloc() failed");
|
||||
}
|
||||
c = getc(fp);
|
||||
while( c == '#' ) {
|
||||
while( getc(fp) !='\n' ) {
|
||||
c = getc(fp);
|
||||
}
|
||||
ungetc(c, fp);
|
||||
if( scanf(fp, "%d %d", $image->, &img->) != 2 ) {
|
||||
fprintf(stderr, "Invalid image size in %s\n)", filename);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if( rgbColor != RGB_COLOR ) {
|
||||
fprintf(stderr,"Invalid image color range in %s\n", filename);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
while(fgetc(fp) != '\n') {
|
||||
image.data = (imagePixel_t *) malloc(image.x * image.y * sizeof(imagePixel_t));
|
||||
if ( !img ) {
|
||||
fprintf(stderr, "malloc() failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if ( fread( image.data, 3 * image.x, image.y, fp ) != img.y ) {
|
||||
fprintf(stderr, "Loading image failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
fclose( fp );
|
||||
return image;
|
||||
}
|
||||
|
||||
int *mkPpmTestArray (int* testarray, imagePixel_t *image ) {
|
||||
int i;
|
||||
int output [image.x * image.y]
|
||||
if ( !image ) {
|
||||
for ( i = 0; i < image.x * image.y>; i++ ) {
|
||||
// image.data[i].red = RGB_COLOR - image[i].red;
|
||||
// image.data[i].green = RGB_COLOR - image.data[i].green;
|
||||
// image.data[i].blue = RGB_COLOR - image.data[i].blue;
|
||||
output[i] = image.data[i].red;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void main ( void ) {
|
||||
char *fN = "beaches.ppm"
|
||||
int testarray [1024];
|
||||
imagePixel_t result;
|
||||
result = readPPM(fN);
|
||||
mkPpmTestArray(testarray, result);
|
||||
for (int i = 0; i < 1023; i++ ) {
|
||||
printf("%d\n", testArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -0,0 +1,14 @@
|
|||
#include <stdio.h>
|
||||
|
||||
void main ( void ) {
|
||||
unsigned ui_one = 1;
|
||||
signed i_one = 1;
|
||||
signed short s_minus_one = -1;
|
||||
|
||||
if ( s_minus_one > ui_one ) {
|
||||
printf("-1 > 1\n");
|
||||
}
|
||||
if ( s_minus_one < i_one ) {
|
||||
printf("-1 < 1\n");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue