1.1 --- a/src/video/directfb/SDL_DirectFB_render.c Sun Oct 04 03:38:01 2009 +0000
1.2 +++ b/src/video/directfb/SDL_DirectFB_render.c Sun Oct 04 04:03:37 2009 +0000
1.3 @@ -499,12 +499,20 @@
1.4 DirectFB_TextureData *data;
1.5 DFBResult ret;
1.6 DFBSurfaceDescription dsc;
1.7 + DFBSurfacePixelFormat pixelformat;
1.8
1.9 SDL_DFB_CALLOC(data, 1, sizeof(*data));
1.10 texture->driverdata = data;
1.11
1.12 + /* find the right pixelformat */
1.13 + pixelformat = SDLToDFBPixelFormat(texture->format);
1.14 + if (pixelformat == DSPF_UNKNOWN) {
1.15 + SDL_SetError("Unknown pixel format %d\n", data->format);
1.16 + goto error;
1.17 + }
1.18 +
1.19 data->format = texture->format;
1.20 - data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
1.21 + data->pitch = texture->w * DFB_BYTES_PER_PIXEL(pixelformat);
1.22
1.23 if (DirectFB_AcquireVidLayer(renderer, texture) != 0) {
1.24 /* fill surface description */
1.25 @@ -525,14 +533,7 @@
1.26 dsc.caps |= DSCAPS_VIDEOONLY;
1.27 #endif
1.28
1.29 - /* find the right pixelformat */
1.30 -
1.31 - dsc.pixelformat = SDLToDFBPixelFormat(data->format);
1.32 - if (dsc.pixelformat == DSPF_UNKNOWN) {
1.33 - SDL_SetError("Unknown pixel format %d\n", data->format);
1.34 - goto error;
1.35 - }
1.36 -
1.37 + dsc.pixelformat = pixelformat;
1.38 data->pixels = NULL;
1.39
1.40 /* Create the surface */
1.41 @@ -550,8 +551,13 @@
1.42 #endif
1.43
1.44 if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
1.45 - data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
1.46 - SDL_DFB_CALLOC(data->pixels, 1, texture->h * data->pitch);
1.47 + /* 3 plane YUVs return 1 bpp, but we need more space for other planes */
1.48 + if(texture->format == SDL_PIXELFORMAT_YV12 ||
1.49 + texture->format == SDL_PIXELFORMAT_IYUV) {
1.50 + SDL_DFB_CALLOC(data->pixels, 1, (texture->h * data->pitch * 3 + texture->h * data->pitch * 3 % 2) / 2);
1.51 + } else {
1.52 + SDL_DFB_CALLOC(data->pixels, 1, texture->h * data->pitch);
1.53 + }
1.54 }
1.55
1.56 return 0;
1.57 @@ -726,6 +732,24 @@
1.58 src += pitch;
1.59 dst += dpitch;
1.60 }
1.61 + /* copy other planes for 3 plane formats */
1.62 + if (texture->format == SDL_PIXELFORMAT_YV12 ||
1.63 + texture->format == SDL_PIXELFORMAT_IYUV) {
1.64 + src = (Uint8 *) pixels + texture->h * pitch;
1.65 + dst = (Uint8 *) dpixels + texture->h * dpitch + rect->y * dpitch / 4 + rect->x * bpp / 2;
1.66 + for (row = 0; row < rect->h / 2; ++row) {
1.67 + SDL_memcpy(dst, src, length / 2);
1.68 + src += pitch / 2;
1.69 + dst += dpitch / 2;
1.70 + }
1.71 + src = (Uint8 *) pixels + texture->h * pitch + texture->h * pitch / 4;
1.72 + dst = (Uint8 *) dpixels + texture->h * dpitch + texture->h * dpitch / 4 + rect->y * dpitch / 4 + rect->x * bpp / 2;
1.73 + for (row = 0; row < rect->h / 2; ++row) {
1.74 + SDL_memcpy(dst, src, length / 2);
1.75 + src += pitch / 2;
1.76 + dst += dpitch / 2;
1.77 + }
1.78 + }
1.79 SDL_DFB_CHECKERR(data->surface->Unlock(data->surface));
1.80 return 0;
1.81 error:
1.82 @@ -759,7 +783,7 @@
1.83 *pixels =
1.84 (void *) ((Uint8 *) texturedata->pixels +
1.85 rect->y * texturedata->pitch +
1.86 - rect->x * SDL_BYTESPERPIXEL(texture->format));
1.87 + rect->x * DFB_BYTES_PER_PIXEL(SDLToDFBPixelFormat(texture->format)));
1.88 *pitch = texturedata->pitch;
1.89 }
1.90 return 0;
1.91 @@ -916,7 +940,7 @@
1.92 if (texturedata->dirty.list) {
1.93 SDL_DirtyRect *dirty;
1.94 void *pixels;
1.95 - int bpp = SDL_BYTESPERPIXEL(texture->format);
1.96 + int bpp = DFB_BYTES_PER_PIXEL(SDLToDFBPixelFormat(texture->format));
1.97 int pitch = texturedata->pitch;
1.98
1.99 for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {