1 /*****************************************************************************
2 * image.c : wrapper for image reading/writing facilities
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Author: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
26 * This file contains the functions to handle the image_handler_t type
29 /*****************************************************************************
31 *****************************************************************************/
34 #include <vlc/decoder.h>
35 #include <vlc_filter.h>
36 #include <vlc_image.h>
38 static picture_t *ImageRead( image_handler_t *, block_t *,
39 video_format_t *, video_format_t * );
40 static picture_t *ImageReadUrl( image_handler_t *, const char *,
41 video_format_t *, video_format_t * );
42 static block_t *ImageWrite( image_handler_t *, picture_t *,
43 video_format_t *, video_format_t * );
44 static int ImageWriteUrl( image_handler_t *, picture_t *,
45 video_format_t *, video_format_t *, const char * );
47 static picture_t *ImageConvert( image_handler_t *, picture_t *,
48 video_format_t *, video_format_t * );
49 static picture_t *ImageFilter( image_handler_t *, picture_t *,
50 video_format_t *, const char *psz_module );
52 static decoder_t *CreateDecoder( vlc_object_t *, video_format_t * );
53 static void DeleteDecoder( decoder_t * );
54 static encoder_t *CreateEncoder( vlc_object_t *, video_format_t *,
56 static void DeleteEncoder( encoder_t * );
57 static filter_t *CreateFilter( vlc_object_t *, es_format_t *,
58 video_format_t *, const char * );
59 static void DeleteFilter( filter_t * );
61 static vlc_fourcc_t Ext2Fourcc( const char * );
62 /*static const char *Fourcc2Ext( vlc_fourcc_t );*/
65 * Create an image_handler_t instance
68 image_handler_t *__image_HandlerCreate( vlc_object_t *p_this )
70 image_handler_t *p_image = malloc( sizeof(image_handler_t) );
72 memset( p_image, 0, sizeof(image_handler_t) );
73 p_image->p_parent = p_this;
75 p_image->pf_read = ImageRead;
76 p_image->pf_read_url = ImageReadUrl;
77 p_image->pf_write = ImageWrite;
78 p_image->pf_write_url = ImageWriteUrl;
79 p_image->pf_convert = ImageConvert;
80 p_image->pf_filter = ImageFilter;
86 * Delete the image_handler_t instance
89 void image_HandlerDelete( image_handler_t *p_image )
91 if( !p_image ) return;
93 if( p_image->p_dec ) DeleteDecoder( p_image->p_dec );
94 if( p_image->p_enc ) DeleteEncoder( p_image->p_enc );
95 if( p_image->p_filter ) DeleteFilter( p_image->p_filter );
105 static picture_t *ImageRead( image_handler_t *p_image, block_t *p_block,
106 video_format_t *p_fmt_in,
107 video_format_t *p_fmt_out )
109 picture_t *p_pic = NULL, *p_tmp;
111 /* Check if we can reuse the current decoder */
112 if( p_image->p_dec &&
113 p_image->p_dec->fmt_in.i_codec != p_fmt_in->i_chroma )
115 DeleteDecoder( p_image->p_dec );
119 /* Start a decoder */
120 if( !p_image->p_dec )
122 p_image->p_dec = CreateDecoder( p_image->p_parent, p_fmt_in );
123 if( !p_image->p_dec ) return NULL;
126 p_block->i_pts = p_block->i_dts = mdate();
127 while( (p_tmp = p_image->p_dec->pf_decode_video( p_image->p_dec, &p_block ))
131 p_pic->pf_release( p_pic );
137 msg_Warn( p_image->p_parent, "no image decoded" );
141 if( !p_fmt_out->i_chroma )
142 p_fmt_out->i_chroma = p_image->p_dec->fmt_out.video.i_chroma;
143 if( !p_fmt_out->i_width && p_fmt_out->i_height )
144 p_fmt_out->i_width = p_fmt_out->i_height
145 * p_image->p_dec->fmt_out.video.i_aspect
146 / VOUT_ASPECT_FACTOR;
147 if( !p_fmt_out->i_height && p_fmt_out->i_width )
148 p_fmt_out->i_height = p_fmt_out->i_width * VOUT_ASPECT_FACTOR
149 / p_image->p_dec->fmt_out.video.i_aspect;
150 if( !p_fmt_out->i_width )
151 p_fmt_out->i_width = p_image->p_dec->fmt_out.video.i_width;
152 if( !p_fmt_out->i_height )
153 p_fmt_out->i_height = p_image->p_dec->fmt_out.video.i_height;
155 /* Check if we need chroma conversion or resizing */
156 if( p_image->p_dec->fmt_out.video.i_chroma != p_fmt_out->i_chroma ||
157 p_image->p_dec->fmt_out.video.i_width != p_fmt_out->i_width ||
158 p_image->p_dec->fmt_out.video.i_height != p_fmt_out->i_height )
160 if( p_image->p_filter )
161 if( p_image->p_filter->fmt_in.video.i_chroma !=
162 p_image->p_dec->fmt_out.video.i_chroma ||
163 p_image->p_filter->fmt_out.video.i_chroma != p_fmt_out->i_chroma )
165 /* We need to restart a new filter */
166 DeleteFilter( p_image->p_filter );
167 p_image->p_filter = 0;
171 if( !p_image->p_filter )
174 CreateFilter( p_image->p_parent, &p_image->p_dec->fmt_out,
177 if( !p_image->p_filter )
179 p_pic->pf_release( p_pic );
185 /* Filters should handle on-the-fly size changes */
186 p_image->p_filter->fmt_in = p_image->p_dec->fmt_out;
187 p_image->p_filter->fmt_out = p_image->p_dec->fmt_out;
188 p_image->p_filter->fmt_out.i_codec = p_fmt_out->i_chroma;
189 p_image->p_filter->fmt_out.video = *p_fmt_out;
192 p_pic = p_image->p_filter->pf_video_filter( p_image->p_filter, p_pic );
193 *p_fmt_out = p_image->p_filter->fmt_out.video;
195 else *p_fmt_out = p_image->p_dec->fmt_out.video;
200 static picture_t *ImageReadUrl( image_handler_t *p_image, const char *psz_url,
201 video_format_t *p_fmt_in,
202 video_format_t *p_fmt_out )
209 file = fopen( psz_url, "rb" );
212 msg_Dbg( p_image->p_parent, "could not open file %s for reading",
217 fseek( file, 0, SEEK_END );
218 i_size = ftell( file );
219 fseek( file, 0, SEEK_SET );
221 p_block = block_New( p_image->p_parent, i_size );
222 fread( p_block->p_buffer, sizeof(char), i_size, file );
225 if( !p_fmt_in->i_chroma )
227 /* Try to guess format from file name */
228 p_fmt_in->i_chroma = Ext2Fourcc( psz_url );
231 p_pic = ImageRead( p_image, p_block, p_fmt_in, p_fmt_out );
241 void PicRelease( picture_t *p_pic ){};
243 static block_t *ImageWrite( image_handler_t *p_image, picture_t *p_pic,
244 video_format_t *p_fmt_in,
245 video_format_t *p_fmt_out )
248 void (*pf_release)( picture_t * );
250 /* Check if we can reuse the current encoder */
251 if( p_image->p_enc &&
252 ( p_image->p_enc->fmt_out.i_codec != p_fmt_out->i_chroma ||
253 p_image->p_enc->fmt_out.video.i_width != p_fmt_out->i_width ||
254 p_image->p_enc->fmt_out.video.i_height != p_fmt_out->i_height ) )
256 DeleteEncoder( p_image->p_enc );
260 /* Start an encoder */
261 if( !p_image->p_enc )
263 p_image->p_enc = CreateEncoder( p_image->p_parent,
264 p_fmt_in, p_fmt_out );
265 if( !p_image->p_enc ) return NULL;
268 /* Check if we need chroma conversion or resizing */
269 if( p_image->p_enc->fmt_in.video.i_chroma != p_fmt_in->i_chroma ||
270 p_image->p_enc->fmt_in.video.i_width != p_fmt_in->i_width ||
271 p_image->p_enc->fmt_in.video.i_height != p_fmt_in->i_height )
275 if( p_image->p_filter )
276 if( p_image->p_filter->fmt_in.video.i_chroma != p_fmt_in->i_chroma ||
277 p_image->p_filter->fmt_out.video.i_chroma !=
278 p_image->p_enc->fmt_in.video.i_chroma )
280 /* We need to restart a new filter */
281 DeleteFilter( p_image->p_filter );
282 p_image->p_filter = 0;
286 if( !p_image->p_filter )
289 es_format_Init( &fmt_in, VIDEO_ES, p_fmt_in->i_chroma );
290 fmt_in.video = *p_fmt_in;
293 CreateFilter( p_image->p_parent, &fmt_in,
294 &p_image->p_enc->fmt_in.video, NULL );
296 if( !p_image->p_filter )
303 /* Filters should handle on-the-fly size changes */
304 p_image->p_filter->fmt_in.i_codec = p_fmt_in->i_chroma;
305 p_image->p_filter->fmt_out.video = *p_fmt_in;
306 p_image->p_filter->fmt_out.i_codec =p_image->p_enc->fmt_in.i_codec;
307 p_image->p_filter->fmt_out.video = p_image->p_enc->fmt_in.video;
310 pf_release = p_pic->pf_release;
311 p_pic->pf_release = PicRelease; /* Small hack */
312 p_pif = p_image->p_filter->pf_video_filter( p_image->p_filter, p_pic );
313 p_pic->pf_release = pf_release;
317 p_block = p_image->p_enc->pf_encode_video( p_image->p_enc, p_pic );
321 msg_Dbg( p_image->p_parent, "no image encoded" );
328 static int ImageWriteUrl( image_handler_t *p_image, picture_t *p_pic,
329 video_format_t *p_fmt_in, video_format_t *p_fmt_out,
330 const char *psz_url )
335 if( !p_fmt_out->i_chroma )
337 /* Try to guess format from file name */
338 p_fmt_out->i_chroma = Ext2Fourcc( psz_url );
341 file = fopen( psz_url, "wb" );
344 msg_Dbg( p_image->p_parent, "could not open file %s for writing",
349 p_block = ImageWrite( p_image, p_pic, p_fmt_in, p_fmt_out );
353 fwrite( p_block->p_buffer, sizeof(char), p_block->i_buffer, file );
354 block_Release( p_block );
359 return p_block ? VLC_SUCCESS : VLC_EGENERIC;
363 * Convert an image to a different format
367 static picture_t *ImageConvert( image_handler_t *p_image, picture_t *p_pic,
368 video_format_t *p_fmt_in,
369 video_format_t *p_fmt_out )
371 void (*pf_release)( picture_t * );
374 if( !p_fmt_out->i_width && !p_fmt_out->i_height &&
375 p_fmt_out->i_sar_num && p_fmt_out->i_sar_den &&
376 p_fmt_out->i_sar_num * p_fmt_in->i_sar_den !=
377 p_fmt_out->i_sar_den * p_fmt_in->i_sar_num )
380 p_fmt_in->i_sar_num * (int64_t)p_fmt_out->i_sar_den *
381 p_fmt_in->i_width / p_fmt_in->i_sar_den / p_fmt_out->i_sar_num;
382 p_fmt_out->i_visible_width =
383 p_fmt_in->i_sar_num * (int64_t)p_fmt_out->i_sar_den *
384 p_fmt_in->i_visible_width / p_fmt_in->i_sar_den /
385 p_fmt_out->i_sar_num;
388 if( !p_fmt_out->i_chroma ) p_fmt_out->i_chroma = p_fmt_in->i_chroma;
389 if( !p_fmt_out->i_width )
390 p_fmt_out->i_width = p_fmt_out->i_visible_width = p_fmt_in->i_width;
391 if( !p_fmt_out->i_height )
392 p_fmt_out->i_height = p_fmt_out->i_visible_height = p_fmt_in->i_height;
393 if( !p_fmt_out->i_sar_num ) p_fmt_out->i_sar_num = p_fmt_in->i_sar_num;
394 if( !p_fmt_out->i_sar_den ) p_fmt_out->i_sar_den = p_fmt_in->i_sar_den;
395 if( !p_fmt_out->i_aspect ) p_fmt_out->i_aspect = p_fmt_in->i_aspect;
397 if( p_image->p_filter )
398 if( p_image->p_filter->fmt_in.video.i_chroma != p_fmt_in->i_chroma ||
399 p_image->p_filter->fmt_out.video.i_chroma != p_fmt_out->i_chroma )
401 /* We need to restart a new filter */
402 DeleteFilter( p_image->p_filter );
403 p_image->p_filter = 0;
407 if( !p_image->p_filter )
410 es_format_Init( &fmt_in, VIDEO_ES, p_fmt_in->i_chroma );
411 fmt_in.video = *p_fmt_in;
414 CreateFilter( p_image->p_parent, &fmt_in, p_fmt_out, NULL );
416 if( !p_image->p_filter )
423 /* Filters should handle on-the-fly size changes */
424 p_image->p_filter->fmt_in.video = *p_fmt_in;
425 p_image->p_filter->fmt_out.video = *p_fmt_out;
428 pf_release = p_pic->pf_release;
429 p_pic->pf_release = PicRelease; /* Small hack */
430 p_pif = p_image->p_filter->pf_video_filter( p_image->p_filter, p_pic );
431 p_pic->pf_release = pf_release;
433 if( p_fmt_in->i_chroma == p_fmt_out->i_chroma &&
434 p_fmt_in->i_width == p_fmt_out->i_width &&
435 p_fmt_in->i_height == p_fmt_out->i_height )
437 /* Duplicate image */
438 p_pif = p_image->p_filter->pf_vout_buffer_new( p_image->p_filter );
439 if( p_pif ) vout_CopyPicture( p_image->p_parent, p_pif, p_pic );
446 * Filter an image with a psz_module filter
450 static picture_t *ImageFilter( image_handler_t *p_image, picture_t *p_pic,
451 video_format_t *p_fmt, const char *psz_module )
453 void (*pf_release)( picture_t * );
457 if( !p_image->p_filter )
460 es_format_Init( &fmt, VIDEO_ES, p_fmt->i_chroma );
464 CreateFilter( p_image->p_parent, &fmt, &fmt.video, psz_module );
466 if( !p_image->p_filter )
473 /* Filters should handle on-the-fly size changes */
474 p_image->p_filter->fmt_in.video = *p_fmt;
475 p_image->p_filter->fmt_out.video = *p_fmt;
478 pf_release = p_pic->pf_release;
479 p_pic->pf_release = PicRelease; /* Small hack */
480 p_pif = p_image->p_filter->pf_video_filter( p_image->p_filter, p_pic );
481 p_pic->pf_release = pf_release;
492 vlc_fourcc_t i_codec;
497 { VLC_FOURCC('j','p','e','g'), "jpeg" },
498 { VLC_FOURCC('j','p','e','g'), "jpg" },
499 { VLC_FOURCC('l','j','p','g'), "ljpg" },
500 { VLC_FOURCC('p','n','g',' '), "png" },
501 { VLC_FOURCC('p','g','m',' '), "pgm" },
502 { VLC_FOURCC('p','g','m','y'), "pgmyuv" },
503 { VLC_FOURCC('p','b','m',' '), "pbm" },
504 { VLC_FOURCC('p','a','m',' '), "pam" },
505 { VLC_FOURCC('t','g','a',' '), "tga" },
506 { VLC_FOURCC('b','m','p',' '), "bmp" },
507 { VLC_FOURCC('p','n','m',' '), "pnm" },
508 { VLC_FOURCC('x','p','m',' '), "xpm" },
509 { VLC_FOURCC('x','c','f',' '), "xcf" },
510 { VLC_FOURCC('p','c','x',' '), "pcx" },
511 { VLC_FOURCC('g','i','f',' '), "gif" },
512 { VLC_FOURCC('t','i','f','f'), "tif" },
513 { VLC_FOURCC('t','i','f','f'), "tiff" },
514 { VLC_FOURCC('l','b','m',' '), "lbm" },
518 static vlc_fourcc_t Ext2Fourcc( const char *psz_name )
522 psz_name = strrchr( psz_name, '.' );
523 if( !psz_name ) return 0;
526 for( i = 0; ext_table[i].i_codec; i++ )
529 for( j = 0; toupper(ext_table[i].psz_ext[j]) == toupper(psz_name[j]);
532 if( !ext_table[i].psz_ext[j] && !psz_name[j] )
533 return ext_table[i].i_codec;
541 static const char *Fourcc2Ext( vlc_fourcc_t i_codec )
545 for( i = 0; ext_table[i].i_codec != 0; i++ )
547 if( ext_table[i].i_codec == i_codec ) return ext_table[i].psz_ext;
554 static void video_release_buffer( picture_t *p_pic )
556 if( p_pic && p_pic->p_data_orig ) free( p_pic->p_data_orig );
557 if( p_pic && p_pic->p_sys ) free( p_pic->p_sys );
558 if( p_pic ) free( p_pic );
561 static picture_t *video_new_buffer( decoder_t *p_dec )
563 picture_t *p_pic = malloc( sizeof(picture_t) );
565 p_dec->fmt_out.video.i_chroma = p_dec->fmt_out.i_codec;
566 vout_AllocatePicture( VLC_OBJECT(p_dec), p_pic,
567 p_dec->fmt_out.video.i_chroma,
568 p_dec->fmt_out.video.i_width,
569 p_dec->fmt_out.video.i_height,
570 p_dec->fmt_out.video.i_aspect );
572 if( !p_pic->i_planes )
578 p_pic->pf_release = video_release_buffer;
579 p_pic->i_status = RESERVED_PICTURE;
585 static void video_del_buffer( decoder_t *p_dec, picture_t *p_pic )
587 if( p_pic && p_pic->p_data_orig ) free( p_pic->p_data_orig );
588 if( p_pic && p_pic->p_sys ) free( p_pic->p_sys );
589 if( p_pic ) free( p_pic );
592 static void video_link_picture( decoder_t *p_dec, picture_t *p_pic )
596 static void video_unlink_picture( decoder_t *p_dec, picture_t *p_pic )
600 static decoder_t *CreateDecoder( vlc_object_t *p_this, video_format_t *fmt )
604 p_dec = vlc_object_create( p_this, VLC_OBJECT_DECODER );
607 msg_Err( p_this, "out of memory" );
611 p_dec->p_module = NULL;
612 es_format_Init( &p_dec->fmt_in, VIDEO_ES, fmt->i_chroma );
613 es_format_Init( &p_dec->fmt_out, VIDEO_ES, 0 );
614 p_dec->fmt_in.video = *fmt;
615 p_dec->b_pace_control = VLC_TRUE;
617 p_dec->pf_vout_buffer_new = video_new_buffer;
618 p_dec->pf_vout_buffer_del = video_del_buffer;
619 p_dec->pf_picture_link = video_link_picture;
620 p_dec->pf_picture_unlink = video_unlink_picture;
622 vlc_object_attach( p_dec, p_this );
624 /* Find a suitable decoder module */
625 p_dec->p_module = module_Need( p_dec, "decoder", "$codec", 0 );
626 if( !p_dec->p_module )
628 msg_Err( p_dec, "no suitable decoder module for fourcc `%4.4s'.\n"
629 "VLC probably does not support this image format.",
630 (char*)&p_dec->fmt_in.i_codec );
632 DeleteDecoder( p_dec );
639 static void DeleteDecoder( decoder_t * p_dec )
641 vlc_object_detach( p_dec );
643 if( p_dec->p_module ) module_Unneed( p_dec, p_dec->p_module );
645 es_format_Clean( &p_dec->fmt_in );
646 es_format_Clean( &p_dec->fmt_out );
648 vlc_object_destroy( p_dec );
651 static encoder_t *CreateEncoder( vlc_object_t *p_this, video_format_t *fmt_in,
652 video_format_t *fmt_out )
656 p_enc = vlc_object_create( p_this, VLC_OBJECT_ENCODER );
659 msg_Err( p_this, "out of memory" );
663 p_enc->p_module = NULL;
664 es_format_Init( &p_enc->fmt_in, VIDEO_ES, fmt_in->i_chroma );
665 p_enc->fmt_in.video = *fmt_in;
666 if( fmt_out->i_width > 0 && fmt_out->i_height > 0 )
668 p_enc->fmt_in.video.i_width = fmt_out->i_width;
669 p_enc->fmt_in.video.i_height = fmt_out->i_height;
671 if( fmt_out->i_visible_width > 0 &&
672 fmt_out->i_visible_height > 0 )
674 p_enc->fmt_in.video.i_visible_width = fmt_out->i_visible_width;
675 p_enc->fmt_in.video.i_visible_height = fmt_out->i_visible_height;
679 p_enc->fmt_in.video.i_visible_width = fmt_out->i_width;
680 p_enc->fmt_in.video.i_visible_height = fmt_out->i_height;
683 else if( fmt_out->i_sar_num && fmt_out->i_sar_den &&
684 fmt_out->i_sar_num * fmt_in->i_sar_den !=
685 fmt_out->i_sar_den * fmt_in->i_sar_num )
687 p_enc->fmt_in.video.i_width =
688 fmt_in->i_sar_num * (int64_t)fmt_out->i_sar_den * fmt_in->i_width /
689 fmt_in->i_sar_den / fmt_out->i_sar_num;
690 p_enc->fmt_in.video.i_visible_width =
691 fmt_in->i_sar_num * (int64_t)fmt_out->i_sar_den *
692 fmt_in->i_visible_width / fmt_in->i_sar_den / fmt_out->i_sar_num;
695 p_enc->fmt_in.video.i_frame_rate = 25;
696 p_enc->fmt_in.video.i_frame_rate_base = 1;
698 es_format_Init( &p_enc->fmt_out, VIDEO_ES, fmt_out->i_chroma );
699 p_enc->fmt_out.video = *fmt_out;
700 p_enc->fmt_out.video.i_width = p_enc->fmt_in.video.i_width;
701 p_enc->fmt_out.video.i_height = p_enc->fmt_in.video.i_height;
703 vlc_object_attach( p_enc, p_this );
705 /* Find a suitable decoder module */
706 p_enc->p_module = module_Need( p_enc, "encoder", 0, 0 );
707 if( !p_enc->p_module )
709 msg_Err( p_enc, "no suitable encoder module for fourcc `%4.4s'.\n"
710 "VLC probably does not support this image format.",
711 (char*)&p_enc->fmt_out.i_codec );
713 DeleteEncoder( p_enc );
716 p_enc->fmt_in.video.i_chroma = p_enc->fmt_in.i_codec;
721 static void DeleteEncoder( encoder_t * p_enc )
723 vlc_object_detach( p_enc );
725 if( p_enc->p_module ) module_Unneed( p_enc, p_enc->p_module );
727 es_format_Clean( &p_enc->fmt_in );
728 es_format_Clean( &p_enc->fmt_out );
730 vlc_object_destroy( p_enc );
733 static filter_t *CreateFilter( vlc_object_t *p_this, es_format_t *p_fmt_in,
734 video_format_t *p_fmt_out,
735 const char *psz_module )
739 p_filter = vlc_object_create( p_this, VLC_OBJECT_FILTER );
740 vlc_object_attach( p_filter, p_this );
742 p_filter->pf_vout_buffer_new =
743 (picture_t *(*)(filter_t *))video_new_buffer;
744 p_filter->pf_vout_buffer_del =
745 (void (*)(filter_t *, picture_t *))video_del_buffer;
747 p_filter->fmt_in = *p_fmt_in;
748 p_filter->fmt_out = *p_fmt_in;
749 p_filter->fmt_out.i_codec = p_fmt_out->i_chroma;
750 p_filter->fmt_out.video = *p_fmt_out;
751 p_filter->p_module = module_Need( p_filter, "video filter2", psz_module,
754 if( !p_filter->p_module )
756 msg_Dbg( p_filter, "no video filter found" );
757 DeleteFilter( p_filter );
764 static void DeleteFilter( filter_t * p_filter )
766 vlc_object_detach( p_filter );
768 if( p_filter->p_module ) module_Unneed( p_filter, p_filter->p_module );
770 es_format_Clean( &p_filter->fmt_in );
771 es_format_Clean( &p_filter->fmt_out );
773 vlc_object_destroy( p_filter );