[xiph-commits] r3167 - liboggplay/trunk/python
shans at svn.annodex.net
shans at svn.annodex.net
Sun Jul 22 23:36:07 PDT 2007
Author: shans
Date: 2007-07-22 23:36:07 -0700 (Sun, 22 Jul 2007)
New Revision: 3167
Modified:
liboggplay/trunk/python/liboggplay.i
Log:
Improvements to python wrapper
Modified: liboggplay/trunk/python/liboggplay.i
===================================================================
--- liboggplay/trunk/python/liboggplay.i 2007-07-20 07:29:34 UTC (rev 3166)
+++ liboggplay/trunk/python/liboggplay.i 2007-07-23 06:36:07 UTC (rev 3167)
@@ -81,6 +81,82 @@
oggplay_set_data_callback(me, PythonCallBack, pycallback);
Py_INCREF(pycallback);
}
+
+#define CLAMP(v) ((v) > 255 ? 255 : (v) < 0 ? 0 : (v))
+
+typedef struct {
+ unsigned char *data;
+ int width;
+ int height;
+} OggPlayVideoFrame;
+
+OggPlayVideoFrame *oggplay_generate_frame(OggPlay *p, int track,
+ OggPlayDataHeader *h) {
+
+ OggPlayVideoData *yuv = oggplay_callback_info_get_video_data(h);
+ int width;
+ int height;
+
+ oggplay_get_video_y_size(p, track, &width, &height);
+
+ unsigned char * ptry = yuv->y;
+ unsigned char * ptru = yuv->u;
+ unsigned char * ptrv = yuv->v;
+ unsigned char * ptro = malloc(width * height * 4);
+ unsigned char * out = ptro;
+ unsigned char * ptro2;
+ int i, j;
+
+
+ for (i = 0; i < height; i++) {
+ ptro2 = ptro;
+ for (j = 0; j < width; j += 2) {
+
+ short pr, pg, pb;
+ short r, g, b;
+
+ //pr = ((128 + (ptrv[j/2] - 128) * 292) >> 8) - 16; /* 1.14 * 256 */
+ pr = (-41344 + ptrv[j/2] * 292) >> 8;
+ //pg = ((128 - (ptru[j/2] - 128) * 101 - (ptrv[j/2] - 128) * 149) >> 8)-16;
+ // /* 0.395 & 0.581 */
+ pg = (28032 - ptru[j/2] * 101 - ptrv[j/2] * 149) >> 8;
+ //pb = ((128 + (ptru[j/2] - 128) * 520) >> 8) - 16; /* 2.032 */
+ pb = (-70528 + ptru[j/2] * 520) >> 8;
+
+ r = ptry[j] + pr;
+ g = ptry[j] + pg;
+ b = ptry[j] + pb;
+
+ *ptro2++ = CLAMP(r);
+ *ptro2++ = CLAMP(g);
+ *ptro2++ = CLAMP(b);
+ *ptro2++ = 255;
+
+ r = ptry[j + 1] + pr;
+ g = ptry[j + 1] + pg;
+ b = ptry[j + 1] + pb;
+
+ *ptro2++ = CLAMP(r);
+ *ptro2++ = CLAMP(g);
+ *ptro2++ = CLAMP(b);
+ *ptro2++ = 255;
+ }
+ ptry += width;
+ if (i & 1) {
+ ptru += width/2;
+ ptrv += width/2;
+ }
+ ptro += width * 4;
+ }
+
+ OggPlayVideoFrame *r = malloc(sizeof(OggPlayVideoFrame));
+ r->data = out;
+ r->width = width;
+ r->height = height;
+
+ return r;
+}
+
%}
%typemap(out) OggPlayDataHeader ** {
@@ -93,6 +169,32 @@
}
}
+%typemap(argout) (int *width, int *height) {
+ PyObject *o1 = PyInt_FromLong(*$1);
+ PyObject *o2 = PyInt_FromLong(*$2);
+ $result = PyList_New(0);
+ PyList_Append($result, o1);
+ PyList_Append($result, o2);
+ Py_XDECREF(o1);
+ Py_XDECREF(o2);
+}
+
+%typemap(in,numinputs=0) (int *width, int *height) (int a, int b) {
+ $1 = &a;
+ $2 = &b;
+}
+
+%typemap(out) (OggPlayVideoFrame *) {
+ $result = PyTuple_New(2);
+ PyTuple_SetItem($result, 0,
+ Py_BuildValue("s#", $1->data, $1->width * $1->height * 4));
+ PyTuple_SetItem($result, 1,
+ Py_BuildValue("ii", $1->width, $1->height));
+ free($1->data);
+ free($1);
+
+}
+
typedef long long ogg_int64_t;
OggPlay *
@@ -107,6 +209,15 @@
void
oggplay_set_data_pycallback(OggPlay *me, PyObject *pycallback);
+typedef struct {
+ unsigned char *data;
+ int width;
+ int height;
+} OggPlayVideoFrame;
+
+OggPlayVideoFrame *oggplay_generate_frame(OggPlay *p, int track,
+ OggPlayDataHeader *h);
+
OggPlayErrorCode
oggplay_set_callback_num_frames(OggPlay *me, int stream, int frames);
@@ -114,10 +225,10 @@
oggplay_set_offset(OggPlay *me, int track, ogg_int64_t offset);
OggPlayErrorCode
-oggplay_get_video_y_size(OggPlay *me, int track, int *y_width, int *y_height);
+oggplay_get_video_y_size(OggPlay *me, int track, int *width, int *height);
OggPlayErrorCode
-oggplay_get_video_uv_size(OggPlay *me, int track, int *uv_width, int *uv_height);
+oggplay_get_video_uv_size(OggPlay *me, int track, int *width, int *height);
OggPlayErrorCode
oggplay_get_audio_channels(OggPlay *me, int track, int *channels);
@@ -173,12 +284,6 @@
OggPlayErrorCode
oggplay_set_track_active(OggPlay *me, int track_num);
-typedef struct {
- unsigned char * y;
- unsigned char * u;
- unsigned char * v;
-} OggPlayVideoData;
-
typedef void * OggPlayAudioData;
typedef char OggPlayTextData;
More information about the commits
mailing list