libtthimage/Lib/foo.c

105 lines
2.0 KiB
C
Raw Normal View History

2022-06-26 11:23:53 +11:00
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
2023-09-18 07:36:08 +11:00
#include <math.h>
2022-06-26 11:23:53 +11:00
2022-06-27 07:55:56 +11:00
#include "../tthimage.h"
2022-06-26 11:23:53 +11:00
/* ============================== */
2023-11-14 23:06:02 +11:00
2024-08-15 21:08:37 +11:00
/* new Wed Aug 14 19:17:20 UTC 2024
*
* parameters :
* ip: Image_Desc * of input picture
* ix, iy: coordinate of the pixel in this pic.
* op, ox, oy : same things for output picture
*/
2024-08-16 05:40:01 +11:00
#define PIXEL_COPY(ip, ix, iy, op, ox, oy) \
do { \
2024-08-16 12:22:55 +11:00
(op->Rpix[oy])[ox] = (ip->Rpix[iy])[ix]; \
(op->Gpix[oy])[ox] = (ip->Gpix[iy])[ix]; \
(op->Bpix[oy])[ox] = (ip->Bpix[iy])[ix]; \
2024-08-15 21:08:37 +11:00
} while (0)
2024-08-16 12:22:55 +11:00
#define SZPIC 4096
2024-08-15 21:08:37 +11:00
2024-08-15 22:43:12 +11:00
void essai_pixcopy(int usemacro)
2023-11-14 23:06:02 +11:00
{
2024-08-15 21:08:37 +11:00
Image_Desc *alice, *bob;
2024-08-15 22:43:12 +11:00
int x, y, foo;
double T0, T1, perpix;
2024-08-15 21:08:37 +11:00
long count;
2024-08-16 12:22:55 +11:00
char *fname;
2023-11-14 23:06:02 +11:00
2024-08-15 21:08:37 +11:00
alice = Image_alloc(SZPIC, SZPIC, IMAGE_RGB);
bob = Image_alloc(SZPIC, SZPIC, IMAGE_RGB);
2023-11-14 23:06:02 +11:00
2024-08-16 12:22:55 +11:00
Image_pattern_000(alice, 0);
Image_TGA_save("alice.tga", alice, 0);
2024-08-15 22:43:12 +11:00
2024-08-15 21:08:37 +11:00
T0 = tthi_dtime();
count = 0L;
2023-11-14 23:06:02 +11:00
2024-08-15 22:43:12 +11:00
if (usemacro) {
for (y=0; y<SZPIC; y++) {
for (x=0; x<SZPIC; x++) {
PIXEL_COPY(alice, x, y, bob, x, y);
count++;
}
}
2024-08-16 12:22:55 +11:00
fname = "bob1.tga";
2024-08-15 22:43:12 +11:00
}
else {
for (y=0; y<SZPIC; y++) {
for (x=0; x<SZPIC; x++) {
Image_pixel_copy(alice, x, y, bob, x, y);
count++;
}
2024-08-15 21:08:37 +11:00
}
2024-08-16 12:22:55 +11:00
fname = "bob0.tga";
2024-08-15 21:08:37 +11:00
}
2023-09-18 07:36:08 +11:00
2024-08-15 21:08:37 +11:00
T1 = tthi_dtime();
2023-09-18 17:46:13 +11:00
2024-08-16 12:22:55 +11:00
foo = Image_TGA_save(fname, bob, 0);
2024-08-15 22:43:12 +11:00
if (foo) {
fprintf(stderr, "%s: save -> %d\n", __func__, foo);
}
2024-08-16 12:22:55 +11:00
perpix = ((T1-T0) / (double)count) * 1e6;
fprintf(stderr, "%s : %10ld pixels, elapsed %9.6f seconds ==> %9.6f µs/pix\n",
2024-08-15 22:43:12 +11:00
usemacro ? "macro" : "func ",
count, T1-T0, perpix);
2023-09-18 17:46:13 +11:00
2024-08-15 21:08:37 +11:00
/* end */
2023-09-18 07:36:08 +11:00
}
2024-08-15 21:08:37 +11:00
/* ============================== */
2022-06-26 11:23:53 +11:00
int main(int argc, char *argv[])
{
2024-08-15 22:43:12 +11:00
int i;
2023-09-29 08:50:23 +11:00
2024-08-16 12:22:55 +11:00
fprintf(stderr, "*********** %s ************\n", argv[0]);
2023-11-14 23:06:02 +11:00
if (argc > 1) {
fprintf(stderr, "argument: %s\n", argv[1]);
2024-08-15 21:08:37 +11:00
Image_print_version(2);
2023-11-14 23:06:02 +11:00
Image_print_sizeof_structs("foo");
}
else {
2024-08-15 22:43:12 +11:00
for (i=0; i<5; i++) {
essai_pixcopy(0);
essai_pixcopy(1);
}
2023-11-14 23:06:02 +11:00
}
2022-06-27 07:55:56 +11:00
2023-11-14 23:06:02 +11:00
/*
2022-10-28 14:54:07 +11:00
foo = essai_show_t16x24(NULL);
fprintf(stderr, "essai show t16x24 --> %d\n", foo);
2023-11-14 23:06:02 +11:00
*/
2023-09-18 07:36:08 +11:00
2022-06-26 11:23:53 +11:00
return 0;
}