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
,
51 libvlc_picture_t
*pic
= malloc( sizeof( *pic
) );
52 if ( unlikely( pic
== NULL
) )
54 vlc_atomic_rc_init( &pic
->rc
);
56 pic
->time
= MS_FROM_VLC_TICK( input
->date
);
60 case libvlc_picture_Argb
:
61 format
= VLC_CODEC_ARGB
;
63 case libvlc_picture_Jpg
:
64 format
= VLC_CODEC_JPEG
;
66 case libvlc_picture_Png
:
67 format
= VLC_CODEC_PNG
;
70 vlc_assert_unreachable();
72 if ( picture_Export( p_obj
, &pic
->converted
, &pic
->fmt
,
73 input
, format
, width
, height
, crop
) != VLC_SUCCESS
)
82 void libvlc_picture_retain( libvlc_picture_t
* pic
)
84 vlc_atomic_rc_inc( &pic
->rc
);
87 void libvlc_picture_release( libvlc_picture_t
* pic
)
89 if ( vlc_atomic_rc_dec( &pic
->rc
) == false )
91 video_format_Clean( &pic
->fmt
);
93 block_Release( pic
->converted
);
97 int libvlc_picture_save( const libvlc_picture_t
* pic
, const char* path
)
99 FILE* file
= vlc_fopen( path
, "wb" );
102 size_t res
= fwrite( pic
->converted
->p_buffer
,
103 pic
->converted
->i_buffer
, 1, file
);
105 return res
== 1 ? 0 : -1;
108 const unsigned char* libvlc_picture_get_buffer( const libvlc_picture_t
* pic
,
111 assert( size
!= NULL
);
112 *size
= pic
->converted
->i_buffer
;
113 return pic
->converted
->p_buffer
;
116 libvlc_picture_type_t
libvlc_picture_type( const libvlc_picture_t
* pic
)
121 unsigned int libvlc_picture_get_stride( const libvlc_picture_t
*pic
)
123 assert( pic
->type
== libvlc_picture_Argb
);
124 return pic
->fmt
.i_width
* pic
->fmt
.i_bits_per_pixel
/ 8;
127 unsigned int libvlc_picture_get_width( const libvlc_picture_t
* pic
)
129 return pic
->fmt
.i_visible_width
;
132 unsigned int libvlc_picture_get_height( const libvlc_picture_t
* pic
)
134 return pic
->fmt
.i_visible_height
;
137 libvlc_time_t
libvlc_picture_get_time( const libvlc_picture_t
* pic
)