5

please can someone explain the 'GS v 0' command? I want to print some Bitmap on my thermal printer. I can't understand the parameters xL xH yL ...

The following is in the programming guide, but until now I can't see solution.

ASCII: Gs v 0 Decimal: 29 118 48 m xL xH yL yH [d]k Hexadecimal: 1D 76 30 m xL xH yL yH [d]k

0 ≤ m ≤ 3, 48 ≤ m ≤ 51 0 ≤ xL ≤ 255 0 ≤ xH ≤ 255 0 ≤ yL ≤ 255 0 ≤ d ≤ 255 k = ( xL + xH × 256) × ( yL + yH × 256) ( k ≠ 0)

xL, xH specifies (xL + xH × 256) bytes in horizontal direction for the bit image. yL, yH specifies (yL + yH × 256) dots in vertical direction for the bit image. [d]k specifies the bit image data (raster format).

Mexxchen
  • 51
  • 1
  • 4
  • Seems is getting deprecated, the alternative way to print is ESC * and [here](http://new-grumpy-mentat.blogspot.com.co/2014/06/java-escpos-image-printing.html) you can find information – William Ardila Aug 01 '17 at 21:49

3 Answers3

6

First let me say that I know the question is old and this command is considered obsolete, but there is still a huge market out there with thermal printers that accept this command.

Don't have enough points on this account to write a comment on @Fewl 's answer.

He is right about yL and yH, but not about xL and xH.

xL, xH specifies (xL + xH × 256) bytes in horizontal direction for the bit image.

yL, yH specifies (yL + yH × 256) dots in vertical direction for the bit image.

Ref: https://www.epson-biz.com/modules/ref_escpos/index.php?content_id=94

So let's say that your bitmap is 384 pixels wide and 260 pixels tall, then:

xL = width % 2048 / 8;
xH = width / 2048;
// width = 384
// xL = 48
// xH = 0
// (xL + xH × 256) = 48 + 0 x 256 = 48 **bytes** in horizontal direction.


yL = height % 256;
yH = height / 256;
//height = 260
// yL = 4
// yH = 1
// (yL + yH × 256) = 4 + 1 x 256 = 260 **dots** in vertical direction

Explanation, example bit image has 384 / 8 = 48 bytes in the horizontal direction, since 48 < 256 you don't need to calculate xH (High byte) it will be 0. You would only need to calculate xH if your bitmap is wider than 8 * 256 = 2048 dots... Which is highly unlikely to happen with thermal pos printers but I've included even that scenario in the code above.

Important note! My example width (384) is divisible by 8. If it isn't you will have to account for that by rounding up the division and pad the bit data with zeroes... or simply resize the bitmap beforehand to have its width divisible by 8.

Community
  • 1
  • 1
Uroš
  • 1,428
  • 1
  • 12
  • 18
  • Where does the 2048 come from? – vesperto Jun 14 '21 at 14:29
  • I've already covered that in my explanation: "You would only need to calculate xH if your bitmap is wider than 8 * 256 = 2048 dots", that is where 2048 comes from. If the bitmap is less than 2048 dots wide you don't need the modulo operation for the xL (just divide width by 8) and obviously you don't need to calculate xH, it will be 0. – Uroš Jun 15 '21 at 16:20
1

As mentioned, the command GS v 0 is obsolete, in place you should try ESC * or GS ( L / GS 8 L.

But, just to answer the question...

xL, xH refers to the width of the bitmap image, and yL, yH the height, as you know.

You said that those values must be between 0 and 255, and to achieve then you do the following:

xL = width % 256
xH = width / 256
yL = height % 256
yH = height / 256

So, let's say you have a 300x200 image. Those values would be:

xL = 44, xH = 1, yL = 200, yH = 0 (decimal)

k = (44 + 1 * 256) * (200 + 0 * 256) = 60.000 (which is the 300x200)

Using the Hex command, you have: 1D 76 30 m 2C 01 C8 00 [d]k, where m is the mode and [d]k is 60.000 bytes image data.

Fewl
  • 11
  • 1
  • 4
0

Using the Hex command, you have: 1D 76 30 m 2C 01 C8 00 [d]k, where m is the mode and [d]k is 60.000 bites image data or 937 bytes (8x8).

Sergey
  • 1