public void storeCustomFormat(Bitmap image, string name) { byte[] array = new byte[(imageModel.getHeight() / 2 * imageModel.getWidth() / 2) * 3]; int counter = 0; for (int y = 0; y < imageModel.getHeight(); y += 2) { for (int x = 0; x < imageModel.getWidth(); x += 2) { array[counter++] = image.GetPixel(x, y).R; array[counter++] = image.GetPixel(x, y).G; array[counter++] = image.GetPixel(x, y).B; } } uint originalDataSize = (uint)(imageModel.getHeight() / 2 * imageModel.getWidth() / 2) * 3; byte[] compressedData = new byte[originalDataSize * (101 / 100) + 384]; int compressedDataSize = CompressionController.Compress(array, compressedData, originalDataSize); this.saveToCustomFormat(name, compressedDataSize, compressedData, image); MessageBox.Show("Compression done!"); }
public void loadCustomFormat(string name) { int width = 0; int height = 0; byte[] compressedData = this.loadFromCustomFormat(name, width, height); uint originalDataSize = (uint)(height / 2 * width / 2) * 3; byte[] decompressedData = new byte[originalDataSize]; uint compressedDataSize = originalDataSize * (101 / 100) + 384; CompressionController.Decompress(compressedData, decompressedData, (uint)compressedDataSize, originalDataSize); int counter = 0; Bitmap bmp = new Bitmap(width, height); Color c; for (int y = 0; y < height; y += 2) { for (int x = 0; x < width; x += 2) { c = Color.FromArgb(decompressedData[counter++], decompressedData[counter++], decompressedData[counter++]); bmp.SetPixel(x, y, c); bmp.SetPixel(x + 1, y, c); bmp.SetPixel(x, y + 1, c); bmp.SetPixel(x + 1, y + 1, c); } } imageModel.setImageFromBitmap(bmp); imageModel.setCIEImage(setCIEImage(bmp)); RGBModel[,] rgbImage = convertToRGB(imageModel.getCIEImage()); histogramView.setBaseImage(imageModel.getFilteredImage()); baseView.setBaseImageFromBitmap(imageModel.getBaseImage()); channelView.setFilteredChannelImages(bmp, setRedChannel(rgbImage), setGreenChannel(rgbImage), setBlueChannel(rgbImage)); undoBuffer.clearBuffer(); redoBuffer.clearBuffer(); }