filter updates

This commit is contained in:
Pin
2021-11-11 00:50:08 -05:00
parent 7caca5e7e6
commit b8600c17d5

View File

@@ -8,6 +8,7 @@
#include <sodium.h> #include <sodium.h>
#include <getopt.h> #include <getopt.h>
#include <pthread.h> #include <pthread.h>
#include <math.h>
#include "crc_util.h" #include "crc_util.h"
#include "CRCLib.h" #include "CRCLib.h"
#include "pspng.h" #include "pspng.h"
@@ -70,11 +71,74 @@ int update_file_crc(unsigned char *addr, unsigned long offset , unsigned int crc
return 0; return 0;
} }
static void random_window_bit_change(unsigned char *data, int width, int rounds, int color_range, size_t length, size_t offset) { static unsigned char* create_raw_pixel_values(unsigned char *data, int width, int color_range, size_t length) {
// Generating twice the size we migth need
length = length * 2;
//length = 500000;
unsigned char* raw_data = calloc(length, sizeof(unsigned char*));
size_t filter_chunk_byte = 0;
for(size_t i = 0; i < length; i++) {
filter_chunk_byte = i - (i % ((width * color_range) + 1));
// Grabbing raw pixel data
if(data[filter_chunk_byte] == 0) {
// Filter: None
raw_data[i] = data[i];
} else if(data[filter_chunk_byte] == 1) {
// Filter: Sub
if ((i % ((width * color_range) + 1)) == 0) {
// Setting filter type
raw_data[i] = data[i];
} else if ((i - filter_chunk_byte) <= color_range) {
// Setting initial color_range byte
raw_data[i] = data[i];
} else {
// Setting remaining bytes
raw_data[i] = data[i] + raw_data[i - color_range];
}
} else if(data[filter_chunk_byte] == 3) {
// Filter: Average
if((i % ((width * color_range) + 1)) == 0) {
// Setting filter type
raw_data[i] = data[i];
} else {
// Setting remaining bytes
if(filter_chunk_byte == 0) {
// If no scanline is present before current
if((i - filter_chunk_byte) <= color_range) {
// If no pixel present before current
raw_data[i] = data[i] + floor((0 + 0) / 2);
} else {
// If pixel present before current
raw_data[i] = data[i] + floor((data[i - color_range] + 0) / 2);
}
} else {
// Scanline is present before current
if((i - filter_chunk_byte) <= color_range) {
// If no pixel present before current
raw_data[i] = data[i] + floor((0 + raw_data[i - ((width * color_range) + 1)]) / 2);
} else {
// If pixel present before current
raw_data[i] = data[i] + floor((raw_data[i - color_range] + raw_data[i - ((width * color_range) + 1)]) / 2);
}
}
}
} else {
// Filter: Error Unsupported
printf("Exiting due to unsupported filter type\n");
exit(EXIT_FAILURE);
}
}
return raw_data;
}
static void random_window_bit_change(unsigned char *data, unsigned char *raw_data, int width, int rounds, int color_range, size_t length, size_t offset) {
size_t random_num = 0; size_t random_num = 0;
size_t filter_chunk_byte = 0; size_t filter_chunk_byte = 0;
size_t change_num = 0;
long prior_chuck_check = 0;
for (int i = 0; i < rounds; i++) { for (int i = 0; i < rounds; i++) {
random_num = 0; random_num = 0;
do { do {
@@ -93,17 +157,21 @@ static void random_window_bit_change(unsigned char *data, int width, int rounds,
// Sub Filter Type Change // Sub Filter Type Change
if(data[random_num] == 255) { if(data[random_num] == 255) {
data[random_num]--; data[random_num]--;
change_num = 1; raw_data[random_num]--;
} else { } else {
data[random_num]++; data[random_num]++;
change_num = -1; raw_data[random_num]++;
} }
// Starting after random change // Fixing Next Pixel in Scanline
for(int j = 1; j < 2; j++) { if(!(random_num+3 > (filter_chunk_byte + (width * color_range) + 1))){
data[random_num+(color_range * j)] = (data[random_num+(color_range * j)] + change_num) % 256; data[random_num+color_range] = raw_data[random_num+color_range] - raw_data[random_num];
}
// Checking Next Scanline type
if(data[filter_chunk_byte+((width * color_range) + 1)] == 3){
data[random_num+((width * color_range)+1)] = raw_data[random_num+((width * color_range)+1)] - floor((raw_data[random_num+((width * color_range)+1)-color_range] + raw_data[random_num]) / 2);
} }
} else if(data[filter_chunk_byte] == 2) { } else if(data[filter_chunk_byte] == 2) {
printf("2\n"); // Add Support
if(data[random_num] == 255) { if(data[random_num] == 255) {
data[random_num]--; data[random_num]--;
} else { } else {
@@ -111,21 +179,23 @@ static void random_window_bit_change(unsigned char *data, int width, int rounds,
} }
} else if(data[filter_chunk_byte] == 3) { } else if(data[filter_chunk_byte] == 3) {
// Average Filter Type Change // Average Filter Type Change
//printf("HEE: %d\n", data[(filter_chunk_byte - (width * color_range))-1]); if(raw_data[random_num] == 255) {
prior_chuck_check = filter_chunk_byte; raw_data[random_num]--;
do {
//printf("C: %d\n", data[prior_chuck_check]);
prior_chuck_check = (prior_chuck_check - (width * color_range)-1);
//printf("CH: %ld\n", prior_chuck_check);
} while(prior_chuck_check >= 0);
if(data[random_num] == 255) {
data[random_num]--;
} else { } else {
data[random_num]++; raw_data[random_num]++;
}
// Update Current Pixel
data[random_num] = raw_data[random_num] - floor((raw_data[random_num-color_range] + raw_data[random_num-((width * color_range) + 1)]) / 2);
// Fixing Next Pixel in Scanline
if(!(random_num+color_range > (filter_chunk_byte + (width * color_range) + 1))){
data[random_num+color_range] = raw_data[random_num+color_range] - floor((raw_data[random_num] + raw_data[random_num-((width * color_range)+ 1)+color_range]) / 2);
}
// Checking Next Scanline type
if(data[filter_chunk_byte+((width * color_range) + 1)] == 3){
data[random_num+((width * color_range)+1)] = raw_data[random_num+((width * color_range)+1)] - floor((raw_data[random_num+((width * color_range)+1)-color_range] + raw_data[random_num]) / 2);
} }
} else if(data[filter_chunk_byte] == 4) { } else if(data[filter_chunk_byte] == 4) {
printf("4\n"); // Add Support
if(data[random_num] == 255) { if(data[random_num] == 255) {
data[random_num]--; data[random_num]--;
} else { } else {
@@ -182,9 +252,11 @@ static int verify_crc_chunks(unsigned char *data, size_t data_length, int crc_de
static int crc_embed_data(unsigned char *data, unsigned int data_length, int bit_width, int color_range, unsigned int sliding_window, char message, size_t offset , size_t iteration) { static int crc_embed_data(unsigned char *data, unsigned int data_length, int bit_width, int color_range, unsigned int sliding_window, char message, size_t offset , size_t iteration) {
unsigned char *check_data; unsigned char *check_data;
unsigned char *raw_data;
size_t check_data_length = 0; size_t check_data_length = 0;
random_window_bit_change(data, bit_width, 2, color_range, sliding_window, offset); raw_data = create_raw_pixel_values(data, bit_width, color_range, sliding_window);
random_window_bit_change(data, raw_data, bit_width, 1, color_range, sliding_window, offset);
// Compressing data for test // Compressing data for test
zlib_compress_data(data, data_length, &check_data, &check_data_length); zlib_compress_data(data, data_length, &check_data, &check_data_length);
@@ -197,6 +269,7 @@ static int crc_embed_data(unsigned char *data, unsigned int data_length, int bit
return 0; return 0;
} }
free(check_data); free(check_data);
free(raw_data);
return 1; return 1;
} }
@@ -215,8 +288,8 @@ void *random_data_change_thread_call(void *w) {
} else { } else {
data->data_len = data->uncom_data_len; data->data_len = data->uncom_data_len;
} }
if(data->uncom_data_len > 16000) { if(data->uncom_data_len > 36000) {
data->win_size = 9000 + (9000 * data->cur_iteration); data->win_size = 36000 + (36000 * data->cur_iteration);
} else { } else {
data->win_size = data->uncom_data_len; data->win_size = data->uncom_data_len;
} }
@@ -260,7 +333,7 @@ size_t generate_offset(unsigned char *data, size_t data_len, size_t iteration) {
void random_data_change(unsigned char *color_data, unsigned char *width, size_t length, char *message) { void random_data_change(unsigned char *color_data, unsigned char *width, size_t length, char *message) {
int searching = 1; int searching = 1;
int core_count = 24; int core_count = 28;
unsigned int sliding_window = 0; unsigned int sliding_window = 0;
unsigned int compress_data_length = 0; unsigned int compress_data_length = 0;
// Needs to be turned into a variable // Needs to be turned into a variable