let surface_to_raw (surface:Sdlvideo.surface) =
        let fmt  = Sdlvideo.surface_format surface in
        let (_,height,pitch) = Sdlvideo.surface_dims surface in
        let buffer_len = height * pitch in
        Sdlvideo.lock surface ;
        let src = Sdlvideo.pixel_data surface in
        let dest = Raw.create `ubyte buffer_len in
        let rec cp_one_byte index =
                if index >= buffer_len then ()
                else begin
                        let abyte = (Bigarray.Array1.get src index) in
                        Raw.set dest index abyte ;
                        cp_one_byte (index + 1)
                end
        in
        cp_one_byte 0 ;
        Sdlvideo.unlock surface ;
        dest