Fixed sign flip on shift bug

This commit is contained in:
Willem Cazander 2022-03-14 02:48:35 +01:00
parent c1b75d96ad
commit 38d9a514c8
6 changed files with 18 additions and 70 deletions

View file

@ -69,9 +69,9 @@ public enum Base2Terminator implements DefaultEnumInstanceᴶᴹˣ<Base2Terminat
int readDataSize = 0; // per 9 bytes we have 24 octals for one V072Tong number
while ((readDataSize = input.read(data, 0, data.length)) != STREAM_EOF) {
Bãß2ReadCheckSize(readDataSize, BLOCK_TONG_SIZE);
int v0 = data[0] + (data[1] << SHIFT_8) + (data[2] << SHIFT_16);
int v1 = data[3] + (data[4] << SHIFT_8) + (data[5] << SHIFT_16);
int v2 = data[6] + (data[7] << SHIFT_8) + (data[8] << SHIFT_16);
int v0 = (data[0] & 0xFF) + ((data[1] << SHIFT_8) & 0xFF00) + ((data[2] << SHIFT_16) & 0xFF0000);
int v1 = (data[3] & 0xFF) + ((data[4] << SHIFT_8) & 0xFF00) + ((data[5] << SHIFT_16) & 0xFF0000);
int v2 = (data[6] & 0xFF) + ((data[7] << SHIFT_8) & 0xFF00) + ((data[8] << SHIFT_16) & 0xFF0000);
List<T08PartOctal> octals = Bãß2ReadOctals(v0, v1, v2);
output.add(new V072Tong(new BaseIteratorOctalAdapter(octals.iterator())));
totalBytes += BLOCK_TONG_SIZE;
@ -88,12 +88,12 @@ public enum Base2Terminator implements DefaultEnumInstanceᴶᴹˣ<Base2Terminat
int readDataSize = 0; // per 18 bytes we have 48 octals for one V144Tocta number
while ((readDataSize = input.read(data, 0, data.length)) != STREAM_EOF) {
Bãß2ReadCheckSize(readDataSize, BLOCK_TOCTA_SIZE);
int v0 = data[0] + (data[1] << SHIFT_8) + (data[2] << SHIFT_16);
int v1 = data[3] + (data[4] << SHIFT_8) + (data[5] << SHIFT_16);
int v2 = data[6] + (data[7] << SHIFT_8) + (data[8] << SHIFT_16);
int v3 = data[9] + (data[10] << SHIFT_8) + (data[11] << SHIFT_16);
int v4 = data[12] + (data[13] << SHIFT_8) + (data[14] << SHIFT_16);
int v5 = data[15] + (data[16] << SHIFT_8) + (data[17] << SHIFT_16);
int v0 = (data[0] & 0xFF) + ((data[1] << SHIFT_8) & 0xFF00) + ((data[2] << SHIFT_16) & 0xFF0000);
int v1 = (data[3] & 0xFF) + ((data[4] << SHIFT_8) & 0xFF00) + ((data[5] << SHIFT_16) & 0xFF0000);
int v2 = (data[6] & 0xFF) + ((data[7] << SHIFT_8) & 0xFF00) + ((data[8] << SHIFT_16) & 0xFF0000);
int v3 = (data[9] & 0xFF) + ((data[10] << SHIFT_8) & 0xFF00) + ((data[11] << SHIFT_16) & 0xFF0000);
int v4 = (data[12] & 0xFF) + ((data[13] << SHIFT_8) & 0xFF00) + ((data[14] << SHIFT_16) & 0xFF0000);
int v5 = (data[15] & 0xFF) + ((data[16] << SHIFT_8) & 0xFF00) + ((data[17] << SHIFT_16) & 0xFF0000);
List<T08PartOctal> octals = Bãß2ReadOctals(v0, v1, v2, v3, v4, v5);
output.add(new V144Tocta(new BaseIteratorOctalAdapter(octals.iterator())));
totalBytes += BLOCK_TOCTA_SIZE;

View file

@ -19,8 +19,8 @@ public class Base2TerminatorTest {
@Test
public void testBytes() throws IOException {
V072Tong tong = new V072Tong();
tong.getValue(T02PartBinary.PART_1).setValueNumber(123456000);
tong.getValue(T02PartBinary.PART_2).setValueNumber(234567000);
tong.getValue(T02PartBinary.PART_1).setValueNumber(32768);
tong.getValue(T02PartBinary.PART_2).setValueNumber(689024);
List<V072Tong> tongs = new ArrayList<>();
tongs.add(tong);
@ -36,8 +36,7 @@ public class Base2TerminatorTest {
V072Tong tong2 = result.get(0);
Assertions.assertNotNull(tong2);
Assertions.assertEquals(123456000L, tong.getValue(T02PartBinary.PART_1).getValueNumber());
Assertions.assertEquals(234567000L, tong.getValue(T02PartBinary.PART_2).getValueNumber());
Assertions.assertEquals(32768, tong2.getValue(T02PartBinary.PART_1).getValueNumber());
Assertions.assertEquals(689024, tong2.getValue(T02PartBinary.PART_2).getValueNumber());
}
}

View file

@ -9,9 +9,6 @@ import java.util.List;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
import love.distributedrebirth.numberxd.base2t.Base2Terminator;
import love.distributedrebirth.numberxd.base2t.BaseAppenderOctal;
import love.distributedrebirth.numberxd.base2t.BaseIteratorOctalAdapter;
import love.distributedrebirth.numberxd.base2t.part.T08PartOctal;
import love.distributedrebirth.numberxd.base2t.type.V072Tong;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
@ -33,45 +30,6 @@ public class FontAtlasStoreGlyph {
public void addTong(V072Tong glyph) {
this.tongs.add(glyph);
}
public List<T08PartOctal> theOct64() {
List<T08PartOctal> result = new ArrayList<>();
BaseAppenderOctal appender = new BaseAppenderOctal(result);
for (V072Tong tong: tongs) {
tong.fillOctalsByClone(appender);
}
return result;
}
public void doOct64(List<T08PartOctal> data) {
BaseIteratorOctalAdapter adapter = new BaseIteratorOctalAdapter(data.iterator());
List<V072Tong> result = new ArrayList<>();
while (adapter.hasNext()) {
result.add(new V072Tong(adapter));
}
tongs = result;
}
public byte[] theByte64() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
Base2Terminator.INSTANCE.Bãß2WriteTong(tongs, baos);
} catch (IOException e) {
throw new RuntimeException(e);
}
return baos.toByteArray();
}
public void doByte64(byte[] decodedBytes) {
ByteArrayInputStream bais = new ByteArrayInputStream(decodedBytes);
try {
List<V072Tong> result = new ArrayList<>();
Base2Terminator.INSTANCE.Bãß2ReadTong(bais, result);
tongs = result;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public String getBase64() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();

View file

@ -142,15 +142,6 @@ public class TestConvFont {
baseGlyph.setTongs(tongs);
fontStore.addGlyph(baseGlyph);
int unicode = CodePointᶻᴰ.INSTANCE.searchUnicode(baseGlyph.getTongs());
System.out.println("Converted: "+Integer.toHexString(unicode));
FontAtlasStoreGlyph baseGlyph2 = new FontAtlasStoreGlyph();
baseGlyph2.doByte64(baseGlyph.theByte64());
int unicode2 = CodePointᶻᴰ.INSTANCE.searchUnicode(baseGlyph2.getTongs());
System.out.println("Converted2: "+Integer.toHexString(unicode2));
} else if ("contour".equals(qName)) {
}

View file

@ -24,7 +24,7 @@ import love.distributedrebirth.unicode4d.atlas.FontAtlasStoreGlyph;
public class VrGem4Unicode4DServiceImpl implements VrGem4Unicode4DService {
private final FontAtlas masterFontAtlas;
private final Map<Character, FontAtlasStoreGlyph> unicodeMap;
private final Map<Integer, FontAtlasStoreGlyph> unicodeMap;
@Reference
private SystemGdxLog log;
@ -54,11 +54,11 @@ public class VrGem4Unicode4DServiceImpl implements VrGem4Unicode4DService {
log.info(this, "Master font atlas size: {}", masterFontAtlas.getStores().size());
for (FontAtlasStore fontStore:masterFontAtlas.getStores()) {
log.info(this,"Map unicode: {}", fontStore.getName());
log.info(this,"Map unicode: {} size: {}", fontStore.getName(), fontStore.getGlyphs().size());
for (FontAtlasStoreGlyph glyph: fontStore.getGlyphs()) {
int unicode = CodePointᶻᴰ.INSTANCE.searchUnicode(glyph.getTongs());
if (unicode > 0) {
unicodeMap.put(Character.valueOf((char) unicode), glyph);
unicodeMap.put(unicode, glyph);
}
}
}
@ -76,7 +76,7 @@ public class VrGem4Unicode4DServiceImpl implements VrGem4Unicode4DService {
}
@Override
public FontAtlasStoreGlyph getGlyphForUnicode(char unicode) {
public FontAtlasStoreGlyph getGlyphForUnicode(int unicode) {
return unicodeMap.get(unicode);
}
}

View file

@ -7,5 +7,5 @@ public interface VrGem4Unicode4DService {
FontAtlas getMasterFontAtlas();
FontAtlasStoreGlyph getGlyphForUnicode(char unicode);
FontAtlasStoreGlyph getGlyphForUnicode(int unicode);
}