framework: remove global profile, rather share one mlt_profile across a service netwo...
[melted] / src / modules / sdl / producer_sdl_image.c
index d1c13f9..ee88102 100644 (file)
@@ -3,22 +3,22 @@
  * Copyright (C) 2005 Visual Media FX
  * Author: Charles Yates <charles.yates@gmail.com>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "producer_sdl_image.h"
+#include <framework/mlt_producer.h>
 #include <framework/mlt_frame.h>
 #include <framework/mlt_pool.h>
 
@@ -37,6 +37,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **image, mlt_image_forma
 {
        mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
        SDL_Surface *surface = mlt_properties_get_data( properties, "surface", NULL );
+       SDL_Surface *converted = NULL;
        uint8_t *alpha;
 
        *width = surface->w;
@@ -45,6 +46,20 @@ static int producer_get_image( mlt_frame frame, uint8_t **image, mlt_image_forma
        *image = mlt_pool_alloc( *width * *height * 2 );
        alpha = mlt_pool_alloc( *width * *height );
 
+       if ( surface->format->BitsPerPixel != 32 && surface->format->BitsPerPixel != 24 )
+       {
+               SDL_PixelFormat fmt;
+               fmt.BitsPerPixel = 24;
+               fmt.BytesPerPixel = 3;
+               fmt.Rshift = 16;
+               fmt.Gshift = 8;
+               fmt.Bshift = 0;
+               fmt.Rmask = 0xff << 16;
+               fmt.Gmask = 0xff << 8;
+               fmt.Bmask = 0xff;
+               converted = SDL_ConvertSurface( surface, &fmt, 0 );
+       }
+
        switch( surface->format->BitsPerPixel )
        {
                case 32:
@@ -55,9 +70,14 @@ static int producer_get_image( mlt_frame frame, uint8_t **image, mlt_image_forma
                        memset( alpha, 255, *width * *height );
                        break;
                default:
+                       mlt_convert_rgb24_to_yuv422( converted->pixels, *width, *height, converted->pitch, *image );
+                       memset( alpha, 255, *width * *height );
                        break;
        }
-       
+
+       if ( converted )
+               SDL_FreeSurface( converted );
+
        // Update the frame
        mlt_properties_set_data( properties, "image", *image, *width * *height * 2, mlt_pool_release, NULL );
        mlt_properties_set_data( properties, "alpha", alpha, *width * *height, mlt_pool_release, NULL );
@@ -154,7 +174,7 @@ static SDL_Surface *load_image( mlt_producer producer )
 static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
 {
        // Generate a frame
-       *frame = mlt_frame_init( );
+       *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
 
        if ( *frame != NULL )
        {
@@ -197,7 +217,7 @@ static void producer_close( mlt_producer producer )
        free( producer );
 }
 
-mlt_producer producer_sdl_image_init( char *file )
+mlt_producer producer_sdl_image_init( mlt_profile profile, mlt_service_type type, const char *id, char *file )
 {
        mlt_producer producer = calloc( 1, sizeof( struct mlt_producer_s ) );
        if ( producer != NULL && mlt_producer_init( producer, NULL ) == 0 )