- XColor color;
- if (x_defined_color (f, SSDATA (specified_bg), &color, 0))
- {
- png_color_16 user_bg;
-
- memset (&user_bg, 0, sizeof user_bg);
- user_bg.red = color.red >> shift;
- user_bg.green = color.green >> shift;
- user_bg.blue = color.blue >> shift;
-
- fn_png_set_background (png_ptr, &user_bg,
- PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
- }
- }
- else
- {
- /* We use the current frame background, ignoring any default
- background color set by the image. */
-#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
- XColor color;
- png_color_16 frame_background;
-
- color.pixel = FRAME_BACKGROUND_PIXEL (f);
- x_query_color (f, &color);
-
- memset (&frame_background, 0, sizeof frame_background);
- frame_background.red = color.red >> shift;
- frame_background.green = color.green >> shift;
- frame_background.blue = color.blue >> shift;
-#endif /* HAVE_X_WINDOWS */
+ int shift = bit_depth == 16 ? 0 : 8;
+ png_color_16 bg = { 0 };
+ bg.red = color.red >> shift;
+ bg.green = color.green >> shift;
+ bg.blue = color.blue >> shift;