Access point for applications wishing to use the jpeg library directly in conjunction with DevIL. The decompressor must be set up with an input source and all desired parameters this function is called. The caller must call jpeg_finish_decompress because the caller may still need decompressor after calling this for e.g. examining saved markers.
| 856 | // the caller may still need decompressor after calling this for e.g. examining |
| 857 | // saved markers. |
| 858 | ILboolean ilLoadFromJpegStruct(void *_JpegInfo) |
| 859 | { |
| 860 | #ifndef IL_NO_JPG |
| 861 | #ifndef IL_USE_IJL |
| 862 | // sam. void (*errorHandler)(j_common_ptr); |
| 863 | ILubyte *TempPtr[1]; |
| 864 | ILuint Returned; |
| 865 | j_decompress_ptr JpegInfo = (j_decompress_ptr)_JpegInfo; |
| 866 | |
| 867 | //added on 2003-08-31 as explained in sf bug 596793 |
| 868 | jpgErrorOccured = IL_FALSE; |
| 869 | |
| 870 | // sam. errorHandler = JpegInfo->err->error_exit; |
| 871 | // sam. JpegInfo->err->error_exit = ExitErrorHandle; |
| 872 | jpeg_start_decompress((j_decompress_ptr)JpegInfo); |
| 873 | |
| 874 | if (!ilTexImage(JpegInfo->output_width, JpegInfo->output_height, 1, (ILubyte)JpegInfo->output_components, 0, IL_UNSIGNED_BYTE, NULL)) { |
| 875 | return IL_FALSE; |
| 876 | } |
| 877 | iCurImage->Origin = IL_ORIGIN_UPPER_LEFT; |
| 878 | |
| 879 | switch (iCurImage->Bpp) |
| 880 | { |
| 881 | case 1: |
| 882 | iCurImage->Format = IL_LUMINANCE; |
| 883 | break; |
| 884 | case 3: |
| 885 | iCurImage->Format = IL_RGB; |
| 886 | break; |
| 887 | case 4: |
| 888 | iCurImage->Format = IL_RGBA; |
| 889 | break; |
| 890 | default: |
| 891 | //@TODO: Anyway to get here? Need to error out or something... |
| 892 | break; |
| 893 | } |
| 894 | |
| 895 | TempPtr[0] = iCurImage->Data; |
| 896 | while (JpegInfo->output_scanline < JpegInfo->output_height) { |
| 897 | Returned = jpeg_read_scanlines(JpegInfo, TempPtr, 1); // anyway to make it read all at once? |
| 898 | TempPtr[0] += iCurImage->Bps; |
| 899 | if (Returned == 0) |
| 900 | break; |
| 901 | } |
| 902 | |
| 903 | // sam. JpegInfo->err->error_exit = errorHandler; |
| 904 | |
| 905 | if (jpgErrorOccured) |
| 906 | return IL_FALSE; |
| 907 | |
| 908 | return ilFixImage(); |
| 909 | #endif |
| 910 | #endif |
| 911 | return IL_FALSE; |
| 912 | } |
| 913 | |
| 914 | |
| 915 |
no test coverage detected