static void clear_image(DrawGraphContext *s, AVFrame *out, AVFilterLink *outlink) { int i, j; int bg = AV_RN32(s->bg); for (i = 0; i < out->height; i++) for (j = 0; j < out->width; j++) AV_WN32(out->data[0] + i * out->linesize[0] + j * 4, bg); }
static void import_palette(CDXLVideoContext *c, uint32_t *new_palette) { int i; for (i = 0; i < c->palette_size / 2; i++) { unsigned rgb = AV_RB16(&c->palette[i * 2]); unsigned r = ((rgb >> 8) & 0xF) * 0x11; unsigned g = ((rgb >> 4) & 0xF) * 0x11; unsigned b = (rgb & 0xF) * 0x11; AV_WN32(&new_palette[i], (0xFFU << 24) | (r << 16) | (g << 8) | b); } }
static void drawtext(AVFrame *pic, int x, int y, const char *txt) { const uint8_t *font; int font_height; int i; font = avpriv_cga_font, font_height = 8; for (i = 0; txt[i]; i++) { int char_y, mask; uint8_t *p = pic->data[0] + y*pic->linesize[0] + (x + i*8)*4; for (char_y = 0; char_y < font_height; char_y++) { for (mask = 0x80; mask; mask >>= 1) { if (font[txt[i] * font_height + char_y] & mask) AV_WN32(p, ~AV_RN32(p)); p += 4; } p += pic->linesize[0] - 8*4; } } }
static int dds_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { DDSContext *ctx = avctx->priv_data; GetByteContext *gbc = &ctx->gbc; AVFrame *frame = data; int mipmap; int ret; ff_texturedsp_init(&ctx->texdsp); bytestream2_init(gbc, avpkt->data, avpkt->size); if (bytestream2_get_bytes_left(gbc) < 128) { av_log(avctx, AV_LOG_ERROR, "Frame is too small (%d).\n", bytestream2_get_bytes_left(gbc)); return AVERROR_INVALIDDATA; } if (bytestream2_get_le32(gbc) != MKTAG('D', 'D', 'S', ' ') || bytestream2_get_le32(gbc) != 124) { // header size av_log(avctx, AV_LOG_ERROR, "Invalid DDS header.\n"); return AVERROR_INVALIDDATA; } bytestream2_skip(gbc, 4); // flags avctx->height = bytestream2_get_le32(gbc); avctx->width = bytestream2_get_le32(gbc); ret = av_image_check_size(avctx->width, avctx->height, 0, avctx); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Invalid image size %dx%d.\n", avctx->width, avctx->height); return ret; } /* Since codec is based on 4x4 blocks, size is aligned to 4. */ avctx->coded_width = FFALIGN(avctx->width, TEXTURE_BLOCK_W); avctx->coded_height = FFALIGN(avctx->height, TEXTURE_BLOCK_H); bytestream2_skip(gbc, 4); // pitch bytestream2_skip(gbc, 4); // depth mipmap = bytestream2_get_le32(gbc); if (mipmap != 0) av_log(avctx, AV_LOG_VERBOSE, "Found %d mipmaps (ignored).\n", mipmap); /* Extract pixel format information, considering additional elements * in reserved1 and reserved2. */ ret = parse_pixel_format(avctx); if (ret < 0) return ret; ret = ff_get_buffer(avctx, frame, 0); if (ret < 0) return ret; if (ctx->compressed) { int size = (avctx->coded_height / TEXTURE_BLOCK_H) * (avctx->coded_width / TEXTURE_BLOCK_W) * ctx->tex_ratio; ctx->slice_count = av_clip(avctx->thread_count, 1, avctx->coded_height / TEXTURE_BLOCK_H); if (bytestream2_get_bytes_left(gbc) < size) { av_log(avctx, AV_LOG_ERROR, "Compressed Buffer is too small (%d < %d).\n", bytestream2_get_bytes_left(gbc), size); return AVERROR_INVALIDDATA; } /* Use the decompress function on the texture, one block per thread. */ ctx->tex_data = gbc->buffer; avctx->execute2(avctx, decompress_texture_thread, frame, NULL, ctx->slice_count); } else { int linesize = av_image_get_linesize(avctx->pix_fmt, frame->width, 0); if (ctx->paletted) { int i; /* Use the first 1024 bytes as palette, then copy the rest. */ bytestream2_get_buffer(gbc, frame->data[1], 256 * 4); for (i = 0; i < 256; i++) AV_WN32(frame->data[1] + i*4, (frame->data[1][2+i*4]<<0)+ (frame->data[1][1+i*4]<<8)+ (frame->data[1][0+i*4]<<16)+ (frame->data[1][3+i*4]<<24) ); frame->palette_has_changed = 1; } if (bytestream2_get_bytes_left(gbc) < frame->height * linesize) { av_log(avctx, AV_LOG_ERROR, "Buffer is too small (%d < %d).\n", bytestream2_get_bytes_left(gbc), frame->height * linesize); return AVERROR_INVALIDDATA; } av_image_copy_plane(frame->data[0], frame->linesize[0], gbc->buffer, linesize, linesize, frame->height); } /* Run any post processing here if needed. */ if (avctx->pix_fmt == AV_PIX_FMT_BGRA || avctx->pix_fmt == AV_PIX_FMT_RGBA || avctx->pix_fmt == AV_PIX_FMT_RGB0 || avctx->pix_fmt == AV_PIX_FMT_BGR0 || avctx->pix_fmt == AV_PIX_FMT_YA8) run_postproc(avctx, frame); /* Frame is ready to be output. */ frame->pict_type = AV_PICTURE_TYPE_I; frame->key_frame = 1; *got_frame = 1; return avpkt->size; }
static inline void draw_dot(int fg, int x, int y, AVFrame *out) { AV_WN32(out->data[0] + y * out->linesize[0] + x * 4, fg); }
static int filter_frame(AVFilterLink *link, AVFrame *in) { TonemapContext *s = link->dst->priv; AVFilterLink *outlink = link->dst->outputs[0]; AVFrame *out; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format); const AVPixFmtDescriptor *odesc = av_pix_fmt_desc_get(outlink->format); int ret, x, y; double peak = s->peak; if (!desc || !odesc) { av_frame_free(&in); return AVERROR_BUG; } out = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!out) { av_frame_free(&in); return AVERROR(ENOMEM); } ret = av_frame_copy_props(out, in); if (ret < 0) { av_frame_free(&in); av_frame_free(&out); return ret; } /* input and output transfer will be linear */ if (in->color_trc == AVCOL_TRC_UNSPECIFIED) { av_log(s, AV_LOG_WARNING, "Untagged transfer, assuming linear light\n"); out->color_trc = AVCOL_TRC_LINEAR; } else if (in->color_trc != AVCOL_TRC_LINEAR) av_log(s, AV_LOG_WARNING, "Tonemapping works on linear light only\n"); /* read peak from side data if not passed in */ if (!peak) { peak = ff_determine_signal_peak(in); av_log(s, AV_LOG_DEBUG, "Computed signal peak: %f\n", peak); } /* load original color space even if pixel format is RGB to compute overbrights */ s->coeffs = &luma_coefficients[in->colorspace]; if (s->desat > 0 && (in->colorspace == AVCOL_SPC_UNSPECIFIED || !s->coeffs)) { if (in->colorspace == AVCOL_SPC_UNSPECIFIED) av_log(s, AV_LOG_WARNING, "Missing color space information, "); else if (!s->coeffs) av_log(s, AV_LOG_WARNING, "Unsupported color space '%s', ", av_color_space_name(in->colorspace)); av_log(s, AV_LOG_WARNING, "desaturation is disabled\n"); s->desat = 0; } /* do the tone map */ for (y = 0; y < out->height; y++) for (x = 0; x < out->width; x++) tonemap(s, out, in, desc, x, y, peak); /* copy/generate alpha if needed */ if (desc->flags & AV_PIX_FMT_FLAG_ALPHA && odesc->flags & AV_PIX_FMT_FLAG_ALPHA) { av_image_copy_plane(out->data[3], out->linesize[3], in->data[3], in->linesize[3], out->linesize[3], outlink->h); } else if (odesc->flags & AV_PIX_FMT_FLAG_ALPHA) { for (y = 0; y < out->height; y++) { for (x = 0; x < out->width; x++) { AV_WN32(out->data[3] + x * odesc->comp[3].step + y * out->linesize[3], av_float2int(1.0f)); } } } av_frame_free(&in); ff_update_hdr_metadata(out, peak); return ff_filter_frame(outlink, out); }