| 1036 | } |
| 1037 | |
| 1038 | void writeImage(int frameNum, const gfx::Rect& frameBounds, DisposalMethod disposal) { |
| 1039 | std::shared_ptr<Palette> framePaletteRef; |
| 1040 | std::unique_ptr<RgbMap> rgbmapRef; |
| 1041 | Palette* framePalette = m_sprite->palette(frameNum); |
| 1042 | RgbMap* rgbmap = m_sprite->rgbMap(frameNum); |
| 1043 | |
| 1044 | // Create optimized palette for RGB/Grayscale images |
| 1045 | if (m_quantizeColormaps) { |
| 1046 | framePaletteRef = createOptimizedPalette(frameBounds); |
| 1047 | framePalette = framePaletteRef.get(); |
| 1048 | |
| 1049 | rgbmapRef.reset(new RgbMap); |
| 1050 | rgbmap = rgbmapRef.get(); |
| 1051 | rgbmap->regenerate(framePalette, m_transparentIndex); |
| 1052 | } |
| 1053 | |
| 1054 | // We will store the frameBounds pixels in frameImage, with the |
| 1055 | // indexes that must be stored in the GIF file for this specific |
| 1056 | // frame. |
| 1057 | if (!m_frameImageBuf) |
| 1058 | m_frameImageBuf.reset(new ImageBuffer); |
| 1059 | |
| 1060 | ImageRef frameImage(Image::create(IMAGE_INDEXED, |
| 1061 | frameBounds.w, |
| 1062 | frameBounds.h, |
| 1063 | m_frameImageBuf)); |
| 1064 | |
| 1065 | // Convert the frameBounds area of m_currentImage (RGB) to frameImage (Indexed) |
| 1066 | // bool needsTransparent = false; |
| 1067 | PalettePicks usedColors(framePalette->size()); |
| 1068 | |
| 1069 | // If the sprite needs a transparent color we mark it as used so |
| 1070 | // the palette includes a spot for it. It doesn't matter if the |
| 1071 | // image doesn't use the transparent index, if the sprite isn't |
| 1072 | // opaque we need the transparent index anyway. |
| 1073 | if (m_transparentIndex >= 0) { |
| 1074 | int i = m_transparentIndex; |
| 1075 | if (i >= usedColors.size()) |
| 1076 | usedColors.resize(i+1); |
| 1077 | usedColors[i] = true; |
| 1078 | } |
| 1079 | |
| 1080 | { |
| 1081 | LockImageBits<RgbTraits> bits(m_currentImage, frameBounds); |
| 1082 | auto it = bits.begin(); |
| 1083 | for (int y=0; y<frameBounds.h; ++y) { |
| 1084 | for (int x=0; x<frameBounds.w; ++x, ++it) { |
| 1085 | ASSERT(it != bits.end()); |
| 1086 | |
| 1087 | color_t color = *it; |
| 1088 | int i; |
| 1089 | |
| 1090 | if (rgba_geta(color) >= 128) { |
| 1091 | i = framePalette->findExactMatch( |
| 1092 | rgba_getr(color), |
| 1093 | rgba_getg(color), |
| 1094 | rgba_getb(color), |
| 1095 | 255, |
nothing calls this directly
no test coverage detected