summaryrefslogtreecommitdiffstats
path: root/test/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/test.c')
-rw-r--r--test/test.c84
1 files changed, 9 insertions, 75 deletions
diff --git a/test/test.c b/test/test.c
index 4884b28..125c9ad 100644
--- a/test/test.c
+++ b/test/test.c
@@ -24,11 +24,6 @@
#include "../libass/ass.h"
#include <png.h>
-typedef struct image_s {
- int width, height, stride;
- unsigned char *buffer; // RGB24
-} image_t;
-
ASS_Library *ass_library;
ASS_Renderer *ass_renderer;
@@ -41,7 +36,7 @@ void msg_callback(int level, const char *fmt, va_list va, void *data)
printf("\n");
}
-static void write_png(char *fname, image_t *img)
+static void write_png(char *fname, ASS_Image *img)
{
FILE *fp;
png_structp png_ptr;
@@ -69,17 +64,15 @@ static void write_png(char *fname, image_t *img)
png_init_io(png_ptr, fp);
png_set_compression_level(png_ptr, 0);
- png_set_IHDR(png_ptr, info_ptr, img->width, img->height,
- 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
+ png_set_IHDR(png_ptr, info_ptr, img->w, img->h,
+ 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_write_info(png_ptr, info_ptr);
- png_set_bgr(png_ptr);
-
- row_pointers = (png_byte **) malloc(img->height * sizeof(png_byte *));
- for (k = 0; k < img->height; k++)
- row_pointers[k] = img->buffer + img->stride * k;
+ row_pointers = (png_byte **) malloc(img->h * sizeof(png_byte *));
+ for (k = 0; k < img->h; k++)
+ row_pointers[k] = img->bitmap + img->stride * k;
png_write_image(png_ptr, row_pointers);
png_write_end(png_ptr, info_ptr);
@@ -111,61 +104,6 @@ static void init(int frame_w, int frame_h)
ASS_FONTPROVIDER_AUTODETECT, NULL, 1);
}
-static image_t *gen_image(int width, int height)
-{
- image_t *img = malloc(sizeof(image_t));
- img->width = width;
- img->height = height;
- img->stride = width * 3;
- img->buffer = (unsigned char *) calloc(1, height * width * 3);
- memset(img->buffer, 63, img->stride * img->height);
- //for (int i = 0; i < height * width * 3; ++i)
- // img->buffer[i] = (i/3/50) % 100;
- return img;
-}
-
-#define _r(c) ((c)>>24)
-#define _g(c) (((c)>>16)&0xFF)
-#define _b(c) (((c)>>8)&0xFF)
-#define _a(c) ((c)&0xFF)
-
-static void blend_single(image_t * frame, ASS_Image *img)
-{
- int x, y;
- unsigned char opacity = 255 - _a(img->color);
- unsigned char r = _r(img->color);
- unsigned char g = _g(img->color);
- unsigned char b = _b(img->color);
-
- unsigned char *src;
- unsigned char *dst;
-
- src = img->bitmap;
- dst = frame->buffer + img->dst_y * frame->stride + img->dst_x * 3;
- for (y = 0; y < img->h; ++y) {
- for (x = 0; x < img->w; ++x) {
- unsigned k = ((unsigned) src[x]) * opacity / 255;
- // possible endianness problems
- dst[x * 3] = (k * b + (255 - k) * dst[x * 3]) / 255;
- dst[x * 3 + 1] = (k * g + (255 - k) * dst[x * 3 + 1]) / 255;
- dst[x * 3 + 2] = (k * r + (255 - k) * dst[x * 3 + 2]) / 255;
- }
- src += img->stride;
- dst += frame->stride;
- }
-}
-
-static void blend(image_t * frame, ASS_Image *img)
-{
- int cnt = 0;
- while (img) {
- blend_single(frame, img);
- ++cnt;
- img = img->next;
- }
- printf("%d images blended\n", cnt);
-}
-
char *font_provider_labels[] = {
[ASS_FONTPROVIDER_NONE] = "None",
[ASS_FONTPROVIDER_AUTODETECT] = "Autodetect",
@@ -210,18 +148,14 @@ int main(int argc, char *argv[])
return 1;
}
- ASS_Image *img =
- ass_render_frame(ass_renderer, track, (int) (tm * 1000), NULL);
- image_t *frame = gen_image(frame_w, frame_h);
- blend(frame, img);
+ ASS_Image *img = ass_render_rgba_frame(ass_renderer, track, (int) (tm * 1000), NULL, 1);
ass_free_track(track);
ass_renderer_done(ass_renderer);
ass_library_done(ass_library);
- write_png(imgfile, frame);
- free(frame->buffer);
- free(frame);
+ write_png(imgfile, img);
+ ass_frame_unref(img);
return 0;
}