'colormap'에 해당되는 글 2건

  1. 2009.07.14 libjpeg colormap - 256 color jpeg
  2. 2009.07.10 libjpeg colormap관련 링크 (2)
프로그램 사용/libjpeg2009. 7. 14. 17:34
jpeg는 grayscale일 경우에는 무조건 흑백인 듯 하다.
(조금 더 확실하게 검색필요)

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

wrbmp.c 파일을 참고 하자면
write_colormap (j_decompress_ptr cinfo, bmp_dest_ptr dest,
		int map_colors, int map_entry_size)
  JSAMPARRAY colormap = cinfo->colormap;
  int num_colors = cinfo->actual_number_of_colors;
  FILE * outfile = dest->pub.output_file;
  int i;

  if (colormap != NULL) {
    if (cinfo->out_color_components == 3) {
      /* Normal case with RGB colormap */
      for (i = 0; i < num_colors; i++) {
	putc(GETJSAMPLE(colormap[2][i]), outfile);
	putc(GETJSAMPLE(colormap[1][i]), outfile);
	putc(GETJSAMPLE(colormap[0][i]), outfile);
	if (map_entry_size == 4)
	  putc(0, outfile);
    } else {
      /* Grayscale colormap (only happens with grayscale quantization) */
      for (i = 0; i < num_colors; i++) {
	putc(GETJSAMPLE(colormap[0][i]), outfile);
	putc(GETJSAMPLE(colormap[0][i]), outfile);
	putc(GETJSAMPLE(colormap[0][i]), outfile);
	if (map_entry_size == 4)
	  putc(0, outfile);
  } else {
    /* If no colormap, must be grayscale data.  Generate a linear "map". */
    for (i = 0; i < 256; i++) {
      putc(i, outfile);
      putc(i, outfile);
      putc(i, outfile);
      if (map_entry_size == 4)
	putc(0, outfile);
  /* Pad colormap with zeros to ensure specified number of colormap entries */ 
  if (i > map_colors)
for (; i < map_colors; i++) { putc(0, outfile); putc(0, outfile); putc(0, outfile); if (map_entry_size == 4) putc(0, outfile);

이런식으로 0에서 255 까지 팔레트를 생성하면 되고,
256color(=8bit) 일 경우에는 팔레트는 RGBQUAD 로 4바이트 구조이므로,
마지막 바이트는 reserve(혹은 alpha) 값으로 0x00(stfae에서는0x80) 을 해주면 된다.
Posted by 구차니
프로그램 사용/libjpeg2009. 7. 10. 17:34
일단 해보니..
struct jpeg_decompress_struct 에
quantize_colors 항목을 TRUE로 설정해주면
colormap 에 팔레트가 생성이되고,
actual_number_of_colors 에는 실제 사용한 색상수 출력이 된다고 하는데..

팔레트가 어떻게 되는지 libjpeg.doc에 제대로 나와있지 않다..
아래의 링크를 조금은 유심히 보고 수정요망

After this call, the final output image dimensions, including any requested
scaling, are available in the JPEG object; so is the selected colormap, if
colormapped output has been requested.  Useful fields include

    output_width        image width and height, as scaled
    out_color_components    # of color components in out_color_space
    output_components    # of color components returned per pixel
    colormap        the selected colormap, if any
    actual_number_of_colors        number of entries in colormap

output_components is 1 (a colormap index) when quantizing colors; otherwise it
equals out_color_components.  It is the number of JSAMPLE values that will be
emitted per pixel in the output arrays.

Typically you will need to allocate data buffers to hold the incoming image.
You will need output_width * output_components JSAMPLEs per scanline in your
output buffer, and a total of output_height scanlines will be returned.

Note: if you are using the JPEG library's internal memory manager to allocate
data buffers (as djpeg does), then the manager's protocol requires that you
request large buffers *before* calling jpeg_start_decompress().  This is a
little tricky since the output_XXX fields are not normally valid then.  You
can make them valid by calling jpeg_calc_output_dimensions() after setting the
relevant parameters (scaling, output color space, and quantization flag).


The decompression parameters that determine the basic properties of the
returned image are:

J_COLOR_SPACE out_color_space
    Output color space.  jpeg_read_header() sets an appropriate default
    based on jpeg_color_space; typically it will be RGB or grayscale.
    The application can change this field to request output in a different
    colorspace.  For example, set it to JCS_GRAYSCALE to get grayscale
    output from a color file.  (This is useful for previewing: grayscale
    output is faster than full color since the color components need not
    be processed.)  Note that not all possible color space transforms are
    currently implemented; you may need to extend jdcolor.c if you want an
    unusual conversion.


boolean quantize_colors
    If set TRUE, colormapped output will be delivered.  Default is FALSE,
    meaning that full-color output will be delivered.


When quantize_colors is TRUE, the target color map is described by the next
two fields.  colormap is set to NULL by jpeg_read_header().  The application
can supply a color map by setting colormap non-NULL and setting
actual_number_of_colors to the map size.  Otherwise, jpeg_start_decompress()
selects a suitable color map and sets these two fields itself.
[Implementation restriction: at present, an externally supplied colormap is
only accepted for 3-component output color spaces.]

    The color map, represented as a 2-D pixel array of out_color_components
    rows and actual_number_of_colors columns.  Ignored if not quantizing.
    CAUTION: if the JPEG library creates its own colormap, the storage
    pointed to by this field is released by jpeg_finish_decompress().
    Copy the colormap somewhere else first, if you want to save it.

int actual_number_of_colors
    The number of colors in the color map.


int out_color_components    Number of color components in out_color_space.
int output_components        Number of color components returned.

[출처 : libjpeg.doc]

[링크 : http://svn.neurostechnology.com/filedetails.php]
[링크 : http://www.koders.com/c/fid95CCE6190079AB3FDDE3C71309BA75EB5BA943FC.aspx]
Posted by 구차니