You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2021/08/30 02:00:44 UTC
[GitHub] [commons-imaging] kinow opened a new pull request #164: IMAGING-285 RationalNumber to support unsigned int format
kinow opened a new pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164
@gwlucastrig I created a new PR from your branch, but instead of using kinow/commons-imaging, picked apache/commons-imaging as base for the pull request.
Please take a look to see if I didn't do anything wrong. If not, I will start reviewing it :+1:
Thanks!!
Bruno
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] coveralls commented on pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
coveralls commented on pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#issuecomment-908288341
[](https://coveralls.io/builds/42495312)
Coverage increased (+0.2%) to 76.897% when pulling **eea6169a27ca9d9243e40c048b1caea644c38922 on gwlucastrig:IMAGING-285** into **32e1a3b839eb75b38c47531cb2dd6e0012bb3bf5 on apache:master**.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] gwlucastrig commented on pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
gwlucastrig commented on pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#issuecomment-918655691
Well, predictably, somethings gone wrong with my branch and pull request... I made the changes, did the squash, and then a push... But they did not seem to make it into the pull request. In my git shell, I got the following:
remote: Resolving deltas: 100% (1218/1218), completed with 185 local objects.
remote:
remote: Create a pull request for 'IMAGING-285' on GitHub by visiting:
remote: https://github.com/gwlucastrig/commons-imaging/pull/new/IMAGING-285
remote:
To https://github.com/gwlucastrig/commons-imaging.git
* [new branch] IMAGING-285 -> IMAGING-285
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] gwlucastrig commented on a change in pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
gwlucastrig commented on a change in pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#discussion_r706926641
##########
File path: src/main/java/org/apache/commons/imaging/common/RationalNumber.java
##########
@@ -73,8 +124,41 @@ private static long gcd(final long a, final long b) {
return gcd(b, a % b);
}
+ /**
+ * Negates the value of the RationalNumber. If the numerator of this
+ * instance has its high-order bit set, then its value is too large
+ * to be treated as a Java 32-bit signed integer. In such a case, the
+ * only way that a RationalNumber instance can be negated is to
+ * sacrifice one bit of precision by dividing both the numerator and
+ * the denominator by 2. However, if that computation would result
+ * in a zero denominator, then the value cannot be negated and an
+ * exception is thrown.
+ * @return a valid instance with a negated value.
+ */
public RationalNumber negate() {
- return new RationalNumber(-numerator, divisor);
+ long n = numerator;
+ long d = divisor;
+ if (unsignedType) {
+ // An instance of an unsigned type can be negated if and only if
+ // its high-order bit (the sign bit) is clear. If the bit is set,
+ // it is necessary to adjust the
Review comment:
numerator and denominator values.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] gwlucastrig commented on pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
gwlucastrig commented on pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#issuecomment-918143792
I will make the recommended (and completely sensible) changes, rebase, and submit within the next couple of days.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] kinow commented on a change in pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#discussion_r702278559
##########
File path: src/main/java/org/apache/commons/imaging/common/RationalNumber.java
##########
@@ -20,6 +20,14 @@
/**
* Rational number, as used by the TIFF image format.
+ * <p>
+ * The TIFF format specifies two data types for rational numbers based on
+ * a pair of 32-bit integers. Rational is based on unsigned 32-bit integers
+ * and SRational is based on signed 32-bit integers. This treatment is
+ * problematic in Java because Java does not support unsigned types.
+ * To address this challenge, this class stores the numerator and divisor
+ * in long (64-bit) integers, applying masks as necessary for the unsigned
+ * type.
Review comment:
:+1: thanks for the useful comments!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] kinow commented on pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
kinow commented on pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#issuecomment-918663016
@gwlucastrig I think we both learned that GitHub must keep some sort of internal unique ID per fork. Your previous fork has disappeared, hence the new PR. Let's create a new PR and close this one :+1: I will consult my previous comments while reviewing the new PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] gwlucastrig commented on a change in pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
gwlucastrig commented on a change in pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#discussion_r707773701
##########
File path: src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeRational.java
##########
@@ -31,11 +31,19 @@ public FieldTypeRational(final int type, final String name) {
@Override
public Object getValue(final TiffField entry) {
final byte[] bytes = entry.getByteArrayValue();
+ boolean unsignedType = true;
+ if(entry.getFieldType()==RATIONAL){
+ unsignedType = true;
+ }else if(entry.getFieldType()==SRATIONAL){
+ unsignedType = false;
+ }
Review comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] kinow commented on a change in pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#discussion_r702279148
##########
File path: src/main/java/org/apache/commons/imaging/common/RationalNumber.java
##########
@@ -73,8 +124,41 @@ private static long gcd(final long a, final long b) {
return gcd(b, a % b);
}
+ /**
+ * Negates the value of the RationalNumber. If the numerator of this
+ * instance has its high-order bit set, then its value is too large
+ * to be treated as a Java 32-bit signed integer. In such a case, the
+ * only way that a RationalNumber instance can be negated is to
+ * sacrifice one bit of precision by dividing both the numerator and
+ * the denominator by 2. However, if that computation would result
+ * in a zero denominator, then the value cannot be negated and an
+ * exception is thrown.
+ * @return a valid instance with a negated value.
+ */
public RationalNumber negate() {
- return new RationalNumber(-numerator, divisor);
+ long n = numerator;
+ long d = divisor;
+ if (unsignedType) {
+ // An instance of an unsigned type can be negated if and only if
+ // its high-order bit (the sign bit) is clear. If the bit is set,
+ // it is necessary to adjust the
Review comment:
to adjust the?
##########
File path: src/main/java/org/apache/commons/imaging/common/RationalNumber.java
##########
@@ -73,8 +124,41 @@ private static long gcd(final long a, final long b) {
return gcd(b, a % b);
}
+ /**
+ * Negates the value of the RationalNumber. If the numerator of this
+ * instance has its high-order bit set, then its value is too large
+ * to be treated as a Java 32-bit signed integer. In such a case, the
+ * only way that a RationalNumber instance can be negated is to
+ * sacrifice one bit of precision by dividing both the numerator and
+ * the denominator by 2. However, if that computation would result
Review comment:
by `2` or by the greatest common divisor?
##########
File path: src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeRational.java
##########
@@ -31,11 +31,19 @@ public FieldTypeRational(final int type, final String name) {
@Override
public Object getValue(final TiffField entry) {
final byte[] bytes = entry.getByteArrayValue();
+ boolean unsignedType = true;
+ if(entry.getFieldType()==RATIONAL){
+ unsignedType = true;
+ }else if(entry.getFieldType()==SRATIONAL){
+ unsignedType = false;
+ }
Review comment:
What about:
```suggestion
boolean unsignedType = entry.getFieldType() != SRATIONAL;
```
##########
File path: src/main/java/org/apache/commons/imaging/common/RationalNumber.java
##########
@@ -20,6 +20,14 @@
/**
* Rational number, as used by the TIFF image format.
+ * <p>
+ * The TIFF format specifies two data types for rational numbers based on
+ * a pair of 32-bit integers. Rational is based on unsigned 32-bit integers
+ * and SRational is based on signed 32-bit integers. This treatment is
+ * problematic in Java because Java does not support unsigned types.
+ * To address this challenge, this class stores the numerator and divisor
+ * in long (64-bit) integers, applying masks as necessary for the unsigned
+ * type.
Review comment:
:+1: thanks for the useful comment!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] gwlucastrig commented on a change in pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
gwlucastrig commented on a change in pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#discussion_r706926284
##########
File path: src/main/java/org/apache/commons/imaging/formats/tiff/fieldtypes/FieldTypeRational.java
##########
@@ -31,11 +31,19 @@ public FieldTypeRational(final int type, final String name) {
@Override
public Object getValue(final TiffField entry) {
final byte[] bytes = entry.getByteArrayValue();
+ boolean unsignedType = true;
+ if(entry.getFieldType()==RATIONAL){
+ unsignedType = true;
+ }else if(entry.getFieldType()==SRATIONAL){
+ unsignedType = false;
+ }
Review comment:
That will work. There are only the two conditions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] gwlucastrig commented on a change in pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
gwlucastrig commented on a change in pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#discussion_r707773546
##########
File path: src/main/java/org/apache/commons/imaging/common/RationalNumber.java
##########
@@ -73,8 +124,41 @@ private static long gcd(final long a, final long b) {
return gcd(b, a % b);
}
+ /**
+ * Negates the value of the RationalNumber. If the numerator of this
+ * instance has its high-order bit set, then its value is too large
+ * to be treated as a Java 32-bit signed integer. In such a case, the
+ * only way that a RationalNumber instance can be negated is to
+ * sacrifice one bit of precision by dividing both the numerator and
+ * the denominator by 2. However, if that computation would result
Review comment:
done
##########
File path: src/main/java/org/apache/commons/imaging/common/RationalNumber.java
##########
@@ -73,8 +124,41 @@ private static long gcd(final long a, final long b) {
return gcd(b, a % b);
}
+ /**
+ * Negates the value of the RationalNumber. If the numerator of this
+ * instance has its high-order bit set, then its value is too large
+ * to be treated as a Java 32-bit signed integer. In such a case, the
+ * only way that a RationalNumber instance can be negated is to
+ * sacrifice one bit of precision by dividing both the numerator and
+ * the denominator by 2. However, if that computation would result
+ * in a zero denominator, then the value cannot be negated and an
+ * exception is thrown.
+ * @return a valid instance with a negated value.
+ */
public RationalNumber negate() {
- return new RationalNumber(-numerator, divisor);
+ long n = numerator;
+ long d = divisor;
+ if (unsignedType) {
+ // An instance of an unsigned type can be negated if and only if
+ // its high-order bit (the sign bit) is clear. If the bit is set,
+ // it is necessary to adjust the
Review comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] gwlucastrig commented on a change in pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
gwlucastrig commented on a change in pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#discussion_r706926789
##########
File path: src/main/java/org/apache/commons/imaging/common/RationalNumber.java
##########
@@ -73,8 +124,41 @@ private static long gcd(final long a, final long b) {
return gcd(b, a % b);
}
+ /**
+ * Negates the value of the RationalNumber. If the numerator of this
+ * instance has its high-order bit set, then its value is too large
+ * to be treated as a Java 32-bit signed integer. In such a case, the
+ * only way that a RationalNumber instance can be negated is to
+ * sacrifice one bit of precision by dividing both the numerator and
+ * the denominator by 2. However, if that computation would result
Review comment:
by the computed greatest common denominator.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] gwlucastrig edited a comment on pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
gwlucastrig edited a comment on pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#issuecomment-918655691
Well, predictably, somethings gone wrong with my branch and pull request... I made the changes, did the squash, and then a push... But they did not seem to make it into the pull request. In my git shell, I got the following:
remote: Resolving deltas: 100% (1218/1218), completed with 185 local objects.
remote:
remote: Create a pull request for 'IMAGING-285' on GitHub by visiting:
remote: https://github.com/gwlucastrig/commons-imaging/pull/new/IMAGING-285
remote:
To https://github.com/gwlucastrig/commons-imaging.git
* [new branch] IMAGING-285 -> IMAGING-285
If you want, I can start over from scratch. Really don't love github at all...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] kinow closed pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
kinow closed pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] kinow commented on pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
kinow commented on pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#issuecomment-917731327
While on it, you can rebase/squash too :grimacing: then it should be ready to merge.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] kinow commented on pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
kinow commented on pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#issuecomment-917711623
ping @gwlucastrig
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] kinow commented on pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
kinow commented on pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#issuecomment-917731260
I think it'd be better if you did these changes @gwlucastrig . I only created the PR to change the base (it was kinow/commons-imaging).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] gwlucastrig commented on a change in pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
gwlucastrig commented on a change in pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#discussion_r707768881
##########
File path: src/main/java/org/apache/commons/imaging/common/RationalNumber.java
##########
@@ -20,6 +20,14 @@
/**
* Rational number, as used by the TIFF image format.
+ * <p>
+ * The TIFF format specifies two data types for rational numbers based on
+ * a pair of 32-bit integers. Rational is based on unsigned 32-bit integers
+ * and SRational is based on signed 32-bit integers. This treatment is
+ * problematic in Java because Java does not support unsigned types.
+ * To address this challenge, this class stores the numerator and divisor
+ * in long (64-bit) integers, applying masks as necessary for the unsigned
+ * type.
Review comment:
You're welcome as always...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-imaging] gwlucastrig commented on pull request #164: IMAGING-285 RationalNumber to support unsigned int format
Posted by GitBox <gi...@apache.org>.
gwlucastrig commented on pull request #164:
URL: https://github.com/apache/commons-imaging/pull/164#issuecomment-917728774
Is the plan for you to make these changes or should I.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org