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;
47 if (_argc > 1 && !strcmp(argv[_arg], "--depth")) {
48 save_depth = atoi(argv[_arg+1]);
55 printf("This tool will split images to fields or join from frames.\n");
56 printf("The odd lines (second line, fourth line, ...) is the first field.\n\n");
57 printf("Usage: %s [--depth 8] frame2field <field> <frame> <first>\n", argv[0]);
58 printf(" %s [--depth 8] field2frame <frame> <field> <first>\n", argv[0]);
59 printf(" --depth <bits> Change color depth from default %d to given bits\n", save_depth);
63 if (!strcmp(argv[_arg], "frame2field"))
64 mode = MODE_FRAME_2_FIELD;
65 else if (!strcmp(argv[_arg], "field2frame"))
66 mode = MODE_FIELD_2_FRAME;
70 frame = field = atoi(argv[_arg+2]);
73 printf("\n\nProcessing frame %d, field %d+%d\n", frame, field, field+1);
74 if (mode == MODE_FRAME_2_FIELD) {
75 frame_img = load_img(&width, &height, argv[_arg+1], frame++);
78 if (!(field1_img = malloc(width * height/2 * 3 * sizeof(unsigned short))))
80 if (!(field2_img = malloc(width * height/2 * 3 * sizeof(unsigned short))))
82 split_image(frame_img, field1_img, field2_img, width, height);
83 if (save_img(field1_img, width, height/2, 0, argv[_arg+2], field++))
85 if (save_img(field2_img, width, height/2, 0, argv[_arg+2], field++))
92 if (mode == MODE_FIELD_2_FRAME) {
93 field1_img = load_img(&width, &height, argv[_arg+1], field++);
96 field2_img = load_img(&width, &height, argv[_arg+1], field++);
99 if (!(frame_img = malloc(width * height*2 * 3 * sizeof(unsigned short))))
101 join_image(field1_img, field2_img, frame_img, width, height*2);
102 if (save_img(frame_img, width, height*2, 0, argv[_arg+2], frame++))