訂正です

657 で

NumPalEntry := GetPaletteEntries(Picture.Bitmap.Palette,0,255,PE);

のところの 255 を 256 にしてください。