22:
224:
Note that interpreting 0 as positive or negative makes no difference in the output. Runs of two bytes adjacent to non-runs are typically written as literal data. There is no way based on the PackBits data to determine the end of the data stream; that is to say, one must already know the size of the
166:
A PackBits data stream consists of packets with a one-byte header followed by data. The header is a signed byte; the data can be signed, unsigned, or packed (such as MacPaint pixels).
1485:
159:
files also use this RLE compression scheme, but treats data stream as pixels instead of bytes. Packbit compression was also used in
113:
1450:
195:
47:
235:
94:
66:
32:
51:
36:
130:
43:
73:
1465:
80:
62:
134:
1455:
225:
compressed or uncompressed data before reading a PackBits data stream to know where it ends.
148:
156:
87:
1479:
1415:// Output is: AA AA AA 80 00 2A AA AA AA AA 80 00 2A 22 AA AA AA AA AA AA AA AA AA AA
228:
Apple
Computer (see the external link) provides this short example of packed data:
21:
1469:
666:
140:
654:'AA AA AA 80 00 2A AA AA AA AA 80 00 2A 22 AA AA AA AA AA AA AA AA AA AA
144:
1466:
PACKBITS Compression or Why We
Support Lossless TIFF Compression Method?
160:
152:
1459:
15:
683:* Also, see this fiddle for interactive PackBits decoder:
218:
No operation (skip and treat next byte as a header byte)
318:"FE AA 02 80 00 2A FD AA 03 80 00 2A 22 F7 AA"
1385:'FE AA 02 80 00 2A FD AA 03 80 00 2A 22 F7 AA'
677:* Helper functions to create readable input and output
173:
is the value of the header byte as a signed integer.
143:introduced the PackBits format with the release of
151:computer. This compression scheme can be used in
8:
1470:https://www.universal-document-converter.com
1451:Apple webpage describing the PackBits format
230:FE AA 02 80 00 2A FD AA 03 80 00 2A 22 F7 AA
50:. Unsourced material may be challenged and
114:Learn how and when to remove this message
175:
7:
1462:site with permission from Corion.net
48:adding citations to reliable sources
210:) times in the decompressed output
686:* https://jsfiddle.net/y13xkh65/3/
14:
206:One byte of data, repeated (1 โ
20:
1486:Lossless compression algorithms
234:The following code, written in
182:Data following the header byte
1:
1472:also describes the algorithm.
1460:https://www.fileformat.info
1456:The TIFF PackBits Algorithm
665:The same implementation in
1502:
1250:// These are literal bytes
1133:// This is a repeated byte
968:* PackBits unpack function
453:'Two's Complement
671:
240:
169:In the following table,
627:'Adjust the pointer
534:'Adjust the pointer
974:* @param {String} data
1468:the article on site
238:, unpacks the data:
131:lossless compression
44:improve this article
135:run-length encoding
1103:// Do nothing, nop
977:* @return {String}
129:is a fast, simple
393:WorksheetFunction
222:
221:
124:
123:
116:
98:
1493:
1440:
1437:
1434:
1431:
1428:
1425:
1422:
1419:
1416:
1413:
1410:
1407:
1404:
1401:
1398:
1395:
1392:
1389:
1386:
1383:
1380:
1377:
1374:
1371:
1368:
1365:
1362:
1359:
1356:
1353:
1350:
1347:
1344:
1341:
1338:
1335:
1332:
1329:
1326:
1323:
1320:
1317:
1314:
1311:
1308:
1305:
1302:
1299:
1296:
1293:
1290:
1287:
1284:
1281:
1278:
1275:
1272:
1269:
1266:
1263:
1260:
1257:
1254:
1251:
1248:
1245:
1242:
1239:
1236:
1233:
1230:
1227:
1224:
1221:
1218:
1215:
1212:
1209:
1206:
1203:
1200:
1197:
1194:
1191:
1188:
1185:
1182:
1179:
1176:
1173:
1170:
1167:
1164:
1161:
1158:
1155:
1152:
1149:
1146:
1143:
1140:
1137:
1134:
1131:
1128:
1125:
1122:
1119:
1116:
1113:
1110:
1107:
1104:
1101:
1098:
1095:
1092:
1089:
1086:
1083:
1080:
1077:
1074:
1071:
1068:
1065:
1062:
1059:
1056:
1053:
1050:
1047:
1044:
1041:
1038:
1035:
1032:
1029:
1026:
1023:
1020:
1017:
1014:
1011:
1008:
1005:
1002:
999:
996:
993:
990:
987:
984:
981:
978:
975:
972:
969:
966:
963:
960:
957:
954:
951:
948:
945:
942:
939:
936:
933:
930:
927:
924:
921:
918:
915:
912:
909:
906:
903:
900:
897:
894:
891:
888:
885:
882:
879:
876:
873:
870:
867:
864:
861:
858:
855:
852:
849:
846:
843:
840:
837:
834:
831:
828:
825:
822:
819:
816:
813:
810:
807:
804:
801:
798:
795:
792:
789:
786:
783:
780:
777:
774:
771:
768:
765:
762:
759:
756:
753:
750:
747:
744:
741:
738:
735:
732:
729:
726:
723:
720:
717:
714:
711:
708:
705:
702:
699:
696:
693:
690:
687:
684:
681:
678:
675:
661:
658:
655:
652:
649:
646:
643:
640:
637:
634:
631:
628:
625:
622:
619:
616:
613:
610:
607:
604:
601:
598:
595:
592:
589:
586:
583:
580:
577:
574:
571:
568:
565:
562:
559:
556:
553:
550:
547:
544:
541:
538:
535:
532:
529:
526:
523:
520:
517:
514:
511:
508:
505:
502:
499:
496:
493:
490:
487:
484:
481:
478:
475:
472:
469:
466:
463:
460:
457:
454:
451:
448:
445:
442:
439:
436:
433:
430:
427:
424:
421:
418:
415:
412:
409:
406:
403:
400:
397:
394:
391:
388:
385:
382:
379:
376:
373:
370:
367:
364:
361:
358:
355:
352:
349:
346:
343:
340:
337:
334:
331:
328:
325:
322:
319:
316:
313:
310:
307:
304:
301:
298:
295:
292:
289:
286:
283:
280:
277:
274:
271:
268:
265:
262:
259:
256:
253:
250:
247:
244:
231:
176:
119:
112:
108:
105:
99:
97:
56:
24:
16:
1501:
1500:
1496:
1495:
1494:
1492:
1491:
1490:
1476:
1475:
1458:taken from the
1447:
1442:
1441:
1438:
1435:
1432:
1429:
1426:
1423:
1420:
1417:
1414:
1411:
1408:
1405:
1402:
1399:
1396:
1393:
1390:
1387:
1384:
1381:
1378:
1375:
1372:
1369:
1366:
1363:
1360:
1357:
1354:
1351:
1348:
1345:
1342:
1339:
1336:
1333:
1330:
1327:
1324:
1321:
1318:
1315:
1312:
1309:
1306:
1303:
1300:
1297:
1294:
1291:
1288:
1285:
1282:
1279:
1276:
1273:
1270:
1267:
1264:
1261:
1258:
1255:
1252:
1249:
1246:
1243:
1240:
1237:
1234:
1231:
1228:
1225:
1222:
1219:
1216:
1213:
1210:
1207:
1204:
1201:
1198:
1195:
1192:
1189:
1186:
1183:
1180:
1177:
1174:
1171:
1168:
1165:
1162:
1159:
1156:
1153:
1150:
1147:
1144:
1141:
1138:
1135:
1132:
1129:
1126:
1123:
1120:
1117:
1114:
1111:
1108:
1105:
1102:
1099:
1096:
1093:
1090:
1087:
1084:
1081:
1078:
1075:
1072:
1069:
1066:
1063:
1060:
1057:
1054:
1051:
1048:
1045:
1042:
1039:
1036:
1033:
1030:
1027:
1024:
1021:
1018:
1015:
1012:
1009:
1006:
1003:
1000:
997:
994:
991:
988:
985:
982:
979:
976:
973:
970:
967:
964:
961:
958:
955:
952:
949:
946:
943:
940:
937:
934:
931:
928:
925:
922:
919:
916:
913:
910:
907:
904:
901:
898:
895:
892:
889:
886:
883:
880:
877:
874:
871:
868:
865:
862:
859:
856:
853:
850:
847:
844:
841:
838:
835:
832:
829:
826:
823:
820:
817:
814:
811:
808:
805:
802:
799:
796:
793:
790:
787:
784:
781:
778:
775:
772:
769:
766:
763:
760:
757:
754:
751:
748:
745:
742:
739:
736:
733:
730:
727:
724:
721:
718:
715:
712:
709:
706:
703:
700:
697:
694:
691:
688:
685:
682:
679:
676:
673:
663:
662:
659:
656:
653:
650:
647:
644:
641:
638:
635:
632:
629:
626:
623:
620:
617:
614:
611:
608:
605:
602:
599:
596:
593:
590:
587:
584:
581:
578:
575:
572:
569:
566:
563:
561:'zero-based
560:
557:
554:
551:
548:
545:
542:
539:
536:
533:
530:
527:
524:
521:
518:
515:
512:
509:
506:
503:
500:
497:
494:
491:
488:
485:
482:
479:
476:
474:'zero-based
473:
470:
467:
464:
461:
458:
455:
452:
449:
446:
443:
440:
437:
434:
431:
428:
425:
422:
419:
416:
413:
410:
407:
404:
401:
398:
395:
392:
389:
386:
383:
380:
377:
374:
371:
368:
365:
362:
359:
356:
353:
350:
347:
344:
341:
338:
335:
332:
329:
326:
323:
320:
317:
314:
311:
308:
305:
302:
299:
296:
293:
290:
287:
284:
281:
278:
275:
272:
269:
266:
263:
260:
257:
254:
251:
248:
245:
242:
229:
120:
109:
103:
100:
57:
55:
41:
25:
12:
11:
5:
1499:
1497:
1489:
1488:
1478:
1477:
1474:
1473:
1463:
1453:
1446:
1445:External links
1443:
672:
246:UnpackBitsDemo
241:
220:
219:
216:
212:
211:
204:
200:
199:
198:bytes of data
188:
184:
183:
180:
122:
121:
28:
26:
19:
13:
10:
9:
6:
4:
3:
2:
1498:
1487:
1484:
1483:
1481:
1471:
1467:
1464:
1461:
1457:
1454:
1452:
1449:
1448:
1444:
670:
668:
603:" "
510:" "
339:" "
239:
237:
236:Microsoft VBA
232:
226:
217:
214:
213:
209:
205:
202:
201:
197:
193:
189:
186:
185:
181:
178:
177:
174:
172:
167:
164:
162:
158:
154:
150:
146:
142:
138:
136:
132:
128:
118:
115:
107:
96:
93:
89:
86:
82:
79:
75:
72:
68:
65: โ
64:
60:
59:Find sources:
53:
49:
45:
39:
38:
34:
29:This article
27:
23:
18:
17:
923:fromCharCode
664:
233:
227:
223:
207:
191:
170:
168:
165:
139:
126:
125:
110:
104:October 2011
101:
91:
84:
77:
70:
58:
42:Please help
30:
887:' '
845:' '
830:toUpperCase
797:'0'
387:Application
179:Header byte
133:scheme for
1397:unpackBits
1070:charCodeAt
1010:''
986:unpackBits
956:''
803:''
767:charCodeAt
725:''
667:JavaScript
203:โ1 to โ127
74:newspapers
63:"PackBits"
149:Macintosh
137:of data.
31:does not
1480:Category
1409:original
1379:original
983:function
929:parseInt
899:function
854:function
818:toString
737:function
692:function
651:MyOutput
570:MyOutput
564:MyOutput
483:MyOutput
477:MyOutput
267:MyOutput
187:0 to 127
163:files.
145:MacPaint
127:PackBits
1430:str2hex
1418:console
1403:hex2str
857:hex2str
695:str2hex
399:Hex2Dec
261:Variant
196:literal
155:files.
147:on the
88:scholar
52:removed
37:sources
1367:output
1364:return
1310:charAt
1298:output
1211:charAt
1199:output
1046:length
1004:output
935:string
917:String
914:return
905:string
872:return
779:return
710:return
633:Select
417:Select
369:UBound
354:LBound
273:String
90:
83:
76:
69:
61:
1277:<=
1178:<=
1028:while
881:split
812:value
785:value
755:value
719:split
648:Print
642:Debug
600:&
573:&
558:Count
507:&
486:&
471:Count
450:Count
438:Count
432:>=
423:Count
381:Count
327:Split
279:Count
190:(1 +
141:Apple
95:JSTOR
81:books
1436:data
1391:data
1304:data
1244:else
1205:data
1121:>
1109:else
1064:data
1040:data
1037:<
992:data
950:join
839:join
788:<
761:char
743:char
636:Next
606:Next
576:File
540:Else
537:Case
513:Next
489:File
426:Case
420:Case
405:File
375:File
360:File
333:File
321:File
312:File
309:Long
297:Long
285:Long
255:File
215:โ128
161:ILBM
153:TIFF
67:news
35:any
33:cite
1439:));
1424:log
1412:));
1376:var
1280:hex
1259:var
1253:for
1181:hex
1160:var
1154:for
1148:hex
1142:256
1136:hex
1124:128
1118:hex
1094:128
1088:hex
1058:hex
1055:var
1001:var
965:/**
947:}).
944:));
893:map
875:hex
863:hex
836:}).
833:();
827:)).
752:var
731:map
713:str
701:str
674:/**
660:Sub
657:End
630:End
543:For
456:For
444:256
435:128
345:For
288:Dim
276:Dim
264:Dim
252:Dim
243:Sub
157:TGA
46:by
1482::
1352:++
1340:+=
1331:);
1301:+=
1286:++
1232:++
1226:);
1202:+=
1187:++
1112:if
1091:==
1082:if
1079:);
980:*/
971:*
959:);
941:16
890:).
848:);
824:16
791:16
782:((
776:);
728:).
689:*/
680:*
669::
555:To
468:To
429:Is
414:))
366:To
306:As
294:As
282:As
270:As
258:As
249:()
194:)
1433:(
1427:(
1421:.
1406:(
1400:(
1394:=
1388:,
1382:=
1373:}
1370:;
1361:}
1358:;
1355:i
1349:}
1346:;
1343:j
1337:i
1334:}
1328:1
1325:+
1322:j
1319:+
1316:i
1313:(
1307:.
1295:{
1292:)
1289:j
1283:;
1274:j
1271:;
1268:0
1265:=
1262:j
1256:(
1247:{
1241:}
1238:;
1235:i
1229:}
1223:1
1220:+
1217:i
1214:(
1208:.
1196:{
1193:)
1190:j
1184:;
1175:j
1172:;
1169:0
1166:=
1163:j
1157:(
1151:;
1145:-
1139:=
1130:{
1127:)
1115:(
1106:}
1100:{
1097:)
1085:(
1076:i
1073:(
1067:.
1061:=
1052:{
1049:)
1043:.
1034:i
1031:(
1025:;
1022:0
1019:=
1016:i
1013:,
1007:=
998:{
995:)
989:(
962:}
953:(
938:,
932:(
926:(
920:.
911:{
908:)
902:(
896:(
884:(
878:.
869:{
866:)
860:(
851:}
842:(
821:(
815:.
809:+
806:)
800::
794:?
773:0
770:(
764:.
758:=
749:{
746:)
740:(
734:(
722:(
716:.
707:{
704:)
698:(
645:.
639:i
624:j
621:+
618:i
615:=
612:i
609:j
597:)
594:1
591:+
588:j
585:+
582:i
579:(
567:=
552:0
549:=
546:j
531:1
528:+
525:i
522:=
519:i
516:j
504:)
501:1
498:+
495:i
492:(
480:=
465:0
462:=
459:j
447:-
441:=
411:i
408:(
402:(
396:.
390:.
384:=
378:)
372:(
363:)
357:(
351:=
348:i
342:)
336:,
330:(
324:=
315:=
303:j
300:,
291:i
208:n
192:n
171:n
117:)
111:(
106:)
102:(
92:ยท
85:ยท
78:ยท
71:ยท
54:.
40:.
Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.