1 /*****************************************************************************
2 * picture.c: libvlc API picture management
3 *****************************************************************************
4 * Copyright (C) 2018 VLC authors and VideoLAN
6 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
27 #include <vlc/libvlc.h>
28 #include <vlc/libvlc_picture.h>
30 #include <vlc_atomic.h>
31 #include <vlc_picture.h>
32 #include <vlc_block.h>
35 #include "picture_internal.h"
37 struct libvlc_picture_t
40 libvlc_picture_type_t type
;
46 libvlc_picture_t
* libvlc_picture_new( vlc_object_t
* p_obj
, picture_t
* input
,
47 libvlc_picture_type_t type
,
48 unsigned int width
, unsigned int height
)
50 libvlc_picture_t
*pic
= malloc( sizeof( *pic
) );
51 if ( unlikely( pic
== NULL
) )
53 vlc_atomic_rc_init( &pic
->rc
);
55 pic
->time
= MS_FROM_VLC_TICK( input
->date
);
59 case libvlc_picture_Argb
:
60 format
= VLC_CODEC_ARGB
;
62 case libvlc_picture_Jpg
:
63 format
= VLC_CODEC_JPEG
;
65 case libvlc_picture_Png
:
66 format
= VLC_CODEC_PNG
;
69 vlc_assert_unreachable();
71 if ( picture_Export( p_obj
, &pic
->converted
, &pic
->fmt
,
72 input
, format
, width
, height
) != VLC_SUCCESS
)
81 void libvlc_picture_retain( libvlc_picture_t
* pic
)
83 vlc_atomic_rc_inc( &pic
->rc
);
86 void libvlc_picture_release( libvlc_picture_t
* pic
)
88 if ( vlc_atomic_rc_dec( &pic
->rc
) == false )
90 video_format_Clean( &pic
->fmt
);
92 block_Release( pic
->converted
);
96 int libvlc_picture_save( const libvlc_picture_t
* pic
, const char* path
)
98 FILE* file
= vlc_fopen( path
, "wb" );
101 size_t res
= fwrite( pic
->converted
->p_buffer
,
102 pic
->converted
->i_buffer
, 1, file
);
104 return res
== 1 ? 0 : -1;
107 const unsigned char* libvlc_picture_get_buffer( const libvlc_picture_t
* pic
,
110 assert( size
!= NULL
);
111 *size
= pic
->converted
->i_buffer
;
112 return pic
->converted
->p_buffer
;
115 libvlc_picture_type_t
libvlc_picture_type( const libvlc_picture_t
* pic
)
120 unsigned int libvlc_picture_get_stride( const libvlc_picture_t
*pic
)
122 assert( pic
->type
== libvlc_picture_Argb
);
123 return pic
->fmt
.i_width
* pic
->fmt
.i_bits_per_pixel
/ 8;
126 unsigned int libvlc_picture_get_width( const libvlc_picture_t
* pic
)
128 return pic
->fmt
.i_visible_width
;
131 unsigned int libvlc_picture_get_height( const libvlc_picture_t
* pic
)
133 return pic
->fmt
.i_visible_height
;
136 libvlc_time_t
libvlc_picture_get_time( const libvlc_picture_t
* pic
)