/*
* Ordering of RGB data in scanlines passed to or from the application.
* If your application wants to deal with data in the order B,G,R, just
* change these macros. You can also deal with formats such as R,G,B,X
* (one extra byte per pixel) by changing RGB_PIXELSIZE. Note that changing
* the offsets will also change the order in which colormap data is organized.
* RESTRICTIONS:
* 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats.
* 2. These macros only affect RGB<=>YCbCr color conversion, so they are not
* useful if you are using JPEG color spaces other than YCbCr or grayscale.
* 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE
* is not 3 (they don't understand about dummy color components!). So you
* can't use color quantization if you change that value.
*/
#define RGB_RED 0 /* Offset of Red in an RGB scanline element */
#define RGB_GREEN 1 /* Offset of Green */
#define RGB_BLUE 2 /* Offset of Blue */
#define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
libjpeg를 일반적인 표준 Bitmap 파일에 적용하기 위해서는 (혹은 Blit 함수에) RGBQUAD나 RGBTRIPLE과 동일한 구조로 나오는 것이 좋다.
unsigned int scale_num, scale_denom
scale_num/scale_denom 의 분수비로 영상 비율을 조절합니다.
기본값은 1/1 혹은 조절하지 않음입니다.
현재, 지원되는 조정 비율은 1/1, 1/2, 1/4, 1/8 입니다.
(라이브러리 설계는 무제한의 비율이 가능하도록 되어있지만,
빠른시일내로 적용되기는 힘들것으로 보입니다.)
작은 조절 비율은 적은 수의 픽셀 연산과 단순화된 IDCT 방법을
사용 할 수 있기 때문에, 매우 빠른 속도의 변환을 합니다
(scale_num은 분자, scale_denom은 분모입니다. 만약에 1/4로 하려고 한다면 scale_num = 1; scale_denom = 4; 로 하면 될 듯 합니다
- 확인요망)
unsigned int scale_num, scale_denom
Scale the image by the fraction scale_num/scale_denom. Default is
1/1, or no scaling. Currently, the only supported scaling ratios
are 1/1, 1/2, 1/4, and 1/8. (The library design allows for arbitrary
scaling ratios but this is not likely to be implemented any time soon.)
Smaller scaling ratios permit significantly faster decoding since
fewer pixels need be processed and a simpler IDCT method can be used.
6. while (scan lines remain to be read)
jpeg_read_scanlines(...);
jpeg_read_scanlines()을 한번 혹은 여러번 호출함으로서 압축해제 된 영상정보를 읽을 수 있습니다.
각각의 호출시에, 읽을 최대 scanline을 넘겨줍니다
(예를들어, working buffer의 높이); jpeg_read_scanlines() 은
많은 줄들의 값을 돌려줄 것 입니다. 돌려준 값은 실제로 읽은 줄의 갯수입니다.
돌려받은 영상정보의 형태(format)는 위의 "Data formats"에 기술되어 있습니다.
흑백과 색상이 있는 JPEG는 서로 다른 데이터 형태라는 것을 잊지마십시오!
영상정보는 상-하 순서로 주어집니다. 만약에 하-상 순서로 영상정보를 저장해야 한다면,
효과적으로 JPEG 라이브러리의 가상 배열 방식을 사용하여 뒤집을 수 있습니다.
예제 프로그램인 djpeg에서 이러한 사용예를 찾으실 수 있습니다.
6. while (scan lines remain to be read)
jpeg_read_scanlines(...);
Now you can read the decompressed image data by calling jpeg_read_scanlines()
one or more times. At each call, you pass in the maximum number of scanlines
to be read (ie, the height of your working buffer); jpeg_read_scanlines()
will return up to that many lines. The return value is the number of lines
actually read. The format of the returned data is discussed under "Data
formats", above. Don't forget that grayscale and color JPEGs will return
different data formats!
Image data is returned in top-to-bottom scanline order. If you must write
out the image in bottom-to-top order, you can use the JPEG library's virtual
array mechanism to invert the data efficiently. Examples of this can be
found in the sample application djpeg.
The library maintains a count of the number of scanlines returned so far
in the output_scanline field of the JPEG object. Usually you can just use
this variable as the loop counter, so that the loop test looks like
"while (cinfo.output_scanline < cinfo.output_height)". (Note that the test
should NOT be against image_height, unless you never use scaling. The image_height field is the height of the original unscaled image.)
The return value always equals the change in the value of output_scanline.
If you don't use a suspending data source, it is safe to assume that
jpeg_read_scanlines() reads at least one scanline per call, until the
bottom of the image has been reached.
If you use a buffer larger than one scanline, it is NOT safe to assume that
jpeg_read_scanlines() fills it. (The current implementation returns only a
few scanlines per call, no matter how large a buffer you pass.) So you must
always provide a loop that calls jpeg_read_scanlines() repeatedly until the
whole image has been read.
Data formats
픽셀들은 scanline 단위로 왼쪽에서 오른쪽 방향으로 저장됩니다
각각의 픽셀을 위한 값들은 열단위로 나란히 있습니다;
24-bit RGB 를 예를 들자면, R,G,B,R,G,B,R,G,B 순서로 되어있습니다. 각각의 scanline은
JSAMPLE 데이터 형의 배열로 되어있습니다 --- jmorecfg.h를 수정하지 않았다면,
일반적으로 "unsigned char" 입니다. (또한 jmorecfg.h를 수정함으로서
RGB 픽셀의 순서를 B,G,R 순서로 변경할수도 있습니다. 하지만 수정전에 제약사항을
먼저 읽어 보시기 바랍니다.)
Data formats
------------
Before diving into procedural details, it is helpful to understand the
image data format that the JPEG library expects or returns.
The standard input image format is a rectangular array of pixels, with each
pixel having the same number of "component" or "sample" values (color
channels). You must specify how many components there are and the colorspace
interpretation of the components. Most applications will use RGB data
(three components per pixel) or grayscale data (one component per pixel).
PLEASE NOTE THAT RGB DATA IS THREE SAMPLES PER PIXEL, GRAYSCALE ONLY ONE.
A remarkable number of people manage to miss this, only to find that their
programs don't work with grayscale JPEG files.
There is no provision for colormapped input. JPEG files are always full-color
or full grayscale (or sometimes another colorspace such as CMYK). You can
feed in a colormapped image by expanding it to full-color format. However
JPEG often doesn't work very well with source data that has been colormapped,
because of dithering noise. This is discussed in more detail in the JPEG FAQ
and the other references mentioned in the README file.
Pixels are stored by scanlines, with each scanline running from left to
right. The component values for each pixel are adjacent in the row; for
example, R,G,B,R,G,B,R,G,B,... for 24-bit RGB color. Each scanline is an
array of data type JSAMPLE --- which is typically "unsigned char", unless you've changed jmorecfg.h. (You can also change the RGB pixel layout, say
to B,G,R order, by modifying jmorecfg.h. But see the restrictions listed in
that file before doing so.)
int w = cinfo.image_width;
int h = cinfo.image_height;
int d = cinfo.jpeg_color_space;
int out_h = cinfo.output_height;
printf("width:%d height:%d depth:%d out_height:%d\n", w, h ,d, out_h);
unsigned char *data = new unsigned char[w * h * d];
while (cinfo.output_scanline < cinfo.output_height)
{
jpeg_read_scanlines(&cinfo, &data, 1);
data += d * cinfo.output_width;
}
jpeg_read_header() 한뒤
jpeg_read_scanline()까지는 알았지만, 문서를 대충 읽다 보니..
도무니 어떻게 메모리를 할당해야 할지 감이 안 잡혔는데..
이 문서를 보니 어떻게 하면 될꺼 같다라는 감이 조금은 온다.. 내일 해보고 결과를 적도록 해야겠다.
위에서 대로 전체 할당하고 jpeg_read_scanlines로 읽어 오니 잘된다!