| 159 | } |
| 160 | |
| 161 | static int dxv_encode(AVCodecContext *avctx, AVPacket *pkt, |
| 162 | const AVFrame *frame, int *got_packet) |
| 163 | { |
| 164 | DXVEncContext *ctx = avctx->priv_data; |
| 165 | PutByteContext *pbc = &ctx->pbc; |
| 166 | int ret; |
| 167 | |
| 168 | /* unimplemented: needs to depend on compression ratio of tex format */ |
| 169 | /* under DXT1, we need 3 words to encode load ops for 32 words. |
| 170 | * the first 2 words of the texture do not need load ops. */ |
| 171 | ret = ff_alloc_packet(avctx, pkt, DXV_HEADER_LENGTH + ctx->tex_size + AV_CEIL_RSHIFT(ctx->tex_size - 8, 7) * 12); |
| 172 | if (ret < 0) |
| 173 | return ret; |
| 174 | |
| 175 | if (ctx->enc.tex_funct) { |
| 176 | uint8_t *safe_data[4] = {frame->data[0], 0, 0, 0}; |
| 177 | int safe_linesize[4] = {frame->linesize[0], 0, 0, 0}; |
| 178 | |
| 179 | if (avctx->width != DXV_ALIGN(avctx->width) || avctx->height != DXV_ALIGN(avctx->height)) { |
| 180 | ret = av_image_alloc( |
| 181 | safe_data, |
| 182 | safe_linesize, |
| 183 | DXV_ALIGN(avctx->width), |
| 184 | DXV_ALIGN(avctx->height), |
| 185 | avctx->pix_fmt, |
| 186 | 1); |
| 187 | if (ret < 0) |
| 188 | return ret; |
| 189 | |
| 190 | av_image_copy2( |
| 191 | safe_data, |
| 192 | safe_linesize, |
| 193 | frame->data, |
| 194 | frame->linesize, |
| 195 | avctx->pix_fmt, |
| 196 | avctx->width, |
| 197 | avctx->height); |
| 198 | |
| 199 | if (avctx->width != DXV_ALIGN(avctx->width)) { |
| 200 | av_assert0(frame->format == AV_PIX_FMT_RGBA); |
| 201 | for (int y = 0; y < avctx->height; y++) { |
| 202 | memset(safe_data[0] + y * safe_linesize[0] + 4*avctx->width, 0, safe_linesize[0] - 4*avctx->width); |
| 203 | } |
| 204 | } |
| 205 | if (avctx->height != DXV_ALIGN(avctx->height)) { |
| 206 | for (int y = avctx->height; y < DXV_ALIGN(avctx->height); y++) { |
| 207 | memset(safe_data[0] + y * safe_linesize[0], 0, safe_linesize[0]); |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | ctx->enc.tex_data.out = ctx->tex_data; |
| 213 | ctx->enc.frame_data.in = safe_data[0]; |
| 214 | ctx->enc.stride = safe_linesize[0]; |
| 215 | ctx->enc.width = DXV_ALIGN(avctx->width); |
| 216 | ctx->enc.height = DXV_ALIGN(avctx->height); |
| 217 | ff_texturedsp_exec_compress_threads(avctx, &ctx->enc); |
| 218 |
nothing calls this directly
no test coverage detected