@@ -109,10 +109,6 @@ namespace LV {
109109 auto color_type = png_get_color_type (png_ptr, info_ptr);
110110 auto bit_depth = png_get_bit_depth (png_ptr, info_ptr);
111111
112- if (color_type == PNG_COLOR_TYPE_PALETTE) {
113- png_set_palette_to_rgb (png_ptr);
114- }
115-
116112 if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8 ) {
117113 png_set_expand_gray_1_2_4_to_8 (png_ptr);
118114 }
@@ -143,6 +139,9 @@ namespace LV {
143139 VisVideoDepth depth = VISUAL_VIDEO_DEPTH_NONE;
144140
145141 switch (png_get_color_type (png_ptr, info_ptr)) {
142+ case PNG_COLOR_TYPE_PALETTE:
143+ depth = VISUAL_VIDEO_DEPTH_8BIT;
144+ break ;
146145 case PNG_COLOR_TYPE_RGB:
147146 depth = VISUAL_VIDEO_DEPTH_24BIT;
148147 break ;
@@ -169,11 +168,30 @@ namespace LV {
169168
170169 png_read_image (png_ptr, pixel_row_ptrs);
171170
171+ auto video = Video::wrap (pixels, true , width, height, depth);
172+
173+ if (depth == VISUAL_VIDEO_DEPTH_8BIT) {
174+ png_colorp file_palette = nullptr ;
175+ int file_color_count = 0 ;
176+ png_get_PLTE (png_ptr, info_ptr, &file_palette, &file_color_count);
177+
178+ LV::Palette palette (256 );
179+ int color_count = std::min (256 , file_color_count);
180+
181+ for (int i = 0 ; i < color_count; i++) {
182+ auto & color = palette.colors [i];
183+ color.r = file_palette[i].red ;
184+ color.g = file_palette[i].green ;
185+ color.b = file_palette[i].blue ;
186+ }
187+ video->set_palette (std::move (palette));
188+ }
189+
172190 png_destroy_read_struct (&png_ptr, &info_ptr, &end_info);
173191
174192 delete [] pixel_row_ptrs;
175193
176- return Video::wrap (pixels, true , width, height, depth) ;
194+ return video ;
177195 }
178196
179197} // LV namespace
0 commit comments