Example #1
0
void dng_jpeg_preview::WriteData (dng_host & /* host */,
								  dng_image_writer & /* writer */,
								  dng_basic_tag_set &basic,
								  dng_stream &stream) const
	{
	
	basic.SetTileOffset (0, (uint32) stream.Position ());
	
	basic.SetTileByteCount (0, fCompressedData->LogicalSize ());
	
	stream.Put (fCompressedData->Buffer      (),
				fCompressedData->LogicalSize ());

	if (fCompressedData->LogicalSize () & 1)
		{
		stream.Put_uint8 (0);
		}
			
	}
Example #2
0
void dng_jpeg_preview::SpoolAdobeThumbnail (dng_stream &stream) const
	{
	
	DNG_ASSERT (fCompressedData.Get (),
				"SpoolAdobeThumbnail: no data");
	
	DNG_ASSERT (fPhotometricInterpretation == piYCbCr,
				"SpoolAdobeThumbnail: Non-YCbCr");
	
	uint32 compressedSize = fCompressedData->LogicalSize ();
	
	stream.Put_uint32 (DNG_CHAR4 ('8','B','I','M'));
	stream.Put_uint16 (1036);
	stream.Put_uint16 (0);
	
	stream.Put_uint32 (compressedSize + 28);
	
	uint32 widthBytes = (fPreviewSize.h * 24 + 31) / 32 * 4;
	
	stream.Put_uint32 (1);
	stream.Put_uint32 (fPreviewSize.h);
	stream.Put_uint32 (fPreviewSize.v);
	stream.Put_uint32 (widthBytes);
	stream.Put_uint32 (widthBytes * fPreviewSize.v);
	stream.Put_uint32 (compressedSize);
	stream.Put_uint16 (24);
	stream.Put_uint16 (1);
	
	stream.Put (fCompressedData->Buffer (),
			    compressedSize);
			    
	if (compressedSize & 1)
		{
		stream.Put_uint8 (0);
		}
	
	}
void dng_iptc::SpoolString (dng_stream &stream,
							const dng_string &s,
							uint8 dataSet,
							uint32 maxChars,
							CharSet charSet)
	{
	
	if (s.IsEmpty ())
		{
		return;
		}
		
	stream.Put_uint16 (0x1C02);
	stream.Put_uint8  (dataSet);
	
	dng_string ss (s);
	
	ss.SetLineEndingsToReturns ();
	
	if (charSet == kCharSetUTF8)
		{
	
		// UTF-8 encoding.
		
		if (ss.Length () > maxChars)
			{
			ss.Truncate (maxChars);
			}
			
		uint32 len = ss.Length ();
			
		stream.Put_uint16 ((uint16) len);
		
		stream.Put (ss.Get (), len);
		
		}
		
	else
		{
	
		// System character set encoding.
		
		dng_memory_data buffer;
		
		uint32 len = ss.Get_SystemEncoding (buffer);
		
		if (len > maxChars)
			{
			
			uint32 lower = 0;
			uint32 upper = ss.Length () - 1;
			
			while (upper > lower)
				{
				
				uint32 middle = (upper + lower + 1) >> 1;
				
				dng_string sss (ss);
				
				sss.Truncate (middle);
				
				len = sss.Get_SystemEncoding (buffer);
				
				if (len <= maxChars)
					{
					
					lower = middle;
					
					}
					
				else
					{
					
					upper = middle - 1;
					
					}
				
				}
				
			ss.Truncate (lower);
			
			len = ss.Get_SystemEncoding (buffer);
			
			}
		
		stream.Put_uint16 ((uint16) len);
		
		stream.Put (buffer.Buffer_char (), len);
		
		}