-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 371262e
Showing
46 changed files
with
968 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
3 | ||
1 1 1 | ||
1 1 1 | ||
1 1 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
5 | ||
1 1 1 1 1 | ||
1 1 1 1 1 | ||
1 1 1 1 1 | ||
1 1 1 1 1 | ||
1 1 1 1 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
3 | ||
0 1 0 | ||
1 1 1 | ||
0 1 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
5 | ||
0 0 1 0 0 | ||
0 0 1 0 0 | ||
1 1 1 1 1 | ||
0 0 1 0 0 | ||
0 0 1 0 0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
11 | ||
121 | ||
1 1 1 1 1 1 1 1 1 1 1 | ||
1 1 1 1 1 1 1 1 1 1 1 | ||
1 1 1 1 1 1 1 1 1 1 1 | ||
1 1 1 1 1 1 1 1 1 1 1 | ||
1 1 1 1 1 1 1 1 1 1 1 | ||
1 1 1 1 1 1 1 1 1 1 1 | ||
1 1 1 1 1 1 1 1 1 1 1 | ||
1 1 1 1 1 1 1 1 1 1 1 | ||
1 1 1 1 1 1 1 1 1 1 1 | ||
1 1 1 1 1 1 1 1 1 1 1 | ||
1 1 1 1 1 1 1 1 1 1 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
3 | ||
9 | ||
1 1 1 | ||
1 1 1 | ||
1 1 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
3 | ||
1 | ||
-1 1 1 | ||
-1 -2 1 | ||
-1 1 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
3 | ||
1 | ||
0 -1 0 | ||
-1 4 -1 | ||
0 -1 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
3 | ||
4 | ||
-1 -1 -1 | ||
-1 12 -1 | ||
-1 -1 -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
3 | ||
1 | ||
-1 -2 -1 | ||
0 0 0 | ||
1 2 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
3 | ||
1 | ||
-1 0 1 | ||
-2 0 2 | ||
-1 0 1 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "png_wrapper.h" | ||
|
||
static void process_image(struct Image img, unsigned char threshold) | ||
{ | ||
for (size_t y = 0; y < img.height; y++) | ||
for (size_t x = 0; x < img.width; x++) | ||
img.pixels[y][x] = img.pixels[y][x] >= threshold ? 255 : 0; | ||
} | ||
|
||
int main(int argc, char * const argv[]) | ||
{ | ||
if (argc < 3 || argc > 4) | ||
error("usage: %s <input_file> [<output_file>] <threshold (0-255)>", | ||
argv[0]); | ||
|
||
char *input_filename = argv[1]; | ||
char *output_filename; | ||
char *s_threshold; | ||
|
||
if (argc == 4) | ||
{ | ||
output_filename = argv[2]; | ||
s_threshold = argv[3]; | ||
} | ||
else | ||
{ | ||
output_filename = alloca(strlen(input_filename) + sizeof("_out.png")); | ||
strcpy(output_filename, input_filename); | ||
strcat(output_filename, "_out.png"); | ||
s_threshold = argv[2]; | ||
} | ||
|
||
int threshold = atoi(s_threshold); | ||
if (threshold < 0 || threshold > 255) | ||
error("wrong threshold (%d)", threshold); | ||
|
||
struct Image img = read_grayscale_png(input_filename); | ||
printf("Input file \"%s\" opened (width = %u, height = %u)\n", | ||
input_filename, img.width, img.height); | ||
|
||
process_image(img, (unsigned char) threshold); | ||
|
||
write_grayscale_png(img, output_filename); | ||
free_pixels(img); | ||
|
||
return 0; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "png_wrapper.h" | ||
|
||
static inline void add_sat(struct Image img, int x, int y, double a) | ||
{ | ||
if (x < 0 || y < 0 || x >= img.width || y >= img.height) | ||
return; | ||
|
||
int sum = img.pixels[y][x] + a + 0.5; | ||
|
||
if (sum < 0) | ||
sum = 0; | ||
else if (sum > 255) | ||
sum = 255; | ||
|
||
img.pixels[y][x] = sum; | ||
} | ||
|
||
static void process_image(struct Image img) | ||
{ | ||
for (int y = 0; y < img.height; y++) | ||
for (int x = 0; x < img.width; x++) | ||
{ | ||
unsigned char old_val = img.pixels[y][x]; | ||
unsigned char new_val = (old_val / 128) * 255; | ||
img.pixels[y][x] = new_val; | ||
int err = old_val - new_val; | ||
|
||
add_sat(img, x + 1, y + 0, err * 7 / 16.0); | ||
add_sat(img, x - 1, y + 1, err * 3 / 16.0); | ||
add_sat(img, x + 0, y + 1, err * 5 / 16.0); | ||
add_sat(img, x + 1, y + 1, err * 1 / 16.0); | ||
} | ||
} | ||
|
||
int main(int argc, char * const argv[]) | ||
{ | ||
if (argc < 2 || argc > 3) | ||
error("usage: %s <input_file> [<output_file>]", argv[0]); | ||
|
||
char *input_filename = argv[1]; | ||
char *output_filename; | ||
|
||
if (argc == 3) | ||
output_filename = argv[2]; | ||
else | ||
{ | ||
output_filename = alloca(strlen(input_filename) + sizeof("_out.png")); | ||
strcpy(output_filename, input_filename); | ||
strcat(output_filename, "_out.png"); | ||
} | ||
|
||
struct Image img = read_grayscale_png(input_filename); | ||
printf("Input file \"%s\" opened (width = %u, height = %u)\n", | ||
input_filename, img.width, img.height); | ||
|
||
process_image(img); | ||
|
||
write_grayscale_png(img, output_filename); | ||
free_pixels(img); | ||
|
||
return 0; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "png_wrapper.h" | ||
|
||
static void process_image(struct Image in, struct Image out, double N) | ||
{ | ||
for (size_t y = 0; y < out.height; y++) | ||
for (size_t x = 0; x < out.width; x++) | ||
{ | ||
size_t in_x = x / N + 0.5, | ||
in_y = y / N + 0.5; | ||
|
||
if (in_x > in.width - 1) in_x = in.width - 1; | ||
if (in_y > in.height - 1) in_y = in.height - 1; | ||
|
||
out.pixels[y][x] = in.pixels[in_y][in_x]; | ||
} | ||
} | ||
|
||
int main(int argc, char * const argv[]) | ||
{ | ||
if (argc < 3 || argc > 4) | ||
error("usage: %s <input_file> [<output_file>] <N (0.0-10.0)>", argv[0]); | ||
|
||
char *input_filename = argv[1]; | ||
char *output_filename; | ||
char *sN; | ||
|
||
if (argc == 4) | ||
{ | ||
output_filename = argv[2]; | ||
sN = argv[3]; | ||
} | ||
else | ||
{ | ||
output_filename = alloca(strlen(input_filename) + sizeof("_out.png")); | ||
strcpy(output_filename, input_filename); | ||
strcat(output_filename, "_out.png"); | ||
sN = argv[2]; | ||
} | ||
|
||
double N = atof(sN); | ||
if (N <= 0.0 || N > 10.0) | ||
error("N should be in the range 0.0-10.0"); | ||
|
||
struct Image in = read_grayscale_png(input_filename); | ||
printf("Input file \"%s\" opened (width = %u, height = %u)\n", | ||
input_filename, in.width, in.height); | ||
|
||
struct Image out = { in.width * N + 0.5, in.height * N + 0.5 }; | ||
alloc_pixels(&out); | ||
|
||
process_image(in, out, N); | ||
free_pixels(in); | ||
|
||
write_grayscale_png(out, output_filename); | ||
free_pixels(out); | ||
|
||
return 0; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "png_wrapper.h" | ||
|
||
static void process_image(struct Image in, struct Image out, double N) | ||
{ | ||
for (size_t y = 0; y < out.height; y++) | ||
for (size_t x = 0; x < out.width; x++) | ||
{ | ||
size_t in_x = x / N, | ||
in_y = y / N; | ||
|
||
if (in_x > in.width - 2) in_x = in.width - 2; | ||
if (in_y > in.height - 2) in_y = in.height - 2; | ||
|
||
unsigned char I00 = in.pixels[in_y + 0][in_x + 0], | ||
I10 = in.pixels[in_y + 0][in_x + 1], | ||
I01 = in.pixels[in_y + 1][in_x + 0], | ||
I11 = in.pixels[in_y + 1][in_x + 1]; | ||
|
||
double u = x / N - in_x, | ||
v = y / N - in_y; | ||
|
||
int res = I00 * (1-u) * (1-v) | ||
+ I10 * u * (1-v) | ||
+ I01 * (1-u) * v | ||
+ I11 * u * v + 0.5; | ||
|
||
if (res < 0) res = 0; | ||
if (res > 255) res = 255; | ||
out.pixels[y][x] = res; | ||
} | ||
} | ||
|
||
int main(int argc, char * const argv[]) | ||
{ | ||
if (argc < 3 || argc > 4) | ||
error("usage: %s <input_file> [<output_file>] <N (0.0-10.0)>", argv[0]); | ||
|
||
char *input_filename = argv[1]; | ||
char *output_filename; | ||
char *sN; | ||
|
||
if (argc == 4) | ||
{ | ||
output_filename = argv[2]; | ||
sN = argv[3]; | ||
} | ||
else | ||
{ | ||
output_filename = alloca(strlen(input_filename) + sizeof("_out.png")); | ||
strcpy(output_filename, input_filename); | ||
strcat(output_filename, "_out.png"); | ||
sN = argv[2]; | ||
} | ||
|
||
double N = atof(sN); | ||
if (N <= 0.0 || N > 10.0) | ||
error("N should be in the range 0.0-10.0"); | ||
|
||
struct Image in = read_grayscale_png(input_filename); | ||
printf("Input file \"%s\" opened (width = %u, height = %u)\n", | ||
input_filename, in.width, in.height); | ||
|
||
struct Image out = { in.width * N + 0.5, in.height * N + 0.5 }; | ||
alloc_pixels(&out); | ||
|
||
process_image(in, out, N); | ||
free_pixels(in); | ||
|
||
write_grayscale_png(out, output_filename); | ||
free_pixels(out); | ||
|
||
return 0; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "png_wrapper.h" | ||
|
||
static void process_images(struct Image top, struct Image bot, | ||
struct Image alpha, struct Image out) | ||
{ | ||
for (int y = 0; y < out.height; y++) | ||
for (int x = 0; x < out.width; x++) | ||
{ | ||
double a = alpha.pixels[y][x] / 255.0; | ||
|
||
int res = top.pixels[y][x] * (1 - a) | ||
+ bot.pixels[y][x] * a + 0.5; | ||
|
||
if (res > 255) res = 255; | ||
out.pixels[y][x] = res; | ||
} | ||
} | ||
|
||
int main(int argc, char * const argv[]) | ||
{ | ||
if (argc < 4 || argc > 5) | ||
error("usage: %s <top_file> <bottom_file> " | ||
"<alpha_channel_file> [<output_file>]", argv[0]); | ||
|
||
char *input1_filename = argv[1]; | ||
char *input2_filename = argv[2]; | ||
char *input3_filename = argv[3]; | ||
char *output_filename; | ||
|
||
if (argc == 5) | ||
output_filename = argv[4]; | ||
else | ||
{ | ||
output_filename = alloca(strlen(input1_filename) + sizeof("_out.png")); | ||
strcpy(output_filename, input1_filename); | ||
strcat(output_filename, "_out.png"); | ||
} | ||
|
||
struct Image in1 = read_grayscale_png(input1_filename); | ||
printf("Top input file \"%s\" opened (width = %u, height = %u)\n", | ||
input1_filename, in1.width, in1.height); | ||
|
||
struct Image in2 = read_grayscale_png(input2_filename); | ||
printf("Bottom input file \"%s\" opened (width = %u, height = %u)\n", | ||
input2_filename, in2.width, in2.height); | ||
|
||
struct Image in3 = read_grayscale_png(input3_filename); | ||
printf("Alpha channel input file \"%s\" opened (width = %u, height = %u)\n", | ||
input3_filename, in3.width, in3.height); | ||
|
||
struct Image out = { in1.width, in2.height }; | ||
alloc_pixels(&out); | ||
|
||
process_images(in1, in2, in3, out); | ||
free_pixels(in1); | ||
free_pixels(in2); | ||
free_pixels(in3); | ||
|
||
write_grayscale_png(out, output_filename); | ||
free_pixels(out); | ||
|
||
return 0; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.