MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / resize_image

Function resize_image

src/doc/algorithm/resize_image.cpp:42–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42void resize_image(const Image* src, Image* dst, ResizeMethod method, const Palette* pal, const RgbMap* rgbmap, color_t maskColor)
43{
44 switch (method) {
45
46 // TODO optimize this
47 case RESIZE_METHOD_NEAREST_NEIGHBOR: {
48 ASSERT(src->pixelFormat() == dst->pixelFormat());
49
50 switch (src->pixelFormat()) {
51 case IMAGE_RGB: resize_image_nearest<RgbTraits>(src, dst); break;
52 case IMAGE_GRAYSCALE: resize_image_nearest<GrayscaleTraits>(src, dst); break;
53 case IMAGE_INDEXED: resize_image_nearest<IndexedTraits>(src, dst); break;
54 case IMAGE_BITMAP: resize_image_nearest<BitmapTraits>(src, dst); break;
55 }
56 break;
57 }
58
59 // TODO optimize this
60 case RESIZE_METHOD_BILINEAR: {
61 uint32_t color[4], dst_color = 0;
62 double u, v, du, dv;
63 int u_floor, u_floor2;
64 int v_floor, v_floor2;
65 int x, y;
66
67 u = v = 0.0;
68 du = (src->width()-1) * 1.0 / (dst->width()-1);
69 dv = (src->height()-1) * 1.0 / (dst->height()-1);
70 for (y=0; y<dst->height(); ++y) {
71 for (x=0; x<dst->width(); ++x) {
72 u_floor = (int)floor(u);
73 v_floor = (int)floor(v);
74
75 if (u_floor > src->width()-1) {
76 u_floor = src->width()-1;
77 u_floor2 = src->width()-1;
78 }
79 else if (u_floor == src->width()-1)
80 u_floor2 = u_floor;
81 else
82 u_floor2 = u_floor+1;
83
84 if (v_floor > src->height()-1) {
85 v_floor = src->height()-1;
86 v_floor2 = src->height()-1;
87 }
88 else if (v_floor == src->height()-1)
89 v_floor2 = v_floor;
90 else
91 v_floor2 = v_floor+1;
92
93 // get the four colors
94 color[0] = src->getPixel(u_floor, v_floor);
95 color[1] = src->getPixel(u_floor2, v_floor);
96 color[2] = src->getPixel(u_floor, v_floor2);
97 color[3] = src->getPixel(u_floor2, v_floor2);
98
99 // calculate the interpolated color

Callers 2

onJobMethod · 0.85
TESTFunction · 0.85

Calls 15

rgba_getrFunction · 0.85
rgba_getgFunction · 0.85
rgba_getbFunction · 0.85
rgba_getaFunction · 0.85
graya_getvFunction · 0.85
graya_getaFunction · 0.85
grayaFunction · 0.85
rotsprite_imageFunction · 0.85
getEntryMethod · 0.80
mapColorMethod · 0.80
rgbaFunction · 0.50
pixelFormatMethod · 0.45

Tested by 1

TESTFunction · 0.68