Skip to content

Commit

Permalink
Output uncropped PNGs, fix snprintf warnings.
Browse files Browse the repository at this point in the history
* Add --full-bitmaps flag.
* Address snprintf warning with buffer for PNG filenames.
  • Loading branch information
cubicibo authored Jul 18, 2024
1 parent 1574b14 commit 32d3f2b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ Moreover, the last table has debugging parameters. These should not have any pra
| ``--squarepx`` | Experimental: Flag to fix the square pixel stretch with|
| | SD 4:3 content. Use ``--anamorphic`` for 16:9 SD. |
+--------------------+--------------------------------------------------------+
| ``--full-bitmaps`` | Output bitmaps to the frame size, without cropping. |
| | I.e all PNGs are 1920x1080 with ``-v 1080p``. |
+--------------------+--------------------------------------------------------+

| ``--height-store`` | Sets the ASS storage height. Only useful for ASS files |
| | with complex transforms and unusual video height. |
+--------------------+--------------------------------------------------------+
Expand Down
9 changes: 7 additions & 2 deletions ass2bdnxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include "common.h"

#define A2B_VERSION_STRING "0.7e"
#define A2B_VERSION_STRING "0.7f"

frate_t frates[] = {
{"23.976",24, 24000, 1001},
Expand Down Expand Up @@ -65,14 +65,15 @@ enum opts_short_e {
//A2B general
OPT_ARG_VERSION = 975,
//A2B renderer
OPT_ARG_DIM = 992,
OPT_ARG_DIM = 990,
OPT_ARG_SQUAREPIX,
OPT_ARG_NEGATIVE,
OPT_ARG_DVD_MODE,
OPT_ARG_FRAME_HEIGHT,
OPT_ARG_STORAGE_HEIGHT,
OPT_ARG_HINTING,
OPT_ARG_KEEPDUPES,
OPT_ARG_FULLBITMAPS,
//LIQ
OPT_LIQ_SPEED = 1000,
OPT_LIQ_DITHER,
Expand Down Expand Up @@ -275,6 +276,7 @@ int main(int argc, char *argv[])
{"dvd-mode", no_argument, 0, OPT_ARG_DVD_MODE},
{"hinting", no_argument, 0, OPT_ARG_HINTING},
{"keep-dupes", no_argument, 0, OPT_ARG_KEEPDUPES},
{"full-bitmaps", no_argument, 0, OPT_ARG_FULLBITMAPS},
{"version", no_argument, 0, OPT_ARG_VERSION},
{"liq-dither", required_argument, 0, OPT_LIQ_DITHER},
{"liq-quality", required_argument, 0, OPT_LIQ_MAXQUAL},
Expand Down Expand Up @@ -330,6 +332,9 @@ int main(int argc, char *argv[])
case OPT_ARG_HINTING:
args.hinting = 1;
break;
case OPT_ARG_FULLBITMAPS:
args.full_bitmaps = 1;
break;
case 't':
track_name = optarg;
break;
Expand Down
3 changes: 2 additions & 1 deletion common.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ typedef struct opts_s {
uint32_t square_px : 1;
uint32_t downsampled : 4;
uint32_t dim_flag : 1; //8
uint32_t _bpad1 : 16;
uint32_t full_bitmaps : 1;
uint32_t _bpad1 : 15;
const char *fontdir;
} opts_t;

Expand Down
32 changes: 19 additions & 13 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#include "common.h"

#define FILENAME_FMT "%08d"
#define FILENAME_CNT "_%d"
#define FILENAME_CNT "_%01d"
#define FILENAME_EXT ".png"
#define FILENAME_MAX_LENGTH (20)

#define BOX_AREA(box) ((box.x2-box.x1)*(box.y2-box.y1))
#define DIV_ROUND_CLOSEST(n, d) (((n) + (d >> 1))/(d))
Expand Down Expand Up @@ -106,7 +107,7 @@ static void write_png_palette(uint32_t count, image_t *rgba_img, liq_image **img

int k, w, h;
int h_margin, w_margin;
char fname[15];
char fname[FILENAME_MAX_LENGTH];

w = rgba_img->subx2 - rgba_img->subx1 + 1;
h = rgba_img->suby2 - rgba_img->suby1 + 1;
Expand Down Expand Up @@ -162,14 +163,14 @@ static void write_png_palette(uint32_t count, image_t *rgba_img, liq_image **img

for (uint8_t split_cnt = 0; split_cnt < MIN(2, 1 + is_split); split_cnt++) {
if (is_split) {
snprintf(fname, 15, FILENAME_FMT FILENAME_CNT FILENAME_EXT, count, split_cnt);
snprintf(fname, FILENAME_MAX_LENGTH, FILENAME_FMT FILENAME_CNT FILENAME_EXT, count, split_cnt);
w = rgba_img->crops[split_cnt].x2 - rgba_img->crops[split_cnt].x1 + 1;
h = rgba_img->crops[split_cnt].y2 - rgba_img->crops[split_cnt].y1 + 1;
w_margin = rgba_img->crops[split_cnt].x1;
h_margin = rgba_img->crops[split_cnt].y1 - rgba_img->suby1;
} else {
w_margin = rgba_img->subx1;
snprintf(fname, 15, FILENAME_FMT FILENAME_EXT, count);
snprintf(fname, FILENAME_MAX_LENGTH, FILENAME_FMT FILENAME_EXT, count);
}

png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
Expand Down Expand Up @@ -392,7 +393,7 @@ static void blend_single(image_t * frame, ASS_Image *img)

#define DIM_COLOR(c, p) (uint8_t)(round(p*(float)c))

static void blend(image_t *frame, ASS_Image *img, const float dimf, const uint8_t dim_flag)
static void blend(image_t *frame, ASS_Image *img, const opts_t *args)
{
int x, y, c;
uint8_t *buf = frame->buffer;
Expand Down Expand Up @@ -421,16 +422,21 @@ static void blend(image_t *frame, ASS_Image *img, const float dimf, const uint8_
frame->subx2 = MAX(frame->subx2, x);
frame->suby2 = MAX(frame->suby2, y);

if (dim_flag) {
buf[c ] = DIM_COLOR(buf[c ], dimf);
buf[c+1] = DIM_COLOR(buf[c+1], dimf);
buf[c+2] = DIM_COLOR(buf[c+2], dimf);
if (args->dim_flag) {
buf[c ] = DIM_COLOR(buf[c ], args->dimf);
buf[c+1] = DIM_COLOR(buf[c+1], args->dimf);
buf[c+2] = DIM_COLOR(buf[c+2], args->dimf);
}
}
}

buf += frame->stride;
}
if (args->full_bitmaps) {
frame->subx1 = frame->suby1 = 0;
frame->subx2 = frame->width - 1;
frame->suby2 = frame->height - 1;
}

//Ensure minimum width and height of 8 pixels.
c = (frame->subx2 - frame->subx1) - 8;
Expand Down Expand Up @@ -647,7 +653,7 @@ static int get_frame(ASS_Renderer *renderer, ASS_Track *track, image_t *prev_fra
ASS_Image *img = ass_render_frame(renderer, track, ms, &changed);

if (changed && img) {
blend(frame, img, args->dimf, args->dim_flag);
blend(frame, img, args);

if (frame->subx1 > -1 && frame->suby1 > -1) {
//frame differ from the previous?
Expand Down Expand Up @@ -722,7 +728,7 @@ eventlist_t *render_subs(char *subfile, frate_t *frate, opts_t *args, liqopts_t
long long tm = 0;
int count = 0, fres = 0, img_cnt = 0;
uint64_t frame_cnt = 1;
char imgfile[15];
char imgfile[FILENAME_MAX_LENGTH];

liq_result *res;
liq_image *img;
Expand Down Expand Up @@ -767,15 +773,15 @@ eventlist_t *render_subs(char *subfile, frate_t *frate, opts_t *args, liqopts_t
frame->subx2 = frame->crops[img_cnt].x2;
frame->suby1 = frame->crops[img_cnt].y1;
frame->suby2 = frame->crops[img_cnt].y2;
snprintf(imgfile, 15, FILENAME_FMT FILENAME_CNT FILENAME_EXT, count, img_cnt);
snprintf(imgfile, FILENAME_MAX_LENGTH, FILENAME_FMT FILENAME_CNT FILENAME_EXT, count, img_cnt);
write_png(imgfile, frame);
}
}
} else {
if (args->quantize) {
write_png_palette(count, frame, &img, &res, args, 0, liqargs->dither);
} else {
snprintf(imgfile, 15, FILENAME_FMT FILENAME_EXT, count);
snprintf(imgfile, FILENAME_MAX_LENGTH, FILENAME_FMT FILENAME_EXT, count);
write_png(imgfile, frame);
}
}
Expand Down

0 comments on commit 32d3f2b

Please sign in to comment.