mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 22:02:44 +00:00 
			
		
		
		
	LibPDF: Derive alternate ICC color space from the number of components
We currently don't support ICC color spaces and fall back to a "simple" one instead. If no alternative is specified however, we are allowed to pick the closest match based on the number of color components.
This commit is contained in:
		
							parent
							
								
									16ed407c01
								
							
						
					
					
						commit
						baaf42360e
					
				
					 1 changed files with 16 additions and 4 deletions
				
			
		|  | @ -271,11 +271,23 @@ PDFErrorOr<NonnullRefPtr<ColorSpace>> ICCBasedColorSpace::create(Document* docum | ||||||
|         return Error { Error::Type::MalformedPDF, "ICCBased color space expects a stream parameter" }; |         return Error { Error::Type::MalformedPDF, "ICCBased color space expects a stream parameter" }; | ||||||
| 
 | 
 | ||||||
|     auto dict = param.get<NonnullRefPtr<Object>>()->cast<StreamObject>()->dict(); |     auto dict = param.get<NonnullRefPtr<Object>>()->cast<StreamObject>()->dict(); | ||||||
|     if (!dict->contains(CommonNames::Alternate)) |  | ||||||
|         TODO(); |  | ||||||
| 
 | 
 | ||||||
|     auto alternate = TRY(dict->get_name(document, CommonNames::Alternate))->name(); |     FlyString name; | ||||||
|     return TRY(ColorSpace::create(document, alternate, page)); |     if (!dict->contains(CommonNames::Alternate)) { | ||||||
|  |         auto number_of_components = dict->get_value(CommonNames::N).to_int(); | ||||||
|  |         if (number_of_components == 1) | ||||||
|  |             name = CommonNames::DeviceGray; | ||||||
|  |         else if (number_of_components == 3) | ||||||
|  |             name = CommonNames::DeviceRGB; | ||||||
|  |         else if (number_of_components == 4) | ||||||
|  |             name = CommonNames::DeviceCMYK; | ||||||
|  |         else | ||||||
|  |             VERIFY_NOT_REACHED(); | ||||||
|  |     } else { | ||||||
|  |         name = TRY(dict->get_name(document, CommonNames::Alternate))->name(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return TRY(ColorSpace::create(document, name, page)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Color ICCBasedColorSpace::color(Vector<Value> const&) const | Color ICCBasedColorSpace::color(Vector<Value> const&) const | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Julian Offenhäuser
						Julian Offenhäuser