@@ -256,27 +256,21 @@ public void UpdateData()
256
256
257
257
if ( hasValuesInUtf8 )
258
258
{
259
- length += 5 + CodedCharacterSetUtf8Value . Length ; // Additional length for UTF-8 Tag.
259
+ // Additional length for UTF-8 Tag.
260
+ length += 5 + CodedCharacterSetUtf8Value . Length ;
260
261
}
261
262
262
263
this . Data = new byte [ length ] ;
263
- int i = 0 ;
264
-
264
+ int offset = 0 ;
265
265
if ( hasValuesInUtf8 )
266
266
{
267
- // Envelope Record.
268
- this . Data [ i ++ ] = IptcTagMarkerByte ;
269
- this . Data [ i ++ ] = ( byte ) IptcRecordNumber . Envelope ;
270
- this . Data [ i ++ ] = IptcEnvelopeCodedCharacterSet ;
271
- this . Data [ i ++ ] = ( byte ) ( CodedCharacterSetUtf8Value . Length >> 8 ) ;
272
- this . Data [ i ++ ] = ( byte ) CodedCharacterSetUtf8Value . Length ;
273
- Buffer . BlockCopy ( CodedCharacterSetUtf8Value , 0 , this . Data , i , CodedCharacterSetUtf8Value . Length ) ;
274
- i += CodedCharacterSetUtf8Value . Length ;
267
+ // Write Envelope Record.
268
+ offset = this . WriteRecord ( offset , CodedCharacterSetUtf8Value , IptcRecordNumber . Envelope , IptcEnvelopeCodedCharacterSet ) ;
275
269
}
276
270
277
271
foreach ( IptcValue value in this . Values )
278
272
{
279
- // Application Record.
273
+ // Write Application Record.
280
274
// +-----------+----------------+---------------------------------------------------------------------------------+
281
275
// | Octet Pos | Name | Description |
282
276
// +==========-+================+=================================================================================+
@@ -293,17 +287,24 @@ public void UpdateData()
293
287
// | | Octet Count | the following data field(32767 or fewer octets). Note that the value of bit 7 of|
294
288
// | | | octet 4(most significant bit) always will be 0. |
295
289
// +-----------+----------------+---------------------------------------------------------------------------------+
296
- this . Data [ i ++ ] = IptcTagMarkerByte ;
297
- this . Data [ i ++ ] = ( byte ) IptcRecordNumber . Application ;
298
- this . Data [ i ++ ] = ( byte ) value . Tag ;
299
- this . Data [ i ++ ] = ( byte ) ( value . Length >> 8 ) ;
300
- this . Data [ i ++ ] = ( byte ) value . Length ;
301
- if ( value . Length > 0 )
302
- {
303
- Buffer . BlockCopy ( value . ToByteArray ( ) , 0 , this . Data , i , value . Length ) ;
304
- i += value . Length ;
305
- }
290
+ offset = this . WriteRecord ( offset , value . ToByteArray ( ) , IptcRecordNumber . Application , ( byte ) value . Tag ) ;
291
+ }
292
+ }
293
+
294
+ private int WriteRecord ( int offset , byte [ ] recordData , IptcRecordNumber recordNumber , byte recordBinaryRepresentation )
295
+ {
296
+ this . Data [ offset ++ ] = IptcTagMarkerByte ;
297
+ this . Data [ offset ++ ] = ( byte ) recordNumber ;
298
+ this . Data [ offset ++ ] = recordBinaryRepresentation ;
299
+ this . Data [ offset ++ ] = ( byte ) ( recordData . Length >> 8 ) ;
300
+ this . Data [ offset ++ ] = ( byte ) recordData . Length ;
301
+ if ( recordData . Length > 0 )
302
+ {
303
+ Buffer . BlockCopy ( recordData , 0 , this . Data , offset , recordData . Length ) ;
304
+ offset += recordData . Length ;
306
305
}
306
+
307
+ return offset ;
307
308
}
308
309
309
310
private void Initialize ( )
0 commit comments