mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-06 03:20:26 +00:00
ncvisual_from_rgba: align suitably for ffmpeg (64B) #1675
This commit is contained in:
parent
20ea3a3345
commit
1622beeac4
@ -2643,8 +2643,8 @@ API int ncblit_rgb_loose(const void* data, int linesize,
|
||||
// Per libav, we "store as BGRA on little-endian, and ARGB on big-endian".
|
||||
// This is an RGBA *byte-order* scheme. libav emits bytes, not words. Those
|
||||
// bytes are R-G-B-A. When read as words, on little endian this will be ABGR,
|
||||
// and on big-endian this will be RGBA. force everything to LE ABGR, a no-op on
|
||||
// and thus favoring little-endian. Take that, big-endian mafia!
|
||||
// and on big-endian this will be RGBA. force everything to LE ABGR, a no-op
|
||||
// on (and thus favoring) little-endian. Take that, big-endian mafia!
|
||||
|
||||
// Extract the 8-bit alpha component from a pixel
|
||||
static inline unsigned
|
||||
|
@ -526,15 +526,24 @@ ncvisual* ncvisual_from_rgba(const void* rgba, int rows, int rowstride, int cols
|
||||
}
|
||||
ncvisual* ncv = ncvisual_create();
|
||||
if(ncv){
|
||||
// ffmpeg needs inputs with rows aligned on 192-byte boundaries
|
||||
ncv->rowstride = rowstride;
|
||||
#define IMGALIGN 64
|
||||
if(ncv->rowstride % IMGALIGN){
|
||||
ncv->rowstride = (ncv->rowstride + IMGALIGN) / IMGALIGN * IMGALIGN;
|
||||
}
|
||||
#undef IMGALIGN
|
||||
ncv->pixx = cols;
|
||||
ncv->pixy = rows;
|
||||
uint32_t* data = memdup(rgba, rowstride * ncv->pixy);
|
||||
//fprintf(stderr, "COPY US %d (%d)\n", rowstride * ncv->pixy, ncv->pixy);
|
||||
uint32_t* data = malloc(ncv->rowstride * ncv->pixy);
|
||||
if(data == NULL){
|
||||
ncvisual_destroy(ncv);
|
||||
return NULL;
|
||||
}
|
||||
for(int y = 0 ; y < rows ; ++y){
|
||||
memcpy(data + (ncv->rowstride * y) / 4, rgba + rowstride * y, rowstride);
|
||||
}
|
||||
//fprintf(stderr, "COPY US %d (%d)\n", rowstride * ncv->pixy, ncv->pixy);
|
||||
//fprintf(stderr, "ROWS: %d STRIDE: %d (%d) COLS: %d\n", rows, rowstride, rowstride / 4, cols);
|
||||
ncvisual_set_data(ncv, data, true);
|
||||
ncvisual_details_seed(ncv);
|
||||
|
@ -42,8 +42,8 @@ typedef struct ncvisual_details {
|
||||
print_frame_summary(const AVCodecContext* cctx, const AVFrame* f){
|
||||
char pfmt[128];
|
||||
av_get_pix_fmt_string(pfmt, sizeof(pfmt), f->format);
|
||||
fprintf(stderr, "Frame %05d (%d? %d?) %dx%d pfmt %d (%s)\n",
|
||||
cctx->frame_number,
|
||||
fprintf(stderr, "Frame %05d %p (%d? %d?) %dx%d pfmt %d (%s)\n",
|
||||
cctx ? cctx->frame_number : 0, f,
|
||||
f->coded_picture_number,
|
||||
f->display_picture_number,
|
||||
f->width, f->height,
|
||||
@ -455,12 +455,12 @@ int ffmpeg_decode_loop(ncvisual* ncv){
|
||||
int ffmpeg_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
|
||||
const struct blitset* bset, const blitterargs* bargs){
|
||||
const AVFrame* inframe = ncv->details->frame;
|
||||
//fprintf(stderr, "inframe: %p frame: %p\n", inframe, ncv->details->frame);
|
||||
//print_frame_summary(NULL, inframe);
|
||||
void* data = NULL;
|
||||
int stride = 0;
|
||||
AVFrame* sframe = NULL;
|
||||
const int targformat = AV_PIX_FMT_RGBA;
|
||||
//fprintf(stderr, "got format: %d want format: %d\n", inframe->format, targformat);
|
||||
//fprintf(stderr, "got format: %d (%d/%d) want format: %d\n", inframe->format, inframe->height, inframe->width, targformat);
|
||||
if(inframe && (cols != inframe->width || rows != inframe->height || inframe->format != targformat)){
|
||||
//fprintf(stderr, "resize+render: %d/%d->%d/%d\n", inframe->height, inframe->width, rows, cols);
|
||||
sframe = av_frame_alloc();
|
||||
@ -471,6 +471,7 @@ int ffmpeg_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
|
||||
//fprintf(stderr, "WHN NCV: %d/%d bargslen: %d/%d\n", inframe->width, inframe->height, bargs->leny, bargs->lenx);
|
||||
const int srclenx = bargs->lenx ? bargs->lenx : inframe->width;
|
||||
const int srcleny = bargs->leny ? bargs->leny : inframe->height;
|
||||
//fprintf(stderr, "src %d/%d -> targ %d/%d ctx: %p\n", srcleny, srclenx, rows, cols, ncv->details->swsctx);
|
||||
ncv->details->swsctx = sws_getCachedContext(ncv->details->swsctx,
|
||||
srclenx, srcleny,
|
||||
inframe->format,
|
||||
@ -492,7 +493,7 @@ int ffmpeg_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
|
||||
//fprintf(stderr, "Error allocating visual data (%d X %d)\n", sframe->height, sframe->width);
|
||||
return -1;
|
||||
}
|
||||
//fprintf(stderr, "INFRAME DAA: %p SDATA: %p FDATA: %p\n", inframe->data[0], sframe->data[0], ncv->details->frame->data[0]);
|
||||
//fprintf(stderr, "INFRAME DAA: %p SDATA: %p FDATA: %p to %d/%d\n", inframe->data[0], sframe->data[0], ncv->details->frame->data[0], sframe->height, sframe->width);
|
||||
int height = sws_scale(ncv->details->swsctx, (const uint8_t* const*)inframe->data,
|
||||
inframe->linesize, 0, srcleny, sframe->data,
|
||||
sframe->linesize);
|
||||
|
Loading…
Reference in New Issue
Block a user