-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathiidc1394.patch
625 lines (586 loc) · 15.6 KB
/
iidc1394.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
diff -ruN effectv-0.3.11/Makefile dctrial/Makefile
--- effectv-0.3.11/Makefile 2003-12-25 23:03:46.854199000 +0900
+++ dctrial/Makefile 2004-10-26 16:09:33.465259000 +0900
@@ -7,7 +7,7 @@
INSTALL = /usr/bin/install -c
CFLAGS = $(CONFIG) $(CONFIG.arch) $(CFLAGS.opt) -Iv4lutils `sdl-config --cflags`
-LIBS = v4lutils/libv4lutils.a -lm `sdl-config --libs` $(LIBS.extra)
+LIBS = v4lutils/libv4lutils.a -lm `sdl-config --libs` -ldc1394_control -lraw1394 $(LIBS.extra)
PROGRAM = effectv
diff -ruN effectv-0.3.11/palette.c dctrial/palette.c
--- effectv-0.3.11/palette.c 2005-07-12 21:12:56.265754000 +0900
+++ dctrial/palette.c 2006-02-14 22:33:05.377335000 +0900
@@ -281,6 +281,134 @@
}
}
+static void convert_DCYUV422toRGB32
+(unsigned char *src, RGB32 *dest, int width, int height)
+{
+ int i, length;
+ unsigned int gray;
+ unsigned int u, v;
+ unsigned char *p;
+
+ length = width * height / 2;
+ p = (unsigned char *)dest;
+ for(i=0; i<length; i++) {
+ u = src[0];
+ v = src[2];
+ gray = YtoRGB[src[1]];
+ p[0] = clip[CLIP + gray + UtoB[u]];
+ p[1] = clip[CLIP + gray + UtoG[u] + VtoG[v]];
+ p[2] = clip[CLIP + gray + VtoR[v]];
+ gray = YtoRGB[src[3]];
+ p[4] = clip[CLIP + gray + UtoB[u]];
+ p[5] = clip[CLIP + gray + UtoG[u] + VtoG[v]];
+ p[6] = clip[CLIP + gray + VtoR[v]];
+ p += 8;
+ src += 4;
+ }
+}
+
+static void convert_DCYUV422toRGB32_hflip
+(unsigned char *src, RGB32 *dest, int width, int height)
+{
+ int x, y;
+ unsigned int gray;
+ unsigned int u, v;
+ unsigned char *p;
+
+ /* Images will be cluttered when 'width' is odd number. It is not so
+ * difficult to adjust it, but it makes conversion little slow.. */
+ width &= 0xfffffffe;
+ p = (unsigned char *)(dest + width - 2);
+ for(y=0; y<height; y++) {
+ for(x=0; x<width; x+=2) {
+ u = src[1];
+ v = src[3];
+ gray = YtoRGB[src[0]];
+ p[4] = clip[CLIP + gray + UtoB[u]];
+ p[5] = clip[CLIP + gray + UtoG[u] + VtoG[v]];
+ p[6] = clip[CLIP + gray + VtoR[v]];
+ gray = YtoRGB[src[2]];
+ p[0] = clip[CLIP + gray + UtoB[u]];
+ p[1] = clip[CLIP + gray + UtoG[u] + VtoG[v]];
+ p[2] = clip[CLIP + gray + VtoR[v]];
+ p -= 8;
+ src += 4;
+ }
+ p += width * 8;
+ }
+}
+
+static void convert_DCYUV411toRGB32
+(unsigned char *src, RGB32 *dest, int width, int height)
+{
+ int i, length;
+ unsigned int gray;
+ unsigned int u, v;
+ unsigned char *p;
+
+ p = (unsigned char *)dest;
+ length = width * height / 4;
+ for(i = 0; i < length; i++) {
+ u = src[0];
+ v = src[3];
+ gray = YtoRGB[src[1]];
+ p[0] = clip[CLIP + gray + UtoB[u]];
+ p[1] = clip[CLIP + gray + UtoG[u] + VtoG[v]];
+ p[2] = clip[CLIP + gray + VtoR[v]];
+ gray = YtoRGB[src[2]];
+ p[4] = clip[CLIP + gray + UtoB[u]];
+ p[5] = clip[CLIP + gray + UtoG[u] + VtoG[v]];
+ p[6] = clip[CLIP + gray + VtoR[v]];
+ gray = YtoRGB[src[4]];
+ p[8] = clip[CLIP + gray + UtoB[u]];
+ p[9] = clip[CLIP + gray + UtoG[u] + VtoG[v]];
+ p[10] = clip[CLIP + gray + VtoR[v]];
+ gray = YtoRGB[src[5]];
+ p[12] = clip[CLIP + gray + UtoB[u]];
+ p[13] = clip[CLIP + gray + UtoG[u] + VtoG[v]];
+ p[14] = clip[CLIP + gray + VtoR[v]];
+
+ p += 16;
+ src += 6;
+ }
+}
+
+static void convert_DCYUV411toRGB32_hflip
+(unsigned char *src, RGB32 *dest, int width, int height)
+{
+ int x, y;
+ unsigned int gray;
+ unsigned int u, v;
+ unsigned char *p;
+
+ p = (unsigned char *)(dest + width - 2);
+ for(y=0; y<height; y++) {
+ for(x=0; x<width; x+=4) {
+ u = src[0];
+ v = src[3];
+ gray = YtoRGB[src[1]];
+ p[12] = clip[CLIP + gray + UtoB[u]];
+ p[13] = clip[CLIP + gray + UtoG[u] + VtoG[v]];
+ p[14] = clip[CLIP + gray + VtoR[v]];
+ gray = YtoRGB[src[2]];
+ p[8] = clip[CLIP + gray + UtoB[u]];
+ p[9] = clip[CLIP + gray + UtoG[u] + VtoG[v]];
+ p[10] = clip[CLIP + gray + VtoR[v]];
+ gray = YtoRGB[src[4]];
+ p[4] = clip[CLIP + gray + UtoB[u]];
+ p[5] = clip[CLIP + gray + UtoG[u] + VtoG[v]];
+ p[6] = clip[CLIP + gray + VtoR[v]];
+ gray = YtoRGB[src[5]];
+ p[0] = clip[CLIP + gray + UtoB[u]];
+ p[1] = clip[CLIP + gray + UtoG[u] + VtoG[v]];
+ p[2] = clip[CLIP + gray + VtoR[v]];
+ p -= 16;
+ src += 6;
+ }
+ p += width * PIXEL_SIZE * 2;
+ }
+}
+
static void convert_YUV422PtoRGB32
(unsigned char *src, RGB32 *dest, int width, int height)
{
@@ -630,6 +758,8 @@
{VIDEO_PALETTE_RGB24, convert_RGB24toRGB32, convert_RGB24toRGB32_hflip},
{VIDEO_PALETTE_RGB565, convert_RGB565toRGB32, convert_RGB565toRGB32_hflip},
{VIDEO_PALETTE_RGB555, convert_RGB555toRGB32, convert_RGB555toRGB32_hflip},
+ {VIDEO_PALETTE_DCYUV422, convert_DCYUV422toRGB32, convert_DCYUV422toRGB32_hflip},
+ {VIDEO_PALETTE_DCYUV411, convert_DCYUV411toRGB32, convert_DCYUV411toRGB32_hflip},
{VIDEO_PALETTE_YUV422, convert_YUV422toRGB32, convert_YUV422toRGB32_hflip},
{VIDEO_PALETTE_YUV422P, convert_YUV422PtoRGB32, convert_YUV422PtoRGB32_hflip},
{VIDEO_PALETTE_YUV420P, convert_YUV420PtoRGB32, convert_YUV420PtoRGB32_hflip},
@@ -875,6 +1005,8 @@
{"rgb565", VIDEO_PALETTE_RGB565, "VIDEO_PALETTE_RGB565"},
{"rgb555", VIDEO_PALETTE_RGB555, "VIDEO_PALETTE_RGB555"},
{"yuv422", VIDEO_PALETTE_YUV422, "VIDEO_PALETTE_YUV422"},
+ {"dcyuv422", VIDEO_PALETTE_DCYUV422, "VIDEO_PALETTE_DCYUV422"},
+ {"dcyuv411", VIDEO_PALETTE_DCYUV411, "VIDEO_PALETTE_DCYUV411"},
{"yuv422p", VIDEO_PALETTE_YUV422P, "VIDEO_PALETTE_YUV422P"},
{"yuv420p", VIDEO_PALETTE_YUV420P, "VIDEO_PALETTE_YUV420P"},
{"yuv411p", VIDEO_PALETTE_YUV411P, "VIDEO_PALETTE_YUV411P"},
diff -ruN effectv-0.3.11/palette.h dctrial/palette.h
--- effectv-0.3.11/palette.h 2005-02-01 08:50:48.839709000 +0900
+++ dctrial/palette.h 2005-02-04 01:48:40.296489000 +0900
@@ -9,6 +9,9 @@
#ifndef __PALETTE_H__
#define __PALETTE_H__
+#define VIDEO_PALETTE_DCYUV411 257
+#define VIDEO_PALETTE_DCYUV422 258
+
typedef void palette_converter_toRGB32(unsigned char *, RGB32 *, int, int);
typedef void palette_converter_fromRGB32(RGB32 *, int, int, unsigned char *, int, int);
struct palette_converter_toRGB32_map
diff -ruN effectv-0.3.11/video.c dctrial/video.c
--- effectv-0.3.11/video.c 2006-02-14 19:25:42.493158000 +0900
+++ dctrial/video.c 2006-02-14 22:38:06.005440000 +0900
@@ -9,7 +9,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <time.h>
+#include <libraw1394/raw1394.h>
+#include <libdc1394/dc1394_control.h>
+
#include <v4lutils.h>
#include "EffecTV.h"
@@ -18,7 +22,12 @@
#include "utils.h"
/* Currently there is only one v4l device obeject. */
+#if 0
static v4ldevice vd;
+#endif
+
+static raw1394handle_t dc1394Handle = NULL;
+static dc1394_cameracapture dc1394Camera;
/* Flag for horizontal flipping mode */
int video_horizontalFlip = 0;
@@ -28,6 +37,7 @@
int video_height;
int video_area; // = video_width * video_height
+#if 0
/* Video input parameters */
static int video_channel;
static int video_norm;
@@ -47,6 +57,7 @@
static int picture_hue;
static int picture_colour;
static int picture_contrast;
+#endif
static palette_converter_toRGB32 *converter;
static palette_converter_toRGB32 *converter_hflip;
@@ -72,12 +83,83 @@
#define MINWIDTH (vd.capability.minwidth)
#define MINHEIGHT (vd.capability.minheight)
+static int getRaw1394Ports()
+{
+#define MAX_PORTS 4
+
+ raw1394handle_t handle = NULL;
+ int numPorts = MAX_PORTS;
+ struct raw1394_portinfo ports[MAX_PORTS];
+
+ handle = raw1394_new_handle();
+ if(handle == NULL) {
+ perror("Unable to acquire a raw1394 handle: ");
+ return -1;
+ }
+
+ numPorts = raw1394_get_port_info(handle, ports, numPorts);
+ raw1394_destroy_handle(handle);
+
+ return numPorts;
+}
+
+static int findCamera(int numPorts)
+{
+ int port;
+ int camCount;
+ nodeid_t *nodes;
+ dc1394_camerainfo info;
+ int found = 0;
+
+ for(port = 0; port < numPorts; port++) {
+ if(dc1394Handle != NULL) {
+ dc1394_destroy_handle(dc1394Handle);
+ }
+
+ dc1394Handle = dc1394_create_handle(port);
+ if(dc1394Handle == NULL) {
+ perror("Unable to aquire a raw1394 handle.\n");
+ return -1;
+ }
+
+ camCount = 0;
+ nodes = dc1394_get_camera_nodes(dc1394Handle, &camCount, 1);
+
+ if(camCount > 0) {
+ if(dc1394_get_camera_info(dc1394Handle, nodes[0], &info) == DC1394_SUCCESS) {
+ dc1394_print_camera_info(&info);
+ dc1394Camera.node = nodes[0];
+ found = 1;
+ break;
+ }
+ }
+ dc1394_free_camera_nodes(nodes);
+ if(found) {
+ if(dc1394Camera.node == raw1394_get_nodecount(dc1394Handle) - 1) {
+ raw1394_reset_bus(dc1394Handle);
+ sleep(2);
+ found = 0;
+ }
+ }
+ }
+
+ if(!found) return -1;
+
+ return 0;
+}
+
/* Channel and norm is determined at initialization time. */
-int video_init(char *file, int channel, int norm, int freq, int w, int h, int palette)
+int video_init(char *file, int ch, int norm, int freq, int w, int h, int palette)
{
- if(file == NULL){
- file = DEFAULT_VIDEO_DEVICE;
+ int numPorts;
+ unsigned int channel, speed;
+
+ dc1394Handle = raw1394_new_handle();
+ if(dc1394Handle == NULL) {
+ perror("Unable to aquire a raw1394 handle.\n");
+ return -1;
}
+#if 0
if(v4lopen(file, &vd)) return -1;
video_file = strdup(file);
@@ -87,17 +169,48 @@
v4lsetdefaultnorm(&vd, norm);
v4lgetcapability(&vd);
+#endif
- if(!(vd.capability.type & VID_TYPE_CAPTURE)) {
- fprintf(stderr, "video_init: This device seems not to support video capturing.\n");
+ numPorts = getRaw1394Ports();
+ if(findCamera(numPorts)) {
+ fprintf(stderr, "Failed to find cameras.\n");
return -1;
}
+
+ {
+ dc1394_feature_set features;
+ if(dc1394_get_camera_feature_set(dc1394Handle, dc1394Camera.node, &features) != DC1394_SUCCESS) {
+ exit(-1);
+ }
+ dc1394_print_feature_set(&features);
+#if 0
if((vd.capability.type & VID_TYPE_TUNER)) {
video_hasTuner = 1;
video_frequencyTable = freq;
video_TVchannel = 0;
video_setfreq(0);
+#endif
+ }
+
+ if(dc1394_start_iso_transmission(dc1394Handle, dc1394Camera.node) != DC1394_SUCCESS) {
+ perror("Failed to start iso transmission.\n");
+ exit(-1);
}
+
+ if(dc1394_get_iso_channel_and_speed(dc1394Handle, dc1394Camera.node,
+ &channel, &speed) != DC1394_SUCCESS) {
+ fprintf(stderr, "unable to get the iso channel number.\n");
+ }
+
+ if(dc1394_dma_setup_capture(dc1394Handle, dc1394Camera.node, channel,
+ FORMAT_VGA_NONCOMPRESSED, MODE_640x480_YUV411,
+ SPEED_400, FRAMERATE_30, 4, 1,
+ NULL, &dc1394Camera) != DC1394_SUCCESS) {
+ perror("Failed to set DMA capture mode.\n");
+ exit(-1);
+ }
+
+#if 0
if(w == 0 && h == 0) {
w = DEFAULT_VIDEO_WIDTH;
h = DEFAULT_VIDEO_HEIGHT;
@@ -111,9 +224,10 @@
h = MINHEIGHT;
fprintf(stderr, "capturing size is set to %dx%d.\n", w, h);
}
+#endif
- video_width = w;
- video_height = h;
+ video_width = 640;
+ video_height = 480;
video_area = video_width * video_height;
framebuffer = (RGB32 *)malloc(video_area*sizeof(RGB32));
@@ -122,6 +236,7 @@
return -1;
}
+#if 0
if(v4lmaxchannel(&vd)) {
if(v4lsetchannel(&vd, channel)) return -1;
}
@@ -149,6 +264,10 @@
picture_hue = vd.picture.hue;
picture_colour = vd.picture.colour;
picture_contrast = vd.picture.contrast;
+#endif
+
+ video_set_grabformat(VIDEO_PALETTE_DCYUV411);
+ atexit(video_quit);
return 0;
}
@@ -156,20 +275,22 @@
/* close v4l device. */
void video_quit(void)
{
- v4lmunmap(&vd);
- v4lclose(&vd);
+ dc1394_dma_unlisten(dc1394Handle, &dc1394Camera);
+ dc1394_dma_release_camera(dc1394Handle, &dc1394Camera);
free(framebuffer);
}
/* Set the format of captured data. */
int video_setformat(int palette)
{
- return v4lsetpalette(&vd, palette);
+// return v4lsetpalette(&vd, palette);
+ return 0;
}
/* check supported pixel format */
int video_grab_check(int palette)
{
+#if 0
int ret;
v4lseterrorlevel(V4L_PERROR_NONE);
@@ -185,10 +306,13 @@
EXIT:
v4lseterrorlevel(V4L_PERROR_ALL);
return ret;
+#endif
+ return 0;
}
int video_set_grabformat(int palette)
{
+#if 0
if(palette == 0) {
if(video_grab_check(DEFAULT_PALETTE) == 0) {
converter = NULL;
@@ -204,6 +328,10 @@
return -1;
}
}
+#endif
+ if(!palette_check_supported_converter_toRGB32(palette, &converter, &converter_hflip)) {
+ return -1;
+ }
return 0;
}
@@ -211,17 +339,20 @@
/* Start the continuous grabbing */
int video_grabstart(void)
{
+#if 0
vd.frame = 0;
if(v4lgrabstart(&vd, 0) < 0)
return -1;
if(v4lgrabstart(&vd, 1) < 0)
return -1;
+#endif
return 0;
}
/* Stop the continuous grabbing */
int video_grabstop(void)
{
+#if 0
if(vd.framestat[vd.frame]) {
if(v4lsync(&vd, vd.frame) < 0)
return -1;
@@ -230,18 +361,24 @@
if(v4lsync(&vd, vd.frame ^ 1) < 0)
return -1;
}
+#endif
return 0;
}
/* Wait on the capturing image */
int video_syncframe(void)
{
- return v4lsyncf(&vd);
+ if(dc1394_dma_single_capture(&dc1394Camera) == DC1394_SUCCESS)
+ return 0;
+
+ return -1;
}
/* Start capturing next image */
int video_grabframe(void){
- return v4lgrabf(&vd);
+ dc1394_dma_done_with_buffer(&dc1394Camera);
+
+ return 0;
}
/* Returns a pointer to captured image */
@@ -249,17 +386,19 @@
{
if(converter) {
if(video_horizontalFlip) {
- (*converter_hflip)(v4lgetaddress(&vd), framebuffer, video_width, video_height);
+ (*converter_hflip)((unsigned char *)dc1394Camera.capture_buffer,
+ framebuffer, video_width, video_height);
} else {
- (*converter)(v4lgetaddress(&vd), framebuffer, video_width, video_height);
+ (*converter)((unsigned char *)dc1394Camera.capture_buffer,
+ framebuffer, video_width, video_height);
}
return (unsigned char *)framebuffer;
} else if(video_horizontalFlip) {
- image_hflip((RGB32 *)v4lgetaddress(&vd), framebuffer,
+ image_hflip((RGB32 *)dc1394Camera.capture_buffer, framebuffer,
video_width, video_height);
return (unsigned char *)framebuffer;
} else {
- return v4lgetaddress(&vd);
+ return (unsigned char *)dc1394Camera.capture_buffer;
}
}
@@ -267,6 +406,7 @@
* the size is set to default size. */
int video_changesize(int width, int height)
{
+#if 0
if(width == 0 || height == 0) {
width = DEFAULT_VIDEO_WIDTH;
height = DEFAULT_VIDEO_HEIGHT;
@@ -275,11 +415,15 @@
video_height = height;
return v4lgrabinit(&vd, width, height);
+#endif
+ return 0;
}
/* change video_TVchannel to video_TVchannel+v */
int video_setfreq(int v)
{
+ return 0;
+#if 0
if(video_hasTuner && (video_frequencyTable >= 0)) {
video_TVchannel += v;
while(video_TVchannel<0) {
@@ -291,48 +435,59 @@
} else {
return 0;
}
+#endif
}
/* increase brightness value with v */
void video_change_brightness(int v)
{
+#if 0
picture_brightness += v;
if(picture_brightness < 0) picture_brightness = 0;
if(picture_brightness > 65535) picture_brightness = 65535;
v4lsetpicture(&vd, picture_brightness, -1, -1, -1, -1);
+#endif
}
/* increase hue value with v */
void video_change_hue(int v)
{
+#if 0
picture_hue += v;
if(picture_hue < 0) picture_hue = 0;
if(picture_hue > 65535) picture_hue = 65535;
v4lsetpicture(&vd, -1, picture_hue, -1, -1, -1);
+#endif
}
/* increase color value with v */
void video_change_color(int v)
{
+#if 0
picture_colour += v;
if(picture_colour < 0) picture_colour = 0;
if(picture_colour > 65535) picture_colour = 65535;
v4lsetpicture(&vd, -1, -1, picture_colour, -1, -1);
+#endif
}
/* increase contrast value with v */
void video_change_contrast(int v)
{
+#if 0
picture_contrast += v;
if(picture_contrast < 0) picture_contrast = 0;
if(picture_contrast > 65535) picture_contrast = 65535;
v4lsetpicture(&vd, -1, -1, -1, picture_contrast, -1);
+#endif
}
/* change channel: stops video grabbing at first, then recreate v4ldevice
* object. */
int video_change_channel(int channel)
{
+ return 0;
+#if 0
int ret = 0;
int maxch;
@@ -346,11 +501,14 @@
video_grabstart();
return ret;
+#endif
}
/* retry grabbing */
int video_retry(void)
{
+ return 0;
+#if 0
video_quit();
return video_init(
video_file,
@@ -360,6 +518,7 @@
video_width,
video_height,
video_palette);
+#endif
}
/*