프로그램 사용/libjpeg2009. 7. 14. 17:34
jpeg는 grayscale일 경우에는 무조건 흑백인 듯 하다.
(조금 더 확실하게 검색필요)

그런 이유로, 8bit color일 경우에는 팔레트가 NULL인지 아닌지 확인하고
NULL일 경우에는 팔레트를 만들어주면 된다.

wrbmp.c 파일을 참고 하자면
01LOCAL(void)
02write_colormap (j_decompress_ptr cinfo, bmp_dest_ptr dest,
03        int map_colors, int map_entry_size)
04{
05  JSAMPARRAY colormap = cinfo->colormap;
06  int num_colors = cinfo->actual_number_of_colors;
07  FILE * outfile = dest->pub.output_file;
08  int i;
09 
10  if (colormap != NULL) {
11    if (cinfo->out_color_components == 3) {
12      /* Normal case with RGB colormap */
13      for (i = 0; i < num_colors; i++) {
14    putc(GETJSAMPLE(colormap[2][i]), outfile);
15    putc(GETJSAMPLE(colormap[1][i]), outfile);
16    putc(GETJSAMPLE(colormap[0][i]), outfile);
17    if (map_entry_size == 4)
18      putc(0, outfile);
19      }
20    } else {
21      /* Grayscale colormap (only happens with grayscale quantization) */
22      for (i = 0; i < num_colors; i++) {
23    putc(GETJSAMPLE(colormap[0][i]), outfile);
24    putc(GETJSAMPLE(colormap[0][i]), outfile);
25    putc(GETJSAMPLE(colormap[0][i]), outfile);
26    if (map_entry_size == 4)
27      putc(0, outfile);
28      }
29    }
30  } else {
31    /* If no colormap, must be grayscale data.  Generate a linear "map". */
32    for (i = 0; i < 256; i++) {
33      putc(i, outfile);
34      putc(i, outfile);
35      putc(i, outfile);
36      if (map_entry_size == 4)
37    putc(0, outfile);
38    }
39  }
40  /* Pad colormap with zeros to ensure specified number of colormap entries */
41  if (i > map_colors)
42    ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, i);
43 
44  for (; i < map_colors; i++) {
45    putc(0, outfile);
46    putc(0, outfile);
47    putc(0, outfile);
48    if (map_entry_size == 4)
49      putc(0, outfile);
50 
51  }
52 
53}

이런식으로 0에서 255 까지 팔레트를 생성하면 되고,
256color(=8bit) 일 경우에는 팔레트는 RGBQUAD 로 4바이트 구조이므로,
마지막 바이트는 reserve(혹은 alpha) 값으로 0x00(stfae에서는0x80) 을 해주면 된다.
Posted by 구차니