MCPcopy Create free account
hub / github.com/SimHacker/micropolis / ditherMap

Method ditherMap

MicropolisCore/src/MicropolisEngine/src/map.cpp:745–817  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

743
744
745void Micropolis::ditherMap()
746{
747/*
748 int i, x, y, width, height;
749 int err, pixel1, pixel8;
750 int line_bytes1 = view->line_bytes;
751 int line_bytes8 = view->line_bytes8;
752 unsigned char *image1 = view->data;
753 unsigned char *image8 = view->data8;
754 int *errors;
755
756 width = view->m_width;
757 height = view->m_height;
758
759 errors = (int *)newPtr(sizeof(int) * width);
760
761 for (i = 0; i < width; i++) {
762 errors[i] = (getRandom16() & 15) - 7;
763 }
764
765 err = (getRandom16() & 15) - 7;
766
767 for (y = 0; y < height; y += 2) {
768 unsigned char *i1 = image1;
769 unsigned char *i8 = image8;
770
771 image1 += line_bytes1;
772 image8 += line_bytes8;
773
774 for (x = 0; x < width; x += 8) {
775 pixel1 = 0;
776 for (i = 0; i < 8; i++) {
777 pixel1 <<= 1;
778 pixel8 = *(i8++) + err + errors[x + i];
779 if (pixel8 > 127) {
780 err = pixel8 - 255;
781 } else {
782 pixel1 |= 1;
783 err = pixel8;
784 }
785 errors[x + i] = err/2;
786 err = err/2;
787 }
788 *(i1++) = pixel1;
789 }
790
791 i1 = image1 + (width / 8) - 1;
792 i8 = image8 + width - 1;
793
794 image1 += line_bytes1;
795 image8 += line_bytes8;
796
797 for (x = width - 8; x >= 0; x -= 8) {
798 pixel1 = 0;
799 for (i = 7; i >= 0; i--) {
800 pixel1 >>= 1;
801 pixel8 = *(i8--) + err + errors[x + i];
802 if (pixel8 > 127) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected