/// <summary> /// Runs a Run Length Encoding Algorithim on the selceted data. /// </summary> /// <param name="xData"></param> /// <param name="Mode"></param> /// <returns></returns> public static byte[] RunRLEAlgorithim(byte[] xData, RLEMode Mode) { if (Mode == RLEMode.Encode) { List <byte> tem = new List <byte>(); for (int i = 0; i < xData.Length; i++) { int rl = 1; while ((i + 1) < xData.Length && xData[i] == xData[i + 1]) { if (rl >= 255) { break; } rl++; i++; } tem.Add((byte)rl); tem.Add(xData[i]); } return(tem.ToArray()); } else if (Mode == RLEMode.Decode) { List <byte> tem = new List <byte>(); for (int i = 0; i < xData.Length; i += 2) { for (int j = 0; j < xData[i]; j++) { tem.Add(xData[i + 1]); } } return(tem.ToArray()); } else { throw MojoIOExceptions.InvalidInputException; } }
public RHR_RLETileEncoder(RLEMode mode) { Mode = mode; }
/// <summary> /// Runs a Run Length Encoding Algorithim on the selceted data. /// </summary> /// <param name="xData"></param> /// <param name="Mode"></param> /// <returns></returns> public static byte[] RunRLEAlgorithim(byte[] xData, RLEMode Mode) { if (Mode == RLEMode.Encode) { List<byte> tem = new List<byte>(); for (int i = 0; i < xData.Length; i++) { int rl = 1; while ((i + 1) < xData.Length && xData[i] == xData[i + 1]) { if (rl >= 255) break; rl++; i++; } tem.Add((byte)rl); tem.Add(xData[i]); } return tem.ToArray(); } else if (Mode == RLEMode.Decode) { List<byte> tem = new List<byte>(); for (int i = 0; i < xData.Length; i += 2) for (int j = 0; j < xData[i]; j++) tem.Add(xData[i + 1]); return tem.ToArray(); } else throw MojoIOExceptions.InvalidInputException; }