Blender V4.3
format_svg.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
15#include "IMB_filetype.hh"
16#include "IMB_imbuf_types.hh"
17#include "nanosvgrast.h"
18
20 const int /*flags*/,
21 const size_t max_thumb_size,
22 char colorspace[],
23 size_t *r_width,
24 size_t *r_height)
25{
26 NSVGimage *image = nsvgParseFromFile(filepath, "px", 96.0f);
27
28 if (image == nullptr) {
29 return nullptr;
30 }
31
32 if (image->width == 0 || image->height == 0) {
33 nsvgDelete(image);
34 return nullptr;
35 }
36
37 int w = int(image->width);
38 int h = int(image->height);
39
40 /* Return full size of the image. */
41 *r_width = size_t(w);
42 *r_height = size_t(h);
43
44 NSVGrasterizer *rast = nsvgCreateRasterizer();
45 if (rast == nullptr) {
46 nsvgDelete(image);
47 return nullptr;
48 }
49
51
52 const float scale = float(max_thumb_size) / std::max(w, h);
53 const int dest_w = std::max(int(w * scale), 1);
54 const int dest_h = std::max(int(h * scale), 1);
55
56 ImBuf *ibuf = IMB_allocImBuf(dest_w, dest_h, 32, IB_rect);
57 if (ibuf != nullptr) {
58 nsvgRasterize(rast, image, 0, 0, scale, ibuf->byte_buffer.data, dest_w, dest_h, dest_w * 4);
59 nsvgDeleteRasterizer(rast);
60 nsvgDelete(image);
61 IMB_flipy(ibuf);
62 }
63
64 return ibuf;
65}
@ COLOR_ROLE_DEFAULT_BYTE
void IMB_flipy(ImBuf *ibuf)
#define IM_MAX_SPACE
Definition IMB_imbuf.hh:49
Contains defines and structs used throughout the imbuf module.
@ IB_rect
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
void colorspace_set_default_role(char *colorspace, int size, int role)
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
ImBuf * imb_load_filepath_thumbnail_svg(const char *filepath, const int, const size_t max_thumb_size, char colorspace[], size_t *r_width, size_t *r_height)
Definition format_svg.cc:19
struct ImBuf * IMB_allocImBuf(unsigned int, unsigned int, unsigned char, unsigned int)
ImBufByteBuffer byte_buffer