5 #include "../src/img.h"
7 /* split interlaced image into two fields */
8 static void split_image(const unsigned short *source, unsigned short *dest1,
9 unsigned short *dest2, int width, int height)
13 for (y = 0; y < (height / 2); y++) {
14 memcpy(dest2 + width * y * 3, source + width * y * 6,
15 width * 3 * sizeof(unsigned short));
16 memcpy(dest1 + width * y * 3, source + width * y * 6 + width * 3,
17 width * 3 * sizeof(unsigned short));
21 /* joint two fields into interlaced image */
22 static void join_image(const unsigned short *source1, unsigned short *source2,
23 unsigned short *dest, int width, int height)
27 for (y = 0; y < (height / 2); y++) {
28 memcpy(dest + width * y * 6, source2 + width * y * 3,
29 width * 3 * sizeof(unsigned short));
30 memcpy(dest + width * y * 6 + width * 3, source1 + width * y * 3,
31 width * 3 * sizeof(unsigned short));
35 #define MODE_FRAME_2_FIELD 1
36 #define MODE_FIELD_2_FRAME 2
39 int main(int argc, char *argv[])
41 unsigned short *field1_img = NULL, *field2_img = NULL, *frame_img = NULL;
43 int frame, field, swap = 0;
47 if (_argc > 1 && !strcmp(argv[_arg], "--depth")) {
48 save_depth = atoi(argv[_arg+1]);
53 if (_argc > 0 && !strcmp(argv[_arg], "--even")) {
61 printf("This tool will split images to fields or join from frames.\n");
62 printf("The odd lines (second line, fourth line, ...) is the first field.\n\n");
63 printf("Usage: %s [--depth 8] frame2field <frame> <field> <first>\n", argv[0]);
64 printf(" %s [--depth 8] field2frame <field> <frame> <first>\n", argv[0]);
65 printf(" --depth <bits> Change color depth from default %d to given bits\n", save_depth);
66 printf(" --even Use even lines for first field and odd for second\n");
70 if (!strcmp(argv[_arg], "frame2field"))
71 mode = MODE_FRAME_2_FIELD;
72 else if (!strcmp(argv[_arg], "field2frame"))
73 mode = MODE_FIELD_2_FRAME;
77 frame = field = atoi(argv[_arg+3]);
80 printf("\n\nProcessing frame %d, field %d+%d\n", frame, field, field+1);
81 if (mode == MODE_FRAME_2_FIELD) {
82 frame_img = load_img(&width, &height, argv[_arg+1], frame++);
85 if (!(field1_img = malloc(width * height/2 * 3 * sizeof(unsigned short))))
87 if (!(field2_img = malloc(width * height/2 * 3 * sizeof(unsigned short))))
90 split_image(frame_img, field2_img, field1_img, width, height);
92 split_image(frame_img, field1_img, field2_img, width, height);
93 if (save_img(field1_img, width, height/2, 0, argv[_arg+2], field++))
95 if (save_img(field2_img, width, height/2, 0, argv[_arg+2], field++))
102 if (mode == MODE_FIELD_2_FRAME) {
103 field1_img = load_img(&width, &height, argv[_arg+1], field++);
106 field2_img = load_img(&width, &height, argv[_arg+1], field++);
109 if (!(frame_img = malloc(width * height*2 * 3 * sizeof(unsigned short))))
112 join_image(field2_img, field1_img, frame_img, width, height*2);
114 join_image(field1_img, field2_img, frame_img, width, height*2);
115 if (save_img(frame_img, width, height*2, 0, argv[_arg+2], frame++))