private static void removeRowFilters(int width, int height, byte[] data, int offset) {

		/*
		 * Yes, it is generally bad convention to have x in function scope in this way. However the 
		 * source code this was retrieved from www.jongware.com/pngdefry.html
		 * has cases where x could be 4*width or 0 such as case 3 in the switch below
		 * so I am duplicating the original implementation as closely as possible.
		 */
		int x = 0;
		int srcPtr = offset;

		for (int y = 0; y < height; y++) {
			int rowFilter = data[srcPtr];
			srcPtr++;

			switch (rowFilter) {
				case 0: //None
					break;

				case 1: //Sub
					for (x = 4; x < 4 * width; x++) {
						data[srcPtr + x] += data[srcPtr + (x - 4)];
					}
					break;

				case 2: //Up
					int upPtr = srcPtr - 4 * width - 1;
					if (y > 0) {
						for (x = 4; x < 4 * width; x++) {
							data[srcPtr + x] += data[upPtr + x];
						}
					}
					break;

				case 3: //Average
					upPtr = srcPtr - 4 * width - 1;

					if (y == 0) {
						for (x = 4; x < 4 * width; x++) {
							data[srcPtr + x] += ((data[upPtr + x] + data[srcPtr + (x - 4)]) >> 1);
						}
					}
					else {
						data[srcPtr] += (data[upPtr + x] >> 1);
						for (x = 4; x < 4 * width; x++) {
							data[srcPtr + x] += ((data[upPtr + x] + data[srcPtr + (x - 4)]) >> 1);
						}
					}
					break;

				case 4: //Paeth
					upPtr = srcPtr - 4 * width - 1;

					for (x = 0; x < 4 * width; x++) {
						int leftPix = 0;
						int topPix = 0;
						int topLeftPix = 0;
						if (x > 0) {
							leftPix = data[srcPtr + (x - 4)];
						}
						if (y > 0) {
							topPix = data[upPtr + x];
							if (x >= 4) {
								topLeftPix = data[upPtr + (x - 4)];
							}
						}
						int p = leftPix + topPix - topLeftPix;
						int pa = p - leftPix;
						if (pa < 0) {
							pa = -pa;
						}
						int pb = p - topPix;
						if (pb < 0) {
							pb = -pb;
						}
						int pc = p - topLeftPix;
						if (pc < 0) {
							pc = -pc;
						}

						int value;
						if (pa <= pb && pa <= pc) {
							value = leftPix;
						}
						else if (pb < pc) {
							value = topPix;
						}
						else {
							value = topLeftPix;
						}
						data[srcPtr + x] += value;
					}
					break;

			}
			srcPtr += 4 * width;
		}

	}
Removes the row filters from the image data
@param width the image width
@param height the image height
@param data the image data
@param offset the offset into data
Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/CrushedPNGUtil.java