mirror of
				https://github.com/webmproject/libwebp.git
				synced 2025-10-31 02:15:42 +01:00 
			
		
		
		
	Make discarding invisible RGB values (cleanup alpha) the default.
Rename the flag to exact instead of the opposite cleanup_alpha. Add the flag to WebPConfig. Do the cleanup in the webp encoder library rather than the cwebp binary, this will be needed for the next stage: smarter alpha cleanup for better compression which cannot be done as a preprocessing due to depending on predictor choices in the encoder. Change-Id: I2fbf57f918a35f2da6186ef0b5d85e5fd0020eef
This commit is contained in:
		
				
					committed by
					
						 James Zern
						James Zern
					
				
			
			
				
	
			
			
			
						parent
						
							b37b0179c5
						
					
				
				
					commit
					1f9be97c22
				
			
							
								
								
									
										2
									
								
								README
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								README
									
									
									
									
									
								
							| @@ -181,7 +181,7 @@ Options: | |||||||
|   -alpha_method <int> .... transparency-compression method (0..1) |   -alpha_method <int> .... transparency-compression method (0..1) | ||||||
|   -alpha_filter <string> . predictive filtering for alpha plane, |   -alpha_filter <string> . predictive filtering for alpha plane, | ||||||
|                            one of: none, fast (default) or best |                            one of: none, fast (default) or best | ||||||
|   -alpha_cleanup ......... clean RGB values in transparent area |   -exact ................. preserve RGB values in transparent area | ||||||
|   -blend_alpha <hex> ..... blend colors against background color |   -blend_alpha <hex> ..... blend colors against background color | ||||||
|                            expressed as RGB values written in |                            expressed as RGB values written in | ||||||
|                            hexadecimal, e.g. 0xc0e0d0 for red=0xc0 |                            hexadecimal, e.g. 0xc0e0d0 for red=0xc0 | ||||||
|   | |||||||
| @@ -611,7 +611,8 @@ static void HelpLong(void) { | |||||||
|   printf("  -alpha_method <int> .... transparency-compression method (0..1)\n"); |   printf("  -alpha_method <int> .... transparency-compression method (0..1)\n"); | ||||||
|   printf("  -alpha_filter <string> . predictive filtering for alpha plane,\n"); |   printf("  -alpha_filter <string> . predictive filtering for alpha plane,\n"); | ||||||
|   printf("                           one of: none, fast (default) or best\n"); |   printf("                           one of: none, fast (default) or best\n"); | ||||||
|   printf("  -alpha_cleanup ......... clean RGB values in transparent area\n"); |   printf("  -exact ................. preserve RGB values in transparent area" | ||||||
|  |          "\n"); | ||||||
|   printf("  -blend_alpha <hex> ..... blend colors against background color\n" |   printf("  -blend_alpha <hex> ..... blend colors against background color\n" | ||||||
|          "                           expressed as RGB values written in\n" |          "                           expressed as RGB values written in\n" | ||||||
|          "                           hexadecimal, e.g. 0xc0e0d0 for red=0xc0\n" |          "                           hexadecimal, e.g. 0xc0e0d0 for red=0xc0\n" | ||||||
| @@ -763,7 +764,10 @@ int main(int argc, const char *argv[]) { | |||||||
|     } else if (!strcmp(argv[c], "-alpha_method") && c < argc - 1) { |     } else if (!strcmp(argv[c], "-alpha_method") && c < argc - 1) { | ||||||
|       config.alpha_compression = ExUtilGetInt(argv[++c], 0, &parse_error); |       config.alpha_compression = ExUtilGetInt(argv[++c], 0, &parse_error); | ||||||
|     } else if (!strcmp(argv[c], "-alpha_cleanup")) { |     } else if (!strcmp(argv[c], "-alpha_cleanup")) { | ||||||
|       keep_alpha = keep_alpha ? 2 : 0; |       // This flag is obsolete, does opposite of -exact. | ||||||
|  |       config.exact = 0; | ||||||
|  |     } else if (!strcmp(argv[c], "-exact")) { | ||||||
|  |       config.exact = 1; | ||||||
|     } else if (!strcmp(argv[c], "-blend_alpha") && c < argc - 1) { |     } else if (!strcmp(argv[c], "-blend_alpha") && c < argc - 1) { | ||||||
|       blend_alpha = 1; |       blend_alpha = 1; | ||||||
|       // background color is given in hex with an optional '0x' prefix |       // background color is given in hex with an optional '0x' prefix | ||||||
| @@ -996,10 +1000,6 @@ int main(int argc, const char *argv[]) { | |||||||
|     WebPBlendAlpha(&picture, background_color); |     WebPBlendAlpha(&picture, background_color); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   if (keep_alpha == 2) { |  | ||||||
|     WebPCleanupTransparentArea(&picture); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   if (verbose) { |   if (verbose) { | ||||||
|     const double read_time = StopwatchReadAndReset(&stop_watch); |     const double read_time = StopwatchReadAndReset(&stop_watch); | ||||||
|     fprintf(stderr, "Time to read input: %.3fs\n", read_time); |     fprintf(stderr, "Time to read input: %.3fs\n", read_time); | ||||||
|   | |||||||
| @@ -247,9 +247,9 @@ mode will just try to form an a priori guess without testing all modes. | |||||||
| Specify the algorithm used for alpha compression: 0 or 1. Algorithm 0 denotes | Specify the algorithm used for alpha compression: 0 or 1. Algorithm 0 denotes | ||||||
| no compression, 1 uses WebP lossless format for compression. The default is 1. | no compression, 1 uses WebP lossless format for compression. The default is 1. | ||||||
| .TP | .TP | ||||||
| .B \-alpha_cleanup | .B \-exact | ||||||
| Modify unseen RGB values under fully transparent area, to help compressibility. | Preserve RGB values in transparent area. The default is off, to help | ||||||
| The default is off. | compressibility. | ||||||
| .TP | .TP | ||||||
| .BI \-blend_alpha " int | .BI \-blend_alpha " int | ||||||
| This option blends the alpha channel (if present) with the source using the | This option blends the alpha channel (if present) with the source using the | ||||||
|   | |||||||
| @@ -43,6 +43,7 @@ int WebPConfigInitInternal(WebPConfig* config, | |||||||
|   config->alpha_filtering = 1; |   config->alpha_filtering = 1; | ||||||
|   config->alpha_quality = 100; |   config->alpha_quality = 100; | ||||||
|   config->lossless = 0; |   config->lossless = 0; | ||||||
|  |   config->exact = 0; | ||||||
|   config->image_hint = WEBP_HINT_DEFAULT; |   config->image_hint = WEBP_HINT_DEFAULT; | ||||||
|   config->emulate_jpeg_size = 0; |   config->emulate_jpeg_size = 0; | ||||||
|   config->thread_level = 0; |   config->thread_level = 0; | ||||||
| @@ -139,6 +140,8 @@ int WebPValidateConfig(const WebPConfig* config) { | |||||||
|     return 0; |     return 0; | ||||||
|   if (config->low_memory < 0 || config->low_memory > 1) |   if (config->low_memory < 0 || config->low_memory > 1) | ||||||
|     return 0; |     return 0; | ||||||
|  |   if (config->exact < 0 || config->exact > 1) | ||||||
|  |     return 0; | ||||||
| #ifdef WEBP_EXPERIMENTAL_FEATURES | #ifdef WEBP_EXPERIMENTAL_FEATURES | ||||||
|   if (config->delta_palettization < 0 || config->delta_palettization > 1) |   if (config->delta_palettization < 0 || config->delta_palettization > 1) | ||||||
|     return 0; |     return 0; | ||||||
|   | |||||||
| @@ -321,6 +321,10 @@ int WebPEncode(const WebPConfig* config, WebPPicture* pic) { | |||||||
|   if (pic->width > WEBP_MAX_DIMENSION || pic->height > WEBP_MAX_DIMENSION) |   if (pic->width > WEBP_MAX_DIMENSION || pic->height > WEBP_MAX_DIMENSION) | ||||||
|     return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION); |     return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION); | ||||||
|  |  | ||||||
|  |   if (!config->exact) { | ||||||
|  |     WebPCleanupTransparentArea(pic); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   if (pic->stats != NULL) memset(pic->stats, 0, sizeof(*pic->stats)); |   if (pic->stats != NULL) memset(pic->stats, 0, sizeof(*pic->stats)); | ||||||
|  |  | ||||||
|   if (!config->lossless) { |   if (!config->lossless) { | ||||||
|   | |||||||
| @@ -20,7 +20,7 @@ | |||||||
| extern "C" { | extern "C" { | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #define WEBP_ENCODER_ABI_VERSION 0x0208    // MAJOR(8b) + MINOR(8b) | #define WEBP_ENCODER_ABI_VERSION 0x0209    // MAJOR(8b) + MINOR(8b) | ||||||
|  |  | ||||||
| // Note: forward declaring enumerations is not allowed in (strict) C and C++, | // Note: forward declaring enumerations is not allowed in (strict) C and C++, | ||||||
| // the types are left here for reference. | // the types are left here for reference. | ||||||
| @@ -136,12 +136,16 @@ struct WebPConfig { | |||||||
|  |  | ||||||
|   int near_lossless;      // Near lossless encoding [0 = off(default) .. 100]. |   int near_lossless;      // Near lossless encoding [0 = off(default) .. 100]. | ||||||
|                           // This feature is experimental. |                           // This feature is experimental. | ||||||
|  |   int exact;              // if non-zero, preserve the exact RGB values under | ||||||
|  |                           // transparent area. Otherwise, discard this invisible | ||||||
|  |                           // RGB information for better compression. The default | ||||||
|  |                           // value is 0. | ||||||
|  |  | ||||||
| #ifdef WEBP_EXPERIMENTAL_FEATURES | #ifdef WEBP_EXPERIMENTAL_FEATURES | ||||||
|   int delta_palettization; |   int delta_palettization; | ||||||
|   uint32_t pad[3];        // padding for later use |   uint32_t pad[2];        // padding for later use | ||||||
| #else | #else | ||||||
|   uint32_t pad[4];        // padding for later use |   uint32_t pad[3];        // padding for later use | ||||||
| #endif  // WEBP_EXPERIMENTAL_FEATURES | #endif  // WEBP_EXPERIMENTAL_FEATURES | ||||||
| }; | }; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user