+ for (i = 0; i < lpbiIn->biClrUsed; i++) {
+ pi->palette_map[i] = MSRLE32_GetNearestPaletteIndex(lpbiOut->biClrUsed, rgbOut, rgbIn[i]);
+ }
+ break;
+ case 15:
+ case 16:
+ pi->palette_map = LocalAlloc(LPTR, lpbiIn->biClrUsed * 2);
+ if (pi->palette_map == NULL)
+ return ICERR_MEMORY;
+
+ for (i = 0; i < lpbiIn->biClrUsed; i++) {
+ WORD color;
+
+ if (lpbiOut->biBitCount == 15)
+ color = ((rgbIn[i].rgbRed >> 3) << 10)
+ | ((rgbIn[i].rgbGreen >> 3) << 5) | (rgbIn[i].rgbBlue >> 3);
+ else
+ color = ((rgbIn[i].rgbRed >> 3) << 11)
+ | ((rgbIn[i].rgbGreen >> 3) << 5) | (rgbIn[i].rgbBlue >> 3);
+
+ pi->palette_map[i * 2 + 1] = color >> 8;
+ pi->palette_map[i * 2 + 0] = color & 0xFF;
+ };
+ break;
+ case 24:
+ case 32:
+ pi->palette_map = LocalAlloc(LPTR, lpbiIn->biClrUsed * sizeof(RGBQUAD));
+ if (pi->palette_map == NULL)
+ return ICERR_MEMORY;
+ memcpy(pi->palette_map, rgbIn, lpbiIn->biClrUsed * sizeof(RGBQUAD));
+ break;