-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovie.c
More file actions
97 lines (92 loc) · 2.8 KB
/
Copy pathMovie.c
File metadata and controls
97 lines (92 loc) · 2.8 KB
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
/* Movie.c */
/* William Scotten's code */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "DIPs.h"
#include "Movie.h"
int clip(int x)
{ x = ((x > 255) ? 255 : (x < 0) ? 0 : x);
return x;
}
/* Allocate the memory space for the movie and the memory space */
/* for the frame list. Return the pointer to the movie. */
MOVIE *CreateMovie(void)
{
MOVIE *movie;
movie = malloc(sizeof(MOVIE));
if (! movie)
{ perror("Out of memory! Aborting...");
exit(10);}
movie->Frames = NULL;
return movie;
}
/* Release the memory space for the frame list. */
/* Release the memory space for the movie. */
void DeleteMovie(MOVIE *movie)
{
assert(movie);
assert(movie->Frames);
DeleteImageList(movie->Frames);
movie->Frames = NULL;
free(movie);
}
/* Convert a YUV movie to a RGB movie */
void YUV2RGBMovie(MOVIE *movie)
{
int x, y;
int C, D, E, R, G, B, Y, U, V;
IENTRY *curr;
curr = movie->Frames->First;
while (curr != NULL) {
curr->RGBImage = CreateImage(curr->YUVImage->Width, curr->YUVImage->Height);
for (y = 0; y < curr->YUVImage->Height; y++) {
for (x = 0; x < curr->YUVImage->Width; x++) {
Y = GetPixelY(curr->YUVImage, x, y);
U = GetPixelU(curr->YUVImage, x, y);
V = GetPixelV(curr->YUVImage, x, y);
C = Y - 16;
D = U - 128;
E = V - 128;
R = clip(( 298 * C + 409 * E + 128) >> 8);
G = clip(( 298 * C - 100 * D - 208 * E + 128) >> 8);
B = clip(( 298 * C + 516 * D + 128) >> 8);
SetPixelR(curr->RGBImage, x, y, R);
SetPixelG(curr->RGBImage, x, y, G);
SetPixelB(curr->RGBImage, x, y, B);
}
}
DeleteYUVImage(curr->YUVImage);
curr->YUVImage = NULL;
curr = curr-> Next;
}
}
/* Convert a RGB movie to a YUV movie */
void RGB2YUVMovie(MOVIE *movie)
{
int x, y;
int R, G, B, Y, U, V;
IENTRY *curr;
assert(movie->Frames->First);
curr = movie->Frames->First;
while (curr != NULL) {
curr->YUVImage = CreateYUVImage(curr->RGBImage->Width,
curr->RGBImage->Height);
for (y = 0; y < curr->YUVImage->Height; y++) {
for (x = 0; x < curr->YUVImage->Width; x++) {
R = GetPixelR(curr->RGBImage, x, y);
G = GetPixelG(curr->RGBImage, x, y);
B = GetPixelB(curr->RGBImage, x, y);
Y = clip( ( ( 66 * R + 129 * G + 25 * B + 128) >> 8) + 16 );
U = clip( ( ( -38 * R - 74 * G + 112 * B + 128) >> 8) + 128 );
V = clip( ( ( 112 * R - 94 * G - 18 * B + 128) >> 8) + 128 );
SetPixelY(curr->YUVImage, x, y, Y);
SetPixelU(curr->YUVImage, x, y, U);
SetPixelV(curr->YUVImage, x, y, V);
}
}
DeleteImage(curr->RGBImage);
curr->RGBImage = NULL;
curr = curr->Next;
}
}