Fix image corruption bug where the DC levels where not being reset correctly on decoding
This commit is contained in:
		
							parent
							
								
									0851b24b7c
								
							
						
					
					
						commit
						5c7dde620c
					
				
							
								
								
									
										16
									
								
								ssdv.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								ssdv.c
									
									
									
									
									
								
							|  | @ -588,6 +588,7 @@ static char ssdv_process(ssdv_t *s) | ||||||
| 		{ | 		{ | ||||||
| 			s->mcupart = 0; | 			s->mcupart = 0; | ||||||
| 			s->mcu_id++; | 			s->mcu_id++; | ||||||
|  | 			s->reset_mcu = s->next_reset_mcu; | ||||||
| 			 | 			 | ||||||
| 			/* Test for the end of image */ | 			/* Test for the end of image */ | ||||||
| 			if(s->mcu_id >= s->mcu_count) | 			if(s->mcu_id >= s->mcu_count) | ||||||
|  | @ -603,13 +604,15 @@ static char ssdv_process(ssdv_t *s) | ||||||
| 				/* The first MCU of each packet should be byte aligned */ | 				/* The first MCU of each packet should be byte aligned */ | ||||||
| 				ssdv_outbits_sync(s); | 				ssdv_outbits_sync(s); | ||||||
| 				 | 				 | ||||||
| 				s->reset_mcu = s->mcu_id; | 				s->next_reset_mcu = s->reset_mcu = s->mcu_id; | ||||||
| 				s->packet_mcu_id = s->mcu_id; | 				s->packet_mcu_id = s->mcu_id; | ||||||
| 				s->packet_mcu_offset = s->pkt_size_payload - s->out_len; | 				s->packet_mcu_offset = s->pkt_size_payload - s->out_len; | ||||||
| 			} | 			} | ||||||
| 			 | 			 | ||||||
| 			if(s->mode == S_DECODING && s->mcu_id == s->reset_mcu) | 			if(s->mode == S_DECODING && s->mcu_id == s->reset_mcu) | ||||||
|  | 			{ | ||||||
| 				s->workbits = s->worklen = 0; | 				s->workbits = s->worklen = 0; | ||||||
|  | 			} | ||||||
| 			 | 			 | ||||||
| 			/* Test for a reset marker */ | 			/* Test for a reset marker */ | ||||||
| 			if(s->dri > 0 && s->mcu_id > 0 && s->mcu_id % s->dri == 0) | 			if(s->dri > 0 && s->mcu_id > 0 && s->mcu_id % s->dri == 0) | ||||||
|  | @ -1029,8 +1032,9 @@ char ssdv_enc_get_packet(ssdv_t *s) | ||||||
| 			if(r == SSDV_BUFFER_FULL || r == SSDV_EOI) | 			if(r == SSDV_BUFFER_FULL || r == SSDV_EOI) | ||||||
| 			{ | 			{ | ||||||
| 				uint16_t mcu_id    = s->packet_mcu_id; | 				uint16_t mcu_id    = s->packet_mcu_id; | ||||||
| 				uint8_t i, mcu_offset = s->packet_mcu_offset; | 				uint8_t mcu_offset = s->packet_mcu_offset; | ||||||
| 				uint32_t x; | 				uint32_t x; | ||||||
|  | 				uint8_t i; | ||||||
| 				 | 				 | ||||||
| 				if(mcu_offset != 0xFF && mcu_offset >= s->pkt_size_payload) | 				if(mcu_offset != 0xFF && mcu_offset >= s->pkt_size_payload) | ||||||
| 				{ | 				{ | ||||||
|  | @ -1251,7 +1255,13 @@ char ssdv_dec_feed(ssdv_t *s, uint8_t *packet) | ||||||
| 	s->packet_mcu_offset = packet[12]; | 	s->packet_mcu_offset = packet[12]; | ||||||
| 	s->packet_mcu_id     = (packet[13] << 8) | packet[14]; | 	s->packet_mcu_id     = (packet[13] << 8) | packet[14]; | ||||||
| 	 | 	 | ||||||
| 	if(s->packet_mcu_id != 0xFFFF) s->reset_mcu = s->packet_mcu_id; | 	if(s->packet_mcu_id != 0xFFFF) | ||||||
|  | 	{ | ||||||
|  | 		/* Set the next reset MCU ID. We can't set it
 | ||||||
|  | 		 * directly here as the previous MCU may still | ||||||
|  | 		 * be being processed. */ | ||||||
|  | 		s->next_reset_mcu = s->packet_mcu_id; | ||||||
|  | 	} | ||||||
| 	 | 	 | ||||||
| 	/* If this is the first packet, write the JPEG headers */ | 	/* If this is the first packet, write the JPEG headers */ | ||||||
| 	if(s->packet_id == 0) | 	if(s->packet_id == 0) | ||||||
|  |  | ||||||
							
								
								
									
										1
									
								
								ssdv.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								ssdv.h
									
									
									
									
									
								
							|  | @ -114,6 +114,7 @@ typedef struct | ||||||
| 		S_DECODING, | 		S_DECODING, | ||||||
| 	} mode; | 	} mode; | ||||||
| 	uint32_t reset_mcu; /* MCU block to do absolute encoding            */ | 	uint32_t reset_mcu; /* MCU block to do absolute encoding            */ | ||||||
|  | 	uint32_t next_reset_mcu; | ||||||
| 	char needbits;      /* Number of bits needed to decode integer      */ | 	char needbits;      /* Number of bits needed to decode integer      */ | ||||||
| 	 | 	 | ||||||
| 	/* The input huffman and quantisation tables */ | 	/* The input huffman and quantisation tables */ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Philip Heron
						Philip Heron