vf_yadif.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2010 Michael Niedermayer <michaelni@gmx.at>
3  * 2010 James Darnley <james.darnley@gmail.com>
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with Libav; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #include "libavutil/cpu.h"
23 #include "libavutil/common.h"
24 #include "libavutil/pixdesc.h"
25 #include "avfilter.h"
26 #include "formats.h"
27 #include "internal.h"
28 #include "video.h"
29 #include "yadif.h"
30 
31 #undef NDEBUG
32 #include <assert.h>
33 
34 #define PERM_RWP AV_PERM_WRITE | AV_PERM_PRESERVE | AV_PERM_REUSE
35 
36 #define CHECK(j)\
37  { int score = FFABS(cur[mrefs-1+(j)] - cur[prefs-1-(j)])\
38  + FFABS(cur[mrefs +(j)] - cur[prefs -(j)])\
39  + FFABS(cur[mrefs+1+(j)] - cur[prefs+1-(j)]);\
40  if (score < spatial_score) {\
41  spatial_score= score;\
42  spatial_pred= (cur[mrefs +(j)] + cur[prefs -(j)])>>1;\
43 
44 #define FILTER \
45  for (x = 0; x < w; x++) { \
46  int c = cur[mrefs]; \
47  int d = (prev2[0] + next2[0])>>1; \
48  int e = cur[prefs]; \
49  int temporal_diff0 = FFABS(prev2[0] - next2[0]); \
50  int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) )>>1; \
51  int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) )>>1; \
52  int diff = FFMAX3(temporal_diff0 >> 1, temporal_diff1, temporal_diff2); \
53  int spatial_pred = (c+e) >> 1; \
54  int spatial_score = FFABS(cur[mrefs - 1] - cur[prefs - 1]) + FFABS(c-e) \
55  + FFABS(cur[mrefs + 1] - cur[prefs + 1]) - 1; \
56  \
57  CHECK(-1) CHECK(-2) }} }} \
58  CHECK( 1) CHECK( 2) }} }} \
59  \
60  if (mode < 2) { \
61  int b = (prev2[2 * mrefs] + next2[2 * mrefs])>>1; \
62  int f = (prev2[2 * prefs] + next2[2 * prefs])>>1; \
63  int max = FFMAX3(d - e, d - c, FFMIN(b - c, f - e)); \
64  int min = FFMIN3(d - e, d - c, FFMAX(b - c, f - e)); \
65  \
66  diff = FFMAX3(diff, min, -max); \
67  } \
68  \
69  if (spatial_pred > d + diff) \
70  spatial_pred = d + diff; \
71  else if (spatial_pred < d - diff) \
72  spatial_pred = d - diff; \
73  \
74  dst[0] = spatial_pred; \
75  \
76  dst++; \
77  cur++; \
78  prev++; \
79  next++; \
80  prev2++; \
81  next2++; \
82  }
83 
84 static void filter_line_c(uint8_t *dst,
85  uint8_t *prev, uint8_t *cur, uint8_t *next,
86  int w, int prefs, int mrefs, int parity, int mode)
87 {
88  int x;
89  uint8_t *prev2 = parity ? prev : cur ;
90  uint8_t *next2 = parity ? cur : next;
91 
92  FILTER
93 }
94 
95 static void filter_line_c_16bit(uint16_t *dst,
96  uint16_t *prev, uint16_t *cur, uint16_t *next,
97  int w, int prefs, int mrefs, int parity,
98  int mode)
99 {
100  int x;
101  uint16_t *prev2 = parity ? prev : cur ;
102  uint16_t *next2 = parity ? cur : next;
103  mrefs /= 2;
104  prefs /= 2;
105 
106  FILTER
107 }
108 
109 static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic,
110  int parity, int tff)
111 {
112  YADIFContext *yadif = ctx->priv;
113  int y, i;
114 
115  for (i = 0; i < yadif->csp->nb_components; i++) {
116  int w = dstpic->video->w;
117  int h = dstpic->video->h;
118  int refs = yadif->cur->linesize[i];
119  int df = (yadif->csp->comp[i].depth_minus1 + 8) / 8;
120 
121  if (i == 1 || i == 2) {
122  /* Why is this not part of the per-plane description thing? */
123  w >>= yadif->csp->log2_chroma_w;
124  h >>= yadif->csp->log2_chroma_h;
125  }
126 
127  for (y = 0; y < h; y++) {
128  if ((y ^ parity) & 1) {
129  uint8_t *prev = &yadif->prev->data[i][y * refs];
130  uint8_t *cur = &yadif->cur ->data[i][y * refs];
131  uint8_t *next = &yadif->next->data[i][y * refs];
132  uint8_t *dst = &dstpic->data[i][y * dstpic->linesize[i]];
133  int mode = y == 1 || y + 2 == h ? 2 : yadif->mode;
134  yadif->filter_line(dst, prev, cur, next, w,
135  y + 1 < h ? refs : -refs,
136  y ? -refs : refs,
137  parity ^ tff, mode);
138  } else {
139  memcpy(&dstpic->data[i][y * dstpic->linesize[i]],
140  &yadif->cur->data[i][y * refs], w * df);
141  }
142  }
143  }
144 
145  emms_c();
146 }
147 
149  int w, int h)
150 {
151  AVFilterBufferRef *picref;
152  int width = FFALIGN(w, 32);
153  int height = FFALIGN(h + 2, 32);
154  int i;
155 
156  picref = ff_default_get_video_buffer(link, perms, width, height);
157 
158  picref->video->w = w;
159  picref->video->h = h;
160 
161  for (i = 0; i < 3; i++)
162  picref->data[i] += picref->linesize[i];
163 
164  return picref;
165 }
166 
167 static int return_frame(AVFilterContext *ctx, int is_second)
168 {
169  YADIFContext *yadif = ctx->priv;
170  AVFilterLink *link = ctx->outputs[0];
171  int tff, ret;
172 
173  if (yadif->parity == -1) {
174  tff = yadif->cur->video->interlaced ?
175  yadif->cur->video->top_field_first : 1;
176  } else {
177  tff = yadif->parity ^ 1;
178  }
179 
180  if (is_second) {
181  yadif->out = ff_get_video_buffer(link, PERM_RWP, link->w, link->h);
182  if (!yadif->out)
183  return AVERROR(ENOMEM);
184 
185  avfilter_copy_buffer_ref_props(yadif->out, yadif->cur);
186  yadif->out->video->interlaced = 0;
187  }
188 
189  if (!yadif->csp)
190  yadif->csp = av_pix_fmt_desc_get(link->format);
191  if (yadif->csp->comp[0].depth_minus1 / 8 == 1)
193 
194  filter(ctx, yadif->out, tff ^ !is_second, tff);
195 
196  if (is_second) {
197  int64_t cur_pts = yadif->cur->pts;
198  int64_t next_pts = yadif->next->pts;
199 
200  if (next_pts != AV_NOPTS_VALUE && cur_pts != AV_NOPTS_VALUE) {
201  yadif->out->pts = cur_pts + next_pts;
202  } else {
203  yadif->out->pts = AV_NOPTS_VALUE;
204  }
205  }
206  ret = ff_filter_frame(ctx->outputs[0], yadif->out);
207 
208  yadif->frame_pending = (yadif->mode&1) && !is_second;
209  return ret;
210 }
211 
212 static int filter_frame(AVFilterLink *link, AVFilterBufferRef *picref)
213 {
214  AVFilterContext *ctx = link->dst;
215  YADIFContext *yadif = ctx->priv;
216 
217  if (yadif->frame_pending)
218  return_frame(ctx, 1);
219 
220  if (yadif->prev)
221  avfilter_unref_buffer(yadif->prev);
222  yadif->prev = yadif->cur;
223  yadif->cur = yadif->next;
224  yadif->next = picref;
225 
226  if (!yadif->cur)
227  return 0;
228 
229  if (yadif->auto_enable && !yadif->cur->video->interlaced) {
230  yadif->out = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
231  if (!yadif->out)
232  return AVERROR(ENOMEM);
233 
234  avfilter_unref_bufferp(&yadif->prev);
235  if (yadif->out->pts != AV_NOPTS_VALUE)
236  yadif->out->pts *= 2;
237  return ff_filter_frame(ctx->outputs[0], yadif->out);
238  }
239 
240  if (!yadif->prev &&
241  !(yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ)))
242  return AVERROR(ENOMEM);
243 
244  yadif->out = ff_get_video_buffer(ctx->outputs[0], PERM_RWP,
245  link->w, link->h);
246  if (!yadif->out)
247  return AVERROR(ENOMEM);
248 
249  avfilter_copy_buffer_ref_props(yadif->out, yadif->cur);
250  yadif->out->video->interlaced = 0;
251 
252  if (yadif->out->pts != AV_NOPTS_VALUE)
253  yadif->out->pts *= 2;
254 
255  return return_frame(ctx, 0);
256 }
257 
258 static int request_frame(AVFilterLink *link)
259 {
260  AVFilterContext *ctx = link->src;
261  YADIFContext *yadif = ctx->priv;
262 
263  if (yadif->frame_pending) {
264  return_frame(ctx, 1);
265  return 0;
266  }
267 
268  do {
269  int ret;
270 
271  if (yadif->eof)
272  return AVERROR_EOF;
273 
274  ret = ff_request_frame(link->src->inputs[0]);
275 
276  if (ret == AVERROR_EOF && yadif->next) {
277  AVFilterBufferRef *next =
279 
280  if (!next)
281  return AVERROR(ENOMEM);
282 
283  next->pts = yadif->next->pts * 2 - yadif->cur->pts;
284 
285  filter_frame(link->src->inputs[0], next);
286  yadif->eof = 1;
287  } else if (ret < 0) {
288  return ret;
289  }
290  } while (!yadif->cur);
291 
292  return 0;
293 }
294 
295 static int poll_frame(AVFilterLink *link)
296 {
297  YADIFContext *yadif = link->src->priv;
298  int ret, val;
299 
300  if (yadif->frame_pending)
301  return 1;
302 
303  val = ff_poll_frame(link->src->inputs[0]);
304  if (val <= 0)
305  return val;
306 
307  //FIXME change API to not requre this red tape
308  if (val == 1 && !yadif->next) {
309  if ((ret = ff_request_frame(link->src->inputs[0])) < 0)
310  return ret;
311  val = ff_poll_frame(link->src->inputs[0]);
312  if (val <= 0)
313  return val;
314  }
315  assert(yadif->next || !val);
316 
317  if (yadif->auto_enable && yadif->next && !yadif->next->video->interlaced)
318  return val;
319 
320  return val * ((yadif->mode&1)+1);
321 }
322 
323 static av_cold void uninit(AVFilterContext *ctx)
324 {
325  YADIFContext *yadif = ctx->priv;
326 
327  if (yadif->prev) avfilter_unref_bufferp(&yadif->prev);
328  if (yadif->cur ) avfilter_unref_bufferp(&yadif->cur );
329  if (yadif->next) avfilter_unref_bufferp(&yadif->next);
330 }
331 
333 {
334  static const enum AVPixelFormat pix_fmts[] = {
355  };
356 
358 
359  return 0;
360 }
361 
362 static av_cold int init(AVFilterContext *ctx, const char *args)
363 {
364  YADIFContext *yadif = ctx->priv;
365 
366  yadif->mode = 0;
367  yadif->parity = -1;
368  yadif->auto_enable = 0;
369  yadif->csp = NULL;
370 
371  if (args)
372  sscanf(args, "%d:%d:%d",
373  &yadif->mode, &yadif->parity, &yadif->auto_enable);
374 
375  yadif->filter_line = filter_line_c;
376 
377  if (ARCH_X86)
378  ff_yadif_init_x86(yadif);
379 
380  av_log(ctx, AV_LOG_VERBOSE, "mode:%d parity:%d auto_enable:%d\n",
381  yadif->mode, yadif->parity, yadif->auto_enable);
382 
383  return 0;
384 }
385 
386 static int config_props(AVFilterLink *link)
387 {
388  link->time_base.num = link->src->inputs[0]->time_base.num;
389  link->time_base.den = link->src->inputs[0]->time_base.den * 2;
390  link->w = link->src->inputs[0]->w;
391  link->h = link->src->inputs[0]->h;
392 
393  return 0;
394 }
395 
397  {
398  .name = "default",
399  .type = AVMEDIA_TYPE_VIDEO,
400  .get_video_buffer = get_video_buffer,
401  .filter_frame = filter_frame,
402  },
403  { NULL }
404 };
405 
407  {
408  .name = "default",
409  .type = AVMEDIA_TYPE_VIDEO,
410  .poll_frame = poll_frame,
411  .request_frame = request_frame,
412  .config_props = config_props,
413  },
414  { NULL }
415 };
416 
418  .name = "yadif",
419  .description = NULL_IF_CONFIG_SMALL("Deinterlace the input image"),
420 
421  .priv_size = sizeof(YADIFContext),
422  .init = init,
423  .uninit = uninit,
425 
426  .inputs = avfilter_vf_yadif_inputs,
427 
428  .outputs = avfilter_vf_yadif_outputs,
429 };
static const AVFilterPad avfilter_vf_yadif_inputs[]
Definition: vf_yadif.c:396
static void filter_line_c_16bit(uint16_t *dst, uint16_t *prev, uint16_t *cur, uint16_t *next, int w, int prefs, int mrefs, int parity, int mode)
Definition: vf_yadif.c:95
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1435
static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic, int parity, int tff)
Definition: vf_yadif.c:109
AVFilterBufferRefVideoProps * video
video buffer specific properties
Definition: avfilter.h:159
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:144
int linesize[8]
number of bytes per line
Definition: avfilter.h:157
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:70
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:122
int ff_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:459
int num
numerator
Definition: rational.h:44
av_cold void ff_yadif_init_x86(YADIFContext *yadif)
Definition: yadif.c:58
int frame_pending
Definition: yadif.h:41
AVFilterBufferRef * cur
Definition: yadif.h:49
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:125
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:66
void avfilter_unref_buffer(AVFilterBufferRef *ref)
Remove a reference to a buffer.
Definition: buffer.c:75
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:165
#define AV_PERM_READ
can read from the buffer
Definition: avfilter.h:97
const char * name
Pad name.
Definition: internal.h:39
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:426
AVFilterBufferRef * ff_default_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
Definition: video.c:80
static int request_frame(AVFilterLink *link)
Definition: vf_yadif.c:258
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:102
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:83
uint8_t
int top_field_first
field order
Definition: avfilter.h:126
static int filter_frame(AVFilterLink *link, AVFilterBufferRef *picref)
Definition: vf_yadif.c:212
#define emms_c()
Definition: internal.h:145
void avfilter_unref_bufferp(AVFilterBufferRef **ref)
Remove a reference to a buffer and set the pointer to NULL.
Definition: buffer.c:88
void(* filter_line)(uint8_t *dst, uint8_t *prev, uint8_t *cur, uint8_t *next, int w, int prefs, int mrefs, int parity, int mode)
Definition: yadif.h:53
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range ...
Definition: pixfmt.h:101
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
Definition: pixfmt.h:78
void ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:375
#define next2
AVFilterBufferRef * out
Definition: yadif.h:52
int64_t pts
presentation timestamp.
Definition: avfilter.h:167
A filter pad used for either input or output.
Definition: internal.h:33
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:150
AVFilterBufferRef * ff_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:145
uint16_t depth_minus1
number of bits in the component minus 1
Definition: pixdesc.h:43
int h
image height
Definition: avfilter.h:123
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:75
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:130
AVFilterBufferRef * prev
Definition: yadif.h:51
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
void * priv
private data for use by the filter
Definition: avfilter.h:439
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:146
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:128
static int query_formats(AVFilterContext *ctx)
Definition: vf_yadif.c:332
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:69
static const AVFilterPad avfilter_vf_yadif_outputs[]
Definition: vf_yadif.c:406
AVFilterBufferRef * avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask)
Add a new reference to a buffer.
Definition: buffer.c:35
int auto_enable
0: deinterlace all frames 1: only deinterlace frames marked as interlaced
Definition: yadif.h:47
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:57
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
Definition: pixfmt.h:77
static int config_props(AVFilterLink *link)
Definition: vf_yadif.c:386
static void filter_line_c(uint8_t *dst, uint8_t *prev, uint8_t *cur, uint8_t *next, int w, int prefs, int mrefs, int parity, int mode)
Definition: vf_yadif.c:84
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:143
int eof
Definition: yadif.h:58
#define PERM_RWP
Definition: vf_yadif.c:34
#define FILTER
Definition: vf_yadif.c:44
static int poll_frame(AVFilterLink *link)
Definition: vf_yadif.c:295
A reference to an AVFilterBuffer.
Definition: avfilter.h:139
NULL
Definition: eval.c:52
static int width
Definition: utils.c:156
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:126
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:71
Filter definition.
Definition: avfilter.h:371
Y , 16bpp, big-endian.
Definition: pixfmt.h:98
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:110
AVFilter avfilter_vf_yadif
Definition: vf_yadif.c:417
int parity
0: top field first 1: bottom field first -1: auto-detection
Definition: yadif.h:39
const char * name
filter name
Definition: avfilter.h:372
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:433
#define prev2
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:129
const AVPixFmtDescriptor * csp
Definition: yadif.h:57
int height
Definition: gxfenc.c:72
static AVFilterBufferRef * get_video_buffer(AVFilterLink *link, int perms, int w, int h)
Definition: vf_yadif.c:148
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
Y , 8bpp.
Definition: pixfmt.h:73
int interlaced
is frame interlaced
Definition: avfilter.h:125
common internal and external API header
#define ARCH_X86
Definition: config.h:33
void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src)
Copy properties of src to dst, without copying the actual data.
Definition: buffer.c:164
AVFilterBufferRef * next
Definition: yadif.h:50
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:127
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
Definition: pixfmt.h:79
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:72
int den
denominator
Definition: rational.h:45
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_yadif.c:323
Y , 16bpp, little-endian.
Definition: pixfmt.h:99
uint8_t * data[8]
picture/audio data for each plane
Definition: avfilter.h:141
static av_cold int init(AVFilterContext *ctx, const char *args)
Definition: vf_yadif.c:362
An instance of a filter.
Definition: avfilter.h:418
struct YADIFContext YADIFContext
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:100
static int return_frame(AVFilterContext *ctx, int is_second)
Definition: vf_yadif.c:167
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:239
internal API functions
int ff_poll_frame(AVFilterLink *link)
Poll a frame from the filter chain.
Definition: avfilter.c:250
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
int mode
0: send 1 frame for each frame 1: send 1 frame for each field 2: like 0 but skips spatial interlacing...
Definition: yadif.h:32
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:149
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:145