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

Function convert_pixel_format

src/render/quantization.cpp:86–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86Image* convert_pixel_format(
87 const Image* image,
88 Image* new_image,
89 PixelFormat pixelFormat,
90 DitheringMethod ditheringMethod,
91 const RgbMap* rgbmap,
92 const Palette* palette,
93 bool is_background,
94 color_t new_mask_color)
95{
96 if (!new_image)
97 new_image = Image::create(pixelFormat, image->width(), image->height());
98 new_image->setMaskColor(new_mask_color);
99
100 // RGB -> Indexed with ordered dithering
101 if (image->pixelFormat() == IMAGE_RGB &&
102 pixelFormat == IMAGE_INDEXED &&
103 ditheringMethod == DitheringMethod::ORDERED) {
104 BayerMatrix<8> matrix;
105 OrderedDither dither;
106 dither.ditherRgbImageToIndexed(matrix, image, new_image, 0, 0, rgbmap, palette);
107 return new_image;
108 }
109
110 color_t c;
111 int r, g, b, a;
112
113 switch (image->pixelFormat()) {
114
115 case IMAGE_RGB: {
116 const LockImageBits<RgbTraits> srcBits(image);
117 LockImageBits<RgbTraits>::const_iterator src_it = srcBits.begin(), src_end = srcBits.end();
118
119 switch (new_image->pixelFormat()) {
120
121 // RGB -> RGB
122 case IMAGE_RGB:
123 new_image->copy(image, gfx::Clip(image->bounds()));
124 break;
125
126 // RGB -> Grayscale
127 case IMAGE_GRAYSCALE: {
128 LockImageBits<GrayscaleTraits> dstBits(new_image, Image::WriteLock);
129 LockImageBits<GrayscaleTraits>::iterator dst_it = dstBits.begin();
130#ifdef _DEBUG
131 LockImageBits<GrayscaleTraits>::iterator dst_end = dstBits.end();
132#endif
133
134 for (; src_it != src_end; ++src_it, ++dst_it) {
135 ASSERT(dst_it != dst_end);
136 c = *src_it;
137
138 g = 255 * Hsv(Rgb(rgba_getr(c),
139 rgba_getg(c),
140 rgba_getb(c))).valueInt() / 100;
141
142 *dst_it = graya(g, rgba_geta(c));
143 }

Callers 5

onExecuteMethod · 0.85
SetPixelFormatMethod · 0.85
pasteFunction · 0.85
create_cel_copyFunction · 0.85

Calls 15

rgba_getrFunction · 0.85
rgba_getgFunction · 0.85
rgba_getbFunction · 0.85
grayaFunction · 0.85
rgba_getaFunction · 0.85
graya_getvFunction · 0.85
graya_getaFunction · 0.85
valueIntMethod · 0.80
mapColorMethod · 0.80
getEntryMethod · 0.80
ClipClass · 0.70

Tested by

no test coverage detected