Functions | |
| bool | CompressToBuffer (unsigned char *srcBuffer, int width, int height, int bpp, unsigned char *dstBuffer, int &len, int quality=75) |
| Compresses an image buffer to a JPEG image in memory. | |
| TL_DLL bool | CompressToFile (unsigned char *buffer, int width, int height, int bpp, const std::string &fileName, int quality=75) |
| Compresses an image buffer to a JPEG image file. | |
| bool | CompressToFile (unsigned char *buffer, int width, int height, int bpp, const string &fileName, int quality=75) |
| bool | DecompressBuffer (unsigned char *srcBuffer, int size, unsigned char *dstBuffer, int &width, int &height, int &bpp) |
| Decompresses a JPEG image buffer to a buffer in memory. | |
| TL_DLL bool | DecompressFile (const std::string &fileName, unsigned char *dstBuffer, int &width, int &height, int &nChannels) |
| Reads and decompresses a JPEG image file to a buffer in memory. | |
| bool | DecompressFile (const string &fileName, unsigned char *dstBuffer, int &width, int &height, int &nChannels) |
| TL_DLL bool | ReadFileParams (const std::string &fileName, int &width, int &height, int &nChannels) |
| Reads the main informations about a JPEG image file. | |
| bool | ReadFileParams (const string &fileName, int &width, int &height, int &nChannels) |
| TL_DLL bool Jpeg::CompressToBuffer | ( | unsigned char * | srcBuffer, | |
| int | width, | |||
| int | height, | |||
| int | bpp, | |||
| unsigned char * | dstBuffer, | |||
| int & | len, | |||
| int | quality = 75 | |||
| ) |
| srcBuffer | address of the image in memory | |
| width | width of image in pixels | |
| height | height of image in pixels | |
| bpp | number of bytes per pixel (1 or 3) | |
| dstBuffer | pointer to a buffer to buffer to return the compressed data. The function assumes that it was allocated with enough space to hold the compressed data | |
| len | returns the size of the compressed data. Initially this parameter should contain the size of the pre-allocated buffer | |
| quality | image quality as a percentage |
Definition at line 183 of file TeLibJpegWrapper.cpp.
Referenced by TeDecoderDatabase::putRasterBlock().
00184 { 00185 if (!srcBuffer || !dstBuffer || len<=0 ) 00186 return false; 00187 00188 JSAMPROW row_pointer[1]; 00189 int row_stride = width*bpp; 00190 00191 struct jpeg_error_mgr jerr; 00192 struct jpeg_compress_struct cinfo; 00193 jpeg_create_compress(&cinfo); 00194 cinfo.err = jpeg_std_error(&jerr); 00195 if (bpp == 3) 00196 cinfo.in_color_space = JCS_RGB; 00197 else if (bpp == 1) 00198 cinfo.in_color_space = JCS_GRAYSCALE; 00199 cinfo.image_width = width; 00200 cinfo.image_height = height; 00201 cinfo.input_components = bpp; 00202 jpeg_set_defaults(&cinfo); 00203 jpeg_set_quality(&cinfo, quality, true); 00204 00205 j_mem_dest(&cinfo,reinterpret_cast<void**>(&dstBuffer),reinterpret_cast<unsigned int*>(&len)); 00206 jpeg_start_compress(&cinfo,true); 00207 while (cinfo.next_scanline < cinfo.image_height) 00208 { 00209 row_pointer[0] = &srcBuffer[cinfo.next_scanline * row_stride]; 00210 jpeg_write_scanlines(&cinfo, row_pointer, 1); 00211 } 00212 jpeg_finish_compress(&cinfo); 00213 jpeg_destroy_compress(&cinfo); 00214 return true; 00215 }
| TL_DLL bool Jpeg::CompressToFile | ( | unsigned char * | buffer, | |
| int | width, | |||
| int | height, | |||
| int | bpp, | |||
| const std::string & | fileName, | |||
| int | quality = 75 | |||
| ) |
| buffer | address of the buffer that contains the image in memory | |
| width | width of image in pixels | |
| height | height of image in pixels | |
| bpp | number of bytes per pixel (1 or 3) | |
| fileName | name of the compressed file | |
| quality | image quality as a percentage value |
| bool Jpeg::CompressToFile | ( | unsigned char * | buffer, | |
| int | width, | |||
| int | height, | |||
| int | bpp, | |||
| const string & | fileName, | |||
| int | quality = 75 | |||
| ) |
Definition at line 134 of file TeLibJpegWrapper.cpp.
Referenced by TeDecoderJPEG::clear(), and TeDecoderJPEG::init().
00135 { 00136 // check if input parameters are valid 00137 if (fileName.empty() || !buffer || (bpp != 1 && bpp != 3) ) 00138 return false; 00139 00140 // create the destination file 00141 FILE* outfile = fopen(fileName.c_str(), "wb"); 00142 if (outfile == 0) 00143 return false; 00144 00145 // create access to source buffer as expected by jpeglib 00146 JSAMPROW row_pointer[1]; 00147 int row_stride = width*bpp; 00148 00149 // create compress structure 00150 struct jpeg_compress_struct cinfo; 00151 struct jpeg_error_mgr jerr; 00152 jpeg_create_compress(&cinfo); 00153 cinfo.err = jpeg_std_error(&jerr); 00154 00155 // set the known parameters and default parameters 00156 if (bpp == 3) 00157 cinfo.in_color_space = JCS_RGB; 00158 else if (bpp == 1) 00159 cinfo.in_color_space = JCS_GRAYSCALE; 00160 cinfo.image_width = width; 00161 cinfo.image_height = height; 00162 cinfo.input_components = bpp; 00163 jpeg_set_defaults(&cinfo); 00164 jpeg_set_quality(&cinfo, quality, true); 00165 jpeg_stdio_dest(&cinfo, outfile); 00166 00167 // decompress the data line by line 00168 jpeg_start_compress(&cinfo, true); 00169 while (cinfo.next_scanline < cinfo.image_height) 00170 { 00171 row_pointer[0] = &buffer[cinfo.next_scanline * row_stride]; 00172 jpeg_write_scanlines(&cinfo, row_pointer, 1); 00173 } 00174 00175 // release structures 00176 jpeg_finish_compress(&cinfo); 00177 jpeg_destroy_compress(&cinfo); 00178 00179 fclose(outfile); 00180 return true; 00181 }
| TL_DLL bool Jpeg::DecompressBuffer | ( | unsigned char * | srcBuffer, | |
| int | size, | |||
| unsigned char * | dstBuffer, | |||
| int & | width, | |||
| int & | height, | |||
| int & | bpp | |||
| ) |
| srcBuffer | memory address containing jpeg compressed data | |
| size | size in bytes of the jpeg compressed data | |
| dstBuffer | pointer to a buffer to return the decompressed data. The function assumes that it was allocated with enough space to hold the decompressed data | |
| width | return the number of columns of the data | |
| height | return the number of lines of the data | |
| bpp | return the number of bytes per pixel |
Definition at line 93 of file TeLibJpegWrapper.cpp.
Referenced by TeDecoderDatabase::getRasterBlock(), and TeDecoderDatabase::getSelectedRasterBlock().
00094 { 00095 if (!dstBuffer) 00096 return false; 00097 00098 struct jpeg_error_mgr jerr; 00099 struct jpeg_decompress_struct cinfo; 00100 00101 cinfo.err = jpeg_std_error(&jerr); 00102 jpeg_create_decompress(&cinfo); 00103 00104 j_mem_src (&cinfo, srcBuffer, size); 00105 00106 jpeg_read_header(&cinfo,true); 00107 jpeg_start_decompress(&cinfo); 00108 00109 width = cinfo.output_width; 00110 height = cinfo.output_height; 00111 bpp = cinfo.num_components; 00112 unsigned char* rowptr[1]; 00113 while (cinfo.output_scanline < cinfo.output_height) 00114 { 00115 rowptr[0] = &dstBuffer[cinfo.output_scanline*cinfo.output_width*cinfo.num_components]; 00116 if (rowptr[0] == 0) 00117 { 00118 jpeg_finish_decompress(&cinfo); 00119 jpeg_destroy_decompress(&cinfo); 00120 return false; 00121 } 00122 if (jpeg_read_scanlines(&cinfo, rowptr, 1) != 1) 00123 { 00124 jpeg_finish_decompress(&cinfo); 00125 jpeg_destroy_decompress(&cinfo); 00126 return false; 00127 } 00128 } 00129 jpeg_finish_decompress(&cinfo); 00130 jpeg_destroy_decompress(&cinfo); 00131 return true; 00132 }
| TL_DLL bool Jpeg::DecompressFile | ( | const std::string & | fileName, | |
| unsigned char * | dstBuffer, | |||
| int & | width, | |||
| int & | height, | |||
| int & | nChannels | |||
| ) |
| fileName | name of the file | |
| dstBuffer | pointer to a buffer to return the decompressed data. The function assumes that it was allocated with enough space to hold the decompressed data | |
| width | returns the number of columns of the data | |
| height | returns the number of lines of the data | |
| nChannels | returns the number of bands, or channels, of the data |
| bool Jpeg::DecompressFile | ( | const string & | fileName, | |
| unsigned char * | dstBuffer, | |||
| int & | width, | |||
| int & | height, | |||
| int & | nChannels | |||
| ) |
Definition at line 60 of file TeLibJpegWrapper.cpp.
Referenced by TeDecoderJPEG::init().
00061 { 00062 if (!dstBuffer || fileName.empty()) 00063 return false; 00064 00065 FILE* infile; 00066 if ((infile = fopen(fileName.c_str(), "rb")) == 0) 00067 return false; 00068 00069 struct jpeg_error_mgr jerr; 00070 struct jpeg_decompress_struct cinfo; 00071 cinfo.err = jpeg_std_error(&jerr); 00072 jpeg_create_decompress(&cinfo); 00073 jpeg_stdio_src(&cinfo, infile); 00074 jpeg_read_header(&cinfo, true); 00075 jpeg_start_decompress(&cinfo); 00076 00077 width = cinfo.output_width; 00078 height = cinfo.output_height; 00079 nChannels = cinfo.num_components; 00080 00081 unsigned char* rowptr[1]; 00082 while (cinfo.output_scanline < cinfo.output_height) 00083 { 00084 rowptr[0] = &dstBuffer[cinfo.output_scanline*cinfo.output_width*cinfo.num_components]; 00085 jpeg_read_scanlines(&cinfo, rowptr, 1); 00086 } 00087 jpeg_finish_decompress(&cinfo); 00088 jpeg_destroy_decompress(&cinfo); 00089 fclose(infile); 00090 return true; 00091 }
| TL_DLL bool Jpeg::ReadFileParams | ( | const std::string & | fileName, | |
| int & | width, | |||
| int & | height, | |||
| int & | nChannels | |||
| ) |
| fileName | name of the file | |
| width | return the number of columns of the data | |
| height | return the number of lines of the data | |
| nChannels | return the number of bands, or channels, of the data |
Definition at line 34 of file TeLibJpegWrapper.cpp.
Referenced by TeDecoderJPEG::TeDecoderJPEG().
00035 { 00036 if (fileName.empty()) 00037 return false; 00038 00039 FILE* infile; 00040 if ((infile = fopen(fileName.c_str(), "rb")) == 0) 00041 return false; 00042 00043 struct jpeg_decompress_struct cinfo; 00044 struct jpeg_error_mgr jerr; 00045 cinfo.err = jpeg_std_error(&jerr); 00046 jpeg_create_decompress(&cinfo); 00047 00048 jpeg_stdio_src(&cinfo, infile); 00049 jpeg_read_header(&cinfo, true); 00050 jpeg_calc_output_dimensions(&cinfo); 00051 00052 width = cinfo.image_width; 00053 height = cinfo.image_height; 00054 nChannels = cinfo.num_components; 00055 jpeg_destroy_decompress(&cinfo); 00056 fclose(infile); 00057 return true; 00058 }
1.5.3