OLD | NEW |
1 /* | 1 /* |
2 * jdmarker.c | 2 * jdmarker.c |
3 * | 3 * |
4 * Copyright (C) 1991-1998, Thomas G. Lane. | 4 * Copyright (C) 1991-1998, Thomas G. Lane. |
5 * This file is part of the Independent JPEG Group's software. | 5 * This file is part of the Independent JPEG Group's software. |
6 * For conditions of distribution and use, see the accompanying README file. | 6 * For conditions of distribution and use, see the accompanying README file. |
7 * | 7 * |
8 * This file contains routines to decode JPEG datastream markers. | 8 * This file contains routines to decode JPEG datastream markers. |
9 * Most of the complexity arises from our desire to support input | 9 * Most of the complexity arises from our desire to support input |
10 * suspension: if not all of the data for a marker is available, | 10 * suspension: if not all of the data for a marker is available, |
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 INPUT_BYTE(cinfo, c2, return FALSE); | 933 INPUT_BYTE(cinfo, c2, return FALSE); |
934 if (c != 0xFF || c2 != (int) M_SOI) | 934 if (c != 0xFF || c2 != (int) M_SOI) |
935 ERREXIT2(cinfo, JERR_NO_SOI, c, c2); | 935 ERREXIT2(cinfo, JERR_NO_SOI, c, c2); |
936 | 936 |
937 cinfo->unread_marker = c2; | 937 cinfo->unread_marker = c2; |
938 | 938 |
939 INPUT_SYNC(cinfo); | 939 INPUT_SYNC(cinfo); |
940 return TRUE; | 940 return TRUE; |
941 } | 941 } |
942 | 942 |
| 943 #ifdef MOTION_JPEG_SUPPORTED |
| 944 |
| 945 /* The default Huffman tables used by motion JPEG frames. When a motion JPEG |
| 946 * frame does not have DHT tables, we should use the huffman tables suggested by |
| 947 * the JPEG standard. Each of these tables represents a member of the JHUFF_TBLS |
| 948 * struct so we can just copy it to the according JHUFF_TBLS member. |
| 949 */ |
| 950 /* DC table 0 */ |
| 951 LOCAL(const unsigned char) mjpg_dc0_bits[] = { |
| 952 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, |
| 953 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 954 }; |
| 955 |
| 956 LOCAL(const unsigned char) mjpg_dc0_huffval[] = { |
| 957 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 958 0x08, 0x09, 0x0A, 0x0B |
| 959 }; |
| 960 |
| 961 /* DC table 1 */ |
| 962 LOCAL(const unsigned char) mjpg_dc1_bits[] = { |
| 963 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, |
| 964 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 965 }; |
| 966 |
| 967 LOCAL(const unsigned char) mjpg_dc1_huffval[] = { |
| 968 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 969 0x08, 0x09, 0x0A, 0x0B |
| 970 }; |
| 971 |
| 972 /* AC table 0 */ |
| 973 LOCAL(const unsigned char) mjpg_ac0_bits[] = { |
| 974 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, |
| 975 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7D |
| 976 }; |
| 977 |
| 978 LOCAL(const unsigned char) mjpg_ac0_huffval[] = { |
| 979 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, |
| 980 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, |
| 981 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, |
| 982 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, |
| 983 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, |
| 984 0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, |
| 985 0x29, 0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, |
| 986 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, |
| 987 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, |
| 988 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, |
| 989 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, |
| 990 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, |
| 991 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, |
| 992 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, |
| 993 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, |
| 994 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, |
| 995 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, |
| 996 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1, 0xE2, |
| 997 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, |
| 998 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, |
| 999 0xF9, 0xFA |
| 1000 }; |
| 1001 |
| 1002 /* AC table 1 */ |
| 1003 LOCAL(const unsigned char) mjpg_ac1_bits[] = { |
| 1004 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, |
| 1005 0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77 |
| 1006 }; |
| 1007 |
| 1008 LOCAL(const unsigned char) mjpg_ac1_huffval[] = { |
| 1009 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, |
| 1010 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, |
| 1011 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, |
| 1012 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0, |
| 1013 0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, |
| 1014 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26, |
| 1015 0x27, 0x28, 0x29, 0x2A, 0x35, 0x36, 0x37, 0x38, |
| 1016 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, |
| 1017 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, |
| 1018 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, |
| 1019 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, |
| 1020 0x79, 0x7A, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, |
| 1021 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, |
| 1022 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, |
| 1023 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, |
| 1024 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, |
| 1025 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, |
| 1026 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, |
| 1027 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, |
| 1028 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, |
| 1029 0xF9, 0xFA |
| 1030 }; |
| 1031 |
| 1032 /* Loads the default Huffman tables used by motion JPEG frames. This function |
| 1033 * just copies the huffman tables suggested in the JPEG standard when we have |
| 1034 * not load them. |
| 1035 */ |
| 1036 LOCAL(void) |
| 1037 mjpg_load_huff_tables (j_decompress_ptr cinfo) |
| 1038 { |
| 1039 JHUFF_TBL *htblptr; |
| 1040 |
| 1041 if (! cinfo->dc_huff_tbl_ptrs[0]) { |
| 1042 htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); |
| 1043 MEMZERO(htblptr, SIZEOF(JHUFF_TBL)); |
| 1044 MEMCOPY(&htblptr->bits[1], mjpg_dc0_bits, SIZEOF(mjpg_dc0_bits)); |
| 1045 MEMCOPY(&htblptr->huffval[0], mjpg_dc0_huffval, SIZEOF(mjpg_dc0_huffval)); |
| 1046 cinfo->dc_huff_tbl_ptrs[0] = htblptr; |
| 1047 } |
| 1048 |
| 1049 if (! cinfo->dc_huff_tbl_ptrs[1]) { |
| 1050 htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); |
| 1051 MEMZERO(htblptr, SIZEOF(JHUFF_TBL)); |
| 1052 MEMCOPY(&htblptr->bits[1], mjpg_dc1_bits, SIZEOF(mjpg_dc1_bits)); |
| 1053 MEMCOPY(&htblptr->huffval[0], mjpg_dc1_huffval, SIZEOF(mjpg_dc1_huffval)); |
| 1054 cinfo->dc_huff_tbl_ptrs[1] = htblptr; |
| 1055 } |
| 1056 |
| 1057 if (! cinfo->ac_huff_tbl_ptrs[0]) { |
| 1058 htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); |
| 1059 MEMZERO(htblptr, SIZEOF(JHUFF_TBL)); |
| 1060 MEMCOPY(&htblptr->bits[1], mjpg_ac0_bits, SIZEOF(mjpg_ac0_bits)); |
| 1061 MEMCOPY(&htblptr->huffval[0], mjpg_ac0_huffval, SIZEOF(mjpg_ac0_huffval)); |
| 1062 cinfo->ac_huff_tbl_ptrs[0] = htblptr; |
| 1063 } |
| 1064 |
| 1065 if (! cinfo->ac_huff_tbl_ptrs[1]) { |
| 1066 htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); |
| 1067 MEMZERO(htblptr, SIZEOF(JHUFF_TBL)); |
| 1068 MEMCOPY(&htblptr->bits[1], mjpg_ac1_bits, SIZEOF(mjpg_ac1_bits)); |
| 1069 MEMCOPY(&htblptr->huffval[0], mjpg_ac1_huffval, SIZEOF(mjpg_ac1_huffval)); |
| 1070 cinfo->ac_huff_tbl_ptrs[1] = htblptr; |
| 1071 } |
| 1072 } |
| 1073 |
| 1074 #else |
| 1075 |
| 1076 #define mjpg_load_huff_tables(cinfo) |
| 1077 |
| 1078 #endif /* MOTION_JPEG_SUPPORTED */ |
| 1079 |
943 | 1080 |
944 /* | 1081 /* |
945 * Read markers until SOS or EOI. | 1082 * Read markers until SOS or EOI. |
946 * | 1083 * |
947 * Returns same codes as are defined for jpeg_consume_input: | 1084 * Returns same codes as are defined for jpeg_consume_input: |
948 * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. | 1085 * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. |
949 */ | 1086 */ |
950 | 1087 |
951 METHODDEF(int) | 1088 METHODDEF(int) |
952 read_markers (j_decompress_ptr cinfo) | 1089 read_markers (j_decompress_ptr cinfo) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 case M_SOF7: /* Differential lossless, Huffman */ | 1139 case M_SOF7: /* Differential lossless, Huffman */ |
1003 case M_JPG: /* Reserved for JPEG extensions */ | 1140 case M_JPG: /* Reserved for JPEG extensions */ |
1004 case M_SOF11: /* Lossless, arithmetic */ | 1141 case M_SOF11: /* Lossless, arithmetic */ |
1005 case M_SOF13: /* Differential sequential, arithmetic */ | 1142 case M_SOF13: /* Differential sequential, arithmetic */ |
1006 case M_SOF14: /* Differential progressive, arithmetic */ | 1143 case M_SOF14: /* Differential progressive, arithmetic */ |
1007 case M_SOF15: /* Differential lossless, arithmetic */ | 1144 case M_SOF15: /* Differential lossless, arithmetic */ |
1008 ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker); | 1145 ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker); |
1009 break; | 1146 break; |
1010 | 1147 |
1011 case M_SOS: | 1148 case M_SOS: |
| 1149 mjpg_load_huff_tables(cinfo); |
1012 if (! get_sos(cinfo)) | 1150 if (! get_sos(cinfo)) |
1013 return JPEG_SUSPENDED; | 1151 return JPEG_SUSPENDED; |
1014 cinfo->unread_marker = 0; /* processed the marker */ | 1152 cinfo->unread_marker = 0; /* processed the marker */ |
1015 return JPEG_REACHED_SOS; | 1153 return JPEG_REACHED_SOS; |
1016 | 1154 |
1017 case M_EOI: | 1155 case M_EOI: |
1018 TRACEMS(cinfo, 1, JTRC_EOI); | 1156 TRACEMS(cinfo, 1, JTRC_EOI); |
1019 cinfo->unread_marker = 0; /* processed the marker */ | 1157 cinfo->unread_marker = 0; /* processed the marker */ |
1020 return JPEG_REACHED_EOI; | 1158 return JPEG_REACHED_EOI; |
1021 | 1159 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1351 { | 1489 { |
1352 my_marker_ptr marker = (my_marker_ptr) cinfo->marker; | 1490 my_marker_ptr marker = (my_marker_ptr) cinfo->marker; |
1353 | 1491 |
1354 if (marker_code == (int) M_COM) | 1492 if (marker_code == (int) M_COM) |
1355 marker->process_COM = routine; | 1493 marker->process_COM = routine; |
1356 else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) | 1494 else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) |
1357 marker->process_APPn[marker_code - (int) M_APP0] = routine; | 1495 marker->process_APPn[marker_code - (int) M_APP0] = routine; |
1358 else | 1496 else |
1359 ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code); | 1497 ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code); |
1360 } | 1498 } |
OLD | NEW |