Skip to content
Myr

render: nanosvg: don't assume image is square

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Scaled image size is now w*scale x h*scale, rather than a square * Final image is centered in the icon slot

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 80947e5 · Browse files · 1 file+17 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+17 added−8 removed

  • other:+17 added−8 removed

1 file+17 added−8 removed

modified:render.c+17 added-8 removed
768 unmodified lines
769 uint64_t *abgr16 = NULL;770771 float scale = svg->width > svg->height ? size / svg->width : size / svg->height;772773 uint8_t *data_8bit = xmalloc(size * size * 4);773 const int width = roundf(svg->width * scale);774 const int height = roundf(svg->height * scale);775775 nsvgRasterize(rast, svg, 0, 0, scale, data_8bit, size, size, size * 4);776 uint8_t *data_8bit = xmalloc(width * height * 4);777778 nsvgRasterize(rast, svg, 0, 0, scale, data_8bit, width, height, width * 4);779780 img = pixman_image_create_bits_no_clear(778 PIXMAN_a8b8g8r8, size, size, (uint32_t *)data_8bit, size * 4);781 PIXMAN_a8b8g8r8, width, height, (uint32_t *)data_8bit, width * 4);782783 if (gamma_correct) {781 data_16bit = xmalloc(size * size * 8);784 data_16bit = xmalloc(width * height * 8);785 abgr16 = (uint64_t *)data_16bit;786787 img_16bit = pixman_image_create_bits_no_clear(785 PIXMAN_a16b16g16r16, size, size, (uint32_t *)data_16bit,786 size * 8);788 PIXMAN_a16b16g16r16, width, height, (uint32_t *)data_16bit,789 width * 8);790 }791792 /* Nanosvg produces non-premultiplied ABGR, while pixman expects793 * premultiplied */794795 for (uint32_t *abgr = (uint32_t *)data_8bit;793 abgr < (uint32_t *)(data_8bit + size * size * 4);796 abgr < (uint32_t *)(data_8bit + width * height * 4);797 abgr++)798 {799 uint16_t alpha = (*abgr >> 24) & 0xff;800 uint16_t blue = (*abgr >> 16) & 0xff;
47 unmodified lines
848849 tll_push_back(icon->rasterized, ((struct rasterized){img, size}));850 }851852 const int w = pixman_image_get_width(img);853 const int h = pixman_image_get_height(img);854855 pixman_image_composite32(850 PIXMAN_OP_OVER, img, NULL, pix, 0, 0, 0, 0, x, y, size, size);856 PIXMAN_OP_OVER, img, NULL, pix, 0, 0, 0, 0,857 x + (size - w) / 2,858 y + (size - h) / 2,859 w, h);860861#if defined(FUZZEL_ENABLE_CAIRO)862 cairo_surface_mark_dirty(cairo_get_target(cairo));863#endif
662 unmodified lines