@@ -276,7 +276,7 @@ internal static uint GetNumberOfComponents(IExifValue exifValue)
276
276
277
277
if ( exifValue . DataType == ExifDataType . Ascii )
278
278
{
279
- return ( uint ) ExifConstants . DefaultEncoding . GetByteCount ( ( string ) value ) + 1 ;
279
+ return ( uint ) ( ExifUcs2StringHelpers . IsUcs2Tag ( ( ExifTagValue ) ( ushort ) exifValue . Tag ) ? ExifUcs2StringHelpers . Ucs2Encoding : ExifConstants . DefaultEncoding ) . GetByteCount ( ( string ) value ) + 1 ;
280
280
}
281
281
282
282
if ( value is EncodedString encodedString )
@@ -297,7 +297,7 @@ private static int WriteArray(IExifValue value, Span<byte> destination, int offs
297
297
int newOffset = offset ;
298
298
foreach ( object obj in ( Array ) value . GetValue ( ) )
299
299
{
300
- newOffset = WriteValue ( value . DataType , obj , destination , newOffset ) ;
300
+ newOffset = WriteValue ( value , value . DataType , obj , destination , newOffset ) ;
301
301
}
302
302
303
303
return newOffset ;
@@ -373,17 +373,15 @@ private static void WriteSignedRational(Span<byte> destination, in SignedRationa
373
373
BinaryPrimitives . WriteInt32LittleEndian ( destination . Slice ( 4 , 4 ) , value . Denominator ) ;
374
374
}
375
375
376
- private static int WriteValue ( ExifDataType dataType , object value , Span < byte > destination , int offset )
376
+ private static int WriteValue ( IExifValue exifValue , ExifDataType dataType , object value , Span < byte > destination , int offset )
377
377
{
378
378
switch ( dataType )
379
379
{
380
380
case ExifDataType . Ascii :
381
- offset = Write ( ExifConstants . DefaultEncoding . GetBytes ( ( string ) value ) , destination , offset ) ;
381
+ offset = Write ( ( ExifUcs2StringHelpers . IsUcs2Tag ( ( ExifTagValue ) ( ushort ) exifValue . Tag ) ? ExifUcs2StringHelpers . Ucs2Encoding : ExifConstants . DefaultEncoding ) . GetBytes ( ( string ) value ) , destination , offset ) ;
382
382
destination [ offset ] = 0 ;
383
383
return offset + 1 ;
384
384
case ExifDataType . Byte :
385
- destination [ offset ] = ( byte ) value ;
386
- return offset + 1 ;
387
385
case ExifDataType . Undefined :
388
386
if ( value is EncodedString encodedString )
389
387
{
@@ -450,7 +448,7 @@ internal static int WriteValue(IExifValue value, Span<byte> destination, int off
450
448
return WriteArray ( value , destination , offset ) ;
451
449
}
452
450
453
- return WriteValue ( value . DataType , value . GetValue ( ) , destination , offset ) ;
451
+ return WriteValue ( value , value . DataType , value . GetValue ( ) , destination , offset ) ;
454
452
}
455
453
}
456
454
}
0 commit comments