Skip to content

Commit b9306a1

Browse files
authored
Merge pull request #43 from sakkeerhussain/master
Removed image size maximum of 255 px restriction
2 parents 4744efa + 6a43ee6 commit b9306a1

File tree

1 file changed

+39
-17
lines changed
  • printooth/src/main/java/com/mazenrashed/printooth/utilities

1 file changed

+39
-17
lines changed

printooth/src/main/java/com/mazenrashed/printooth/utilities/ImageUtils.kt

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,35 @@ object ImageUtils {
4949
}
5050

5151
val bmpHexList = binaryListToHexStringList(list)
52-
val commandHexString = "1D763000"
53-
var widthHexString = Integer
54-
.toHexString(if (bmpWidth % 8 == 0)
55-
bmpWidth / 8
56-
else
57-
bmpWidth / 8 + 1)
58-
if (widthHexString.length > 2) {
52+
val commandHexString = "1D763000"
53+
54+
val printWidth = if (bmpWidth % 8 == 0) bmpWidth / 8 else bmpWidth / 8 + 1
55+
var printLowWidthHex = Integer.toHexString(getLowValue(printWidth))
56+
var printHighWidthHex = Integer.toHexString(getHighValue(printWidth))
57+
if (printHighWidthHex.length > 2) {
5958
Log.e("decodeBitmap error", " width is too large")
6059
return null
61-
} else if (widthHexString.length == 1) {
62-
widthHexString = "0$widthHexString"
60+
} else if (printHighWidthHex.length == 1) {
61+
printHighWidthHex = "0$printHighWidthHex"
62+
}
63+
if (printLowWidthHex.length == 1) {
64+
printLowWidthHex = "0$printLowWidthHex"
6365
}
64-
widthHexString += "00"
6566

66-
var heightHexString = Integer.toHexString(bmpHeight)
67-
if (heightHexString.length > 2) {
67+
var printLowHeightHex = Integer.toHexString(getLowValue(bmpHeight))
68+
var printHighHeightHex = Integer.toHexString(getHighValue(bmpHeight))
69+
if (printHighHeightHex.length > 2) {
6870
Log.e("decodeBitmap error", " height is too large")
6971
return null
70-
} else if (heightHexString.length == 1) {
71-
heightHexString = "0$heightHexString"
72+
} else if (printHighHeightHex.length == 1) {
73+
printHighHeightHex = "0$printHighHeightHex"
74+
}
75+
if (printLowHeightHex.length == 1) {
76+
printLowHeightHex = "0$printLowHeightHex"
7277
}
73-
heightHexString += "00"
7478

7579
val commandList = ArrayList<String>()
76-
commandList.add(commandHexString + widthHexString + heightHexString)
80+
commandList.add(commandHexString + printLowWidthHex + printHighWidthHex + printLowHeightHex + printHighHeightHex)
7781
commandList.addAll(bmpHexList)
7882

7983
return hexList2Byte(commandList)
@@ -156,4 +160,22 @@ object ImageUtils {
156160
return "0123456789ABCDEF".indexOf(c).toByte()
157161
}
158162

159-
}
163+
private fun getLowValue(rawValue: Int): Int {
164+
var value = rawValue
165+
while (value > 255) {
166+
value -= 256
167+
}
168+
return value
169+
}
170+
171+
private fun getHighValue(rawValue: Int): Int {
172+
var value = rawValue
173+
var res = 0
174+
while (value > 255) {
175+
value -= 256
176+
res++
177+
}
178+
return res
179+
}
180+
181+
}

0 commit comments

Comments
 (0)