9 #define BLOCK_SIZE (BLOCK_WIDTH * BLOCK_HEIGHT)
10 #define MACROBLOCK_WIDTH 16
11 #define MACROBLOCK_HEIGHT 16
12 #define MACROBLOCK_WIDTH_IN_BLOCKS (MACROBLOCK_WIDTH / BLOCK_WIDTH)
13 #define MACROBLOCK_HEIGHT_IN_BLOCKS (MACROBLOCK_HEIGHT / BLOCK_HEIGHT)
14 #define BLOCKS_PER_MACROBLOCK 6
16 #define INPUT_WIDTH 16
17 #define INPUT_HEIGHT 16
18 #define INPUT_WIDTH_IN_MACROBLOCKS (INPUT_WIDTH / MACROBLOCK_WIDTH)
19 #define INPUT_HEIGHT_IN_MACROBLOCKS (INPUT_HEIGHT / MACROBLOCK_HEIGHT)
20 #define NUM_MACROBLOCKS (INPUT_WIDTH_IN_MACROBLOCKS * INPUT_HEIGHT_IN_MACROBLOCKS)
22 #define DEFAULT_OUTPUT_WIDTH INPUT_WIDTH
23 #define DEFAULT_OUTPUT_HEIGHT INPUT_HEIGHT
24 #define DEFAULT_ACCEPTABLE_ERR 0.01
26 void ParseArgs(int argc
, char **argv
, unsigned int *output_width
, unsigned int *output_height
, double *acceptable_error
, int *prompt
);
27 void Gradient(short *block
, unsigned int start
, unsigned int stop
, int horizontal
);
29 void ParseArgs(int argc
, char **argv
, unsigned int *output_width
, unsigned int *output_height
, double *acceptable_error
, int *prompt
)
34 *output_width
= DEFAULT_OUTPUT_WIDTH
;
35 *output_height
= DEFAULT_OUTPUT_WIDTH
;
36 *acceptable_error
= DEFAULT_ACCEPTABLE_ERR
;
39 for (i
= 1; i
< argc
&& !fail
; ++i
)
41 if (!strcmp(argv
[i
], "-w"))
43 if (sscanf(argv
[++i
], "%u", output_width
) != 1)
46 else if (!strcmp(argv
[i
], "-h"))
48 if (sscanf(argv
[++i
], "%u", output_height
) != 1)
51 else if (!strcmp(argv
[i
], "-e"))
53 if (sscanf(argv
[++i
], "%lf", acceptable_error
) != 1)
56 else if (strcmp(argv
[i
], "-n"))
68 "Usage: %s [options]\n"
69 "\t-w <width>\tOutput width\n"
70 "\t-h <height>\tOutput height\n"
71 "\t-e <error>\tAcceptable margin of error per pixel, from 0 to 1\n"
72 "\t-n\tDon't prompt for quit\n",
77 void Gradient(short *block
, unsigned int start
, unsigned int stop
, int horizontal
)
80 unsigned int range
= stop
- start
;
84 for (y
= 0; y
< BLOCK_HEIGHT
; ++y
)
85 for (x
= 0; x
< BLOCK_WIDTH
; ++x
)
86 block
[y
* BLOCK_WIDTH
+ x
] = (short)(start
+ range
* (x
/ (float)(BLOCK_WIDTH
- 1)));
90 for (y
= 0; y
< BLOCK_HEIGHT
; ++y
)
91 for (x
= 0; x
< BLOCK_WIDTH
; ++x
)
92 block
[y
* BLOCK_WIDTH
+ x
] = (short)(start
+ range
* (y
/ (float)(BLOCK_HEIGHT
- 1)));
96 int main(int argc
, char **argv
)
98 unsigned int output_width
;
99 unsigned int output_height
;
100 double acceptable_error
;
104 const unsigned int mc_types
[2] = {XVMC_MOCOMP
| XVMC_MPEG_2
, XVMC_IDCT
| XVMC_MPEG_2
};
107 unsigned int is_overlay
, intra_unsigned
;
111 XvMCBlockArray block_array
;
112 XvMCMacroBlockArray mb_array
;
113 int mbx
, mby
, bx
, by
;
118 ParseArgs(argc
, argv
, &output_width
, &output_height
, &acceptable_error
, &prompt
);
120 display
= XOpenDisplay(NULL
);
127 XVMC_CHROMA_FORMAT_420
,
136 XCloseDisplay(display
);
137 error(1, 0, "Error, unable to find a good port.\n");
142 Atom xv_colorkey
= XInternAtom(display
, "XV_COLORKEY", 0);
143 XvGetPortAttribute(display
, port_num
, xv_colorkey
, &colorkey
);
146 root
= XDefaultRootWindow(display
);
147 window
= XCreateSimpleWindow(display
, root
, 0, 0, output_width
, output_height
, 0, 0, colorkey
);
149 assert(XvMCCreateContext(display
, port_num
, surface_type_id
, INPUT_WIDTH
, INPUT_HEIGHT
, XVMC_DIRECT
, &context
) == Success
);
150 assert(XvMCCreateSurface(display
, &context
, &surface
) == Success
);
151 assert(XvMCCreateBlocks(display
, &context
, NUM_MACROBLOCKS
* BLOCKS_PER_MACROBLOCK
, &block_array
) == Success
);
152 assert(XvMCCreateMacroBlocks(display
, &context
, NUM_MACROBLOCKS
, &mb_array
) == Success
);
154 mb
= mb_array
.macro_blocks
;
155 blocks
= block_array
.blocks
;
157 for (mby
= 0; mby
< INPUT_HEIGHT_IN_MACROBLOCKS
; ++mby
)
158 for (mbx
= 0; mbx
< INPUT_WIDTH_IN_MACROBLOCKS
; ++mbx
)
162 mb
->macroblock_type
= XVMC_MB_TYPE_INTRA
;
163 /*mb->motion_type = ;*/
164 /*mb->motion_vertical_field_select = ;*/
165 mb
->dct_type
= XVMC_DCT_TYPE_FRAME
;
166 /*mb->PMV[0][0][0] = ;
173 mb->PMV[1][1][1] = ;*/
174 mb
->index
= (mby
* INPUT_WIDTH_IN_MACROBLOCKS
+ mbx
) * BLOCKS_PER_MACROBLOCK
;
175 mb
->coded_block_pattern
= 0x3F;
179 for (by
= 0; by
< MACROBLOCK_HEIGHT_IN_BLOCKS
; ++by
)
180 for (bx
= 0; bx
< MACROBLOCK_WIDTH_IN_BLOCKS
; ++bx
)
182 const int start
= 16, stop
= 235, range
= stop
- start
;
187 (short)(start
+ range
* ((mbx
* MACROBLOCK_WIDTH
+ bx
* BLOCK_WIDTH
) / (float)(INPUT_WIDTH
- 1))),
188 (short)(start
+ range
* ((mbx
* MACROBLOCK_WIDTH
+ bx
* BLOCK_WIDTH
+ BLOCK_WIDTH
- 1) / (float)(INPUT_WIDTH
- 1))),
192 blocks
+= BLOCK_SIZE
;
195 for (by
= 0; by
< MACROBLOCK_HEIGHT_IN_BLOCKS
/ 2; ++by
)
196 for (bx
= 0; bx
< MACROBLOCK_WIDTH_IN_BLOCKS
/ 2; ++bx
)
198 const int start
= 16, stop
= 240, range
= stop
- start
;
203 (short)(start
+ range
* ((mbx
* MACROBLOCK_WIDTH
+ bx
* BLOCK_WIDTH
) / (float)(INPUT_WIDTH
- 1))),
204 (short)(start
+ range
* ((mbx
* MACROBLOCK_WIDTH
+ bx
* BLOCK_WIDTH
+ BLOCK_WIDTH
- 1) / (float)(INPUT_WIDTH
- 1))),
208 blocks
+= BLOCK_SIZE
;
213 (short)(start
+ range
* ((mbx
* MACROBLOCK_WIDTH
+ bx
* BLOCK_WIDTH
) / (float)(INPUT_WIDTH
- 1))),
214 (short)(start
+ range
* ((mbx
* MACROBLOCK_WIDTH
+ bx
* BLOCK_WIDTH
+ BLOCK_WIDTH
- 1) / (float)(INPUT_WIDTH
- 1))),
218 blocks
+= BLOCK_SIZE
;
222 XSelectInput(display
, window
, ExposureMask
| KeyPressMask
);
223 XMapWindow(display
, window
);
226 /* Test NULL context */
227 assert(XvMCRenderSurface(display
, NULL
, XVMC_FRAME_PICTURE
, &surface
, NULL
, NULL
, 0, NUM_MACROBLOCKS
, 0, &mb_array
, &block_array
) == XvMCBadContext
);
228 /* Test NULL surface */
229 assert(XvMCRenderSurface(display
, &context
, XVMC_FRAME_PICTURE
, NULL
, NULL
, NULL
, 0, NUM_MACROBLOCKS
, 0, &mb_array
, &block_array
) == XvMCBadSurface
);
230 /* Test bad picture structure */
231 assert(XvMCRenderSurface(display
, &context
, 0, &surface
, NULL
, NULL
, 0, NUM_MACROBLOCKS
, 0, &mb_array
, &block_array
) == BadValue
);
232 /* Test valid params */
233 assert(XvMCRenderSurface(display
, &context
, XVMC_FRAME_PICTURE
, &surface
, NULL
, NULL
, 0, NUM_MACROBLOCKS
, 0, &mb_array
, &block_array
) == Success
);
235 /* Test NULL surface */
236 assert(XvMCPutSurface(display
, NULL
, window
, 0, 0, INPUT_WIDTH
, INPUT_HEIGHT
, 0, 0, output_width
, output_height
, XVMC_FRAME_PICTURE
) == XvMCBadSurface
);
237 /* Test bad window */
238 /* XXX: X halts with a bad drawable for some reason, doesn't return BadDrawable as expected */
239 /*assert(XvMCPutSurface(display, &surface, 0, 0, 0, width, height, 0, 0, width, height, XVMC_FRAME_PICTURE) == BadDrawable);*/
243 puts("Press any button to quit...");
247 if (XPending(display
) > 0)
251 XNextEvent(display
, &event
);
257 /* Test valid params */
262 display
, &surface
, window
,
263 0, 0, INPUT_WIDTH
, INPUT_HEIGHT
,
264 0, 0, output_width
, output_height
,
280 assert(XvMCDestroyBlocks(display
, &block_array
) == Success
);
281 assert(XvMCDestroyMacroBlocks(display
, &mb_array
) == Success
);
282 assert(XvMCDestroySurface(display
, &surface
) == Success
);
283 assert(XvMCDestroyContext(display
, &context
) == Success
);
285 XvUngrabPort(display
, port_num
, CurrentTime
);
286 XDestroyWindow(display
, window
);
287 XCloseDisplay(display
);