-
-
Notifications
You must be signed in to change notification settings - Fork 887
Fix IPTC tags written on jpg files that contains non-English characters can't be correctly displayed on external apps #2212 #2213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…rs can't be correctly displayed on external apps SixLabors#2212
|
|
brianpopow
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lmerino-ep thanks for the contribution. I have added a test for making sure the envelope data is written when UTF-8 data is present. I think this is good to go into main now.
|
Thank you, @brianpopow it looks beautiful now.
El mié, 24 ago 2022 a las 7:07, Brian Popow ***@***.***>)
escribió:
… ***@***.**** approved this pull request.
@lmerino-ep <https://github.com/lmerino-ep> thanks for the contribution.
I have added a test for making sure the envelope data is written when UTF-8
data is present. I think this is good to go into main now.
—
Reply to this email directly, view it on GitHub
<#2213 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A2UPGMW3KF7MBZRAJKAUVHDV2WU2TANCNFSM57KPW5CA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
*INFORMACÍON BÁSICA SOBRE PROTECCIÓN DE DATOS CONFORME EL NUEVO REGLAMENTO
EUROPEO*
*RESPONSABLE: *EUROPA PRESS NOTICIAS S.A./CASTELLANA 210, 28046,
MADRID / 91 359 2600 ***@***.***
***@***.***>*| FINALIDAD PRINCIPAL: *Mantener
relaciones profesionales y/o comerciales. Prestar el servicio contratado.*
| LEGITIMACIÓN: *Consentimiento del interesado. Interés legítimo. Ejecución
de un contrato.* | DESTINATARIOS: *No se cederán datos a terceros, salvo
autorización expresa u obligación legal.* | DERECHOS DE LOS TITULARES:
*Acceder, rectificar y suprimir los datos, portabilidad de los datos,
limitación u oposición a su tratamiento, derecho a no ser objeto de
decisiones automatizadas, así como a obtener información clara y
transparente sobre el tratamiento de sus datos.* | INFORMACIÓN ADICIONAL:
*Puede consultar la información adicional y detallada sobre nuestra
Política de Privacidad en
https://www.europapress.es/politica-privacidad.html
<http://www.europapress.es/politica-privacidad.html>* | CONFIDENCIALIDAD:*
Si Ud. no es el destinatario y recibe este mail/fax por error, rogamos se
ponga en contacto con nosotros y destruya de inmediato el mail/fax por
error recibido con todos sus documentos adjuntos sin leerlos ni hacer
ningún uso de los datos que en ellos figuren, ateniéndose a las
consecuencias que de un uso indebido de dichos datos puedan derivarse .
|
| /// <summary> | ||
| /// This value marks that UTF-8 encoding is used in application records. | ||
| /// </summary> | ||
| private static readonly byte[] CodedCharacterSetUtf8Value = { 0x1B, 0x25, 0x47 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private static readonly byte[] CodedCharacterSetUtf8Value = { 0x1B, 0x25, 0x47 }; | |
| // Uses C#'s optimization to refer to the data segment in the assembly direclty, no allocation occurs. | |
| private static ReadOnlySpan<byte> CodedCharacterSetUtf8Value => new byte[]{ 0x1B, 0x25, 0x47 }; |
And update WriteRecord (L294) to take a ROS.
| if (hasValuesInUtf8) | ||
| { | ||
| // Additional length for UTF-8 Tag. | ||
| length += 5 + CodedCharacterSetUtf8Value.Length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cool thing is that with the above suggestion the JIT will treat CodedCharacterSetUtf8Value.Length as constant (3) here.
| this.Data[offset++] = IptcTagMarkerByte; | ||
| this.Data[offset++] = (byte)recordNumber; | ||
| this.Data[offset++] = recordBinaryRepresentation; | ||
| this.Data[offset++] = (byte)(recordData.Length >> 8); | ||
| this.Data[offset++] = (byte)recordData.Length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the JIT needs to introduce a bound check for each access to Data. These can be avoided by
Span<byte> data = this.Data.AsSpan(offset, 5);
data[0] = IptcTagMarkerByte;
data[1] = recordNumber;
data[2] = recordBinaryRepresentation;
data[3] = (byte)(recordData.Length >> 8);
data[4] = (byte)recordData.Length;
offset += 5;So if the AsSpan succeeds the JIT knows that all index accesses are within bounds, so no bounds check needs to be emitted (tested with .NET 6).
| this.Data[offset++] = (byte)recordData.Length; | ||
| if (recordData.Length > 0) | ||
| { | ||
| Buffer.BlockCopy(recordData, 0, this.Data, offset, recordData.Length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will become
| Buffer.BlockCopy(recordData, 0, this.Data, offset, recordData.Length); | |
| recordData.CopyTo(this.Data.AsSpan(offset)); |
|
thanks @gfoidl, I have added your suggestions. |
Prerequisites
Description
This fixes the issue of incorrect characters showed on IPTC tags that contains non-English characters.