Skip to content

Commit

Permalink
Merge pull request #43 from sakkeerhussain/master
Browse files Browse the repository at this point in the history
Removed image size maximum of 255 px restriction
  • Loading branch information
mazenrashed authored Mar 4, 2022
2 parents 4744efa + 6a43ee6 commit b9306a1
Showing 1 changed file with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,35 @@ object ImageUtils {
}

val bmpHexList = binaryListToHexStringList(list)
val commandHexString = "1D763000"
var widthHexString = Integer
.toHexString(if (bmpWidth % 8 == 0)
bmpWidth / 8
else
bmpWidth / 8 + 1)
if (widthHexString.length > 2) {
val commandHexString = "1D763000"

val printWidth = if (bmpWidth % 8 == 0) bmpWidth / 8 else bmpWidth / 8 + 1
var printLowWidthHex = Integer.toHexString(getLowValue(printWidth))
var printHighWidthHex = Integer.toHexString(getHighValue(printWidth))
if (printHighWidthHex.length > 2) {
Log.e("decodeBitmap error", " width is too large")
return null
} else if (widthHexString.length == 1) {
widthHexString = "0$widthHexString"
} else if (printHighWidthHex.length == 1) {
printHighWidthHex = "0$printHighWidthHex"
}
if (printLowWidthHex.length == 1) {
printLowWidthHex = "0$printLowWidthHex"
}
widthHexString += "00"

var heightHexString = Integer.toHexString(bmpHeight)
if (heightHexString.length > 2) {
var printLowHeightHex = Integer.toHexString(getLowValue(bmpHeight))
var printHighHeightHex = Integer.toHexString(getHighValue(bmpHeight))
if (printHighHeightHex.length > 2) {
Log.e("decodeBitmap error", " height is too large")
return null
} else if (heightHexString.length == 1) {
heightHexString = "0$heightHexString"
} else if (printHighHeightHex.length == 1) {
printHighHeightHex = "0$printHighHeightHex"
}
if (printLowHeightHex.length == 1) {
printLowHeightHex = "0$printLowHeightHex"
}
heightHexString += "00"

val commandList = ArrayList<String>()
commandList.add(commandHexString + widthHexString + heightHexString)
commandList.add(commandHexString + printLowWidthHex + printHighWidthHex + printLowHeightHex + printHighHeightHex)
commandList.addAll(bmpHexList)

return hexList2Byte(commandList)
Expand Down Expand Up @@ -156,4 +160,22 @@ object ImageUtils {
return "0123456789ABCDEF".indexOf(c).toByte()
}

}
private fun getLowValue(rawValue: Int): Int {
var value = rawValue
while (value > 255) {
value -= 256
}
return value
}

private fun getHighValue(rawValue: Int): Int {
var value = rawValue
var res = 0
while (value > 255) {
value -= 256
res++
}
return res
}

}

0 comments on commit b9306a1

Please sign in to comment.