📄 main.c
字号:
else if (cmd->colorSpace == SS_YUV){
if (arguments[3][i]=='y')
cmd->c1_flag = SS_ATTACK;
else if (arguments[3][i]=='u')
cmd->c2_flag = SS_ATTACK;
else if (arguments[3][i]=='v')
cmd->c3_flag = SS_ATTACK;
else {
fprintf(stderr,"ERROR: Channel %c does not belong to color space!\n",arguments[3][i]);
printUsage();
exit(1);
}
}
else if (cmd->colorSpace == SS_HSV) {
if (arguments[3][i]=='h')
cmd->c1_flag = SS_ATTACK;
else if (arguments[3][i]=='s')
cmd->c2_flag = SS_ATTACK;
else if (arguments[3][i]=='v')
cmd->c3_flag = SS_ATTACK;
else {
fprintf(stderr,"ERROR: Channel %c does not belong to color space!\n",arguments[3][i]);
printUsage();
exit(1);
}
}
else if (cmd->colorSpace == SS_LAB) {
if (arguments[3][i]=='l')
cmd->c1_flag = SS_ATTACK;
else if (arguments[3][i]=='a')
cmd->c2_flag = SS_ATTACK;
else if (arguments[3][i]=='b')
cmd->c3_flag = SS_ATTACK;
else {
fprintf(stderr,"ERROR: Channel %c does not belong to color space!\n",arguments[3][i]);
printUsage();
exit(1);
}
}
else if (cmd->colorSpace == SS_XYZ) {
if (arguments[3][i]=='x')
cmd->c1_flag = SS_ATTACK;
else if (arguments[3][i]=='y')
cmd->c2_flag = SS_ATTACK;
else if (arguments[3][i]=='z')
cmd->c3_flag = SS_ATTACK;
else {
fprintf(stderr,"ERROR: Channel %c does not belong to color space!\n",arguments[3][i]);
printUsage();
exit(1);
}
}
}
}
/* Check the fourth argument */
if (arguments[4][0]=='x')
/* Exchange the colour channel of original and watermarked image */
cmd->type = SS_SWITCH;
else if (arguments[4][0]=='s')
/* Dewatermarking by swappping in the spatial domain */
cmd->type = SS_SPATIAL;
else if (arguments[4][0]=='h'){
/* Dewatermarking by swappping in the wavelet domain */
/* To be implemented and tested */
/* cmd->type = WAVELET; */
fprintf(stderr,"ERROR: Wavelet not supported yet\n");
printUsage();
exit(1);
}
else {
fprintf(stderr,"ERROR: Wrong fourth argument\n");
printUsage();
exit(1);
}
/* Check the fifth argument if necessary */
if (cmd->type != SS_SWITCH){
if (argNumber != 6){
fprintf(stderr, "ERROR: Fifth argument mandatory in this mode\n");
printUsage();
exit(1);
}
cmd->percent = atoi(arguments[5]);
if (cmd->percent>100 || cmd->percent<0){
fprintf(stderr, "ERROR: Fifth argument should be between 0 and 100\n");
printUsage();
exit(1);
}
}
}
/*--------------------------------------------------------------------------------*
| Main function. |
*--------------------------------------------------------------------------------*/
extern int findAdaptativeThreshold(float *array, long numSample, int percent);
int main(int argc,char **argv)
{
optionsCmd commandLine;
char *attackFile;
int w_orig, h_orig; /* Size of the original image */
int w_water, h_water; /* Size of the watermarked image */
image *R_orig, *G_orig, *B_orig; /* RGB components of original image */
image *R_water, *G_water, *B_water; /* RGB components of watermarked image */
image *channel1_orig, *channel2_orig, *channel3_orig;
image *channel1_water, *channel2_water, *channel3_water;
image *R_sup, *G_sup, *B_sup; /* RGB support */
image *channel1_sup, *channel2_sup, *channel3_sup;
int maxRGB, i;
/* Analyze the command line */
analyzeCmd(argc, argv, &commandLine);
printVersion();
/* Import original file */
printf("Reading image providing IFS codebook...\n");
if (ReadPPM(commandLine.origFile, &w_orig, &h_orig, &maxRGB, &R_orig, &G_orig, &B_orig)==0){
fprintf(stderr,"ERROR: File reading error!\n");
printUsage();
exit(1);
}
if (maxRGB!=255)
ExpandLevels(R_orig, G_orig, B_orig, w_orig*h_orig, maxRGB);
/* Import watermarked image */
printf("Reading watermarked image to be attacked...\n");
if (ReadPPM(commandLine.waterFile, &w_water, &h_water, &maxRGB, &R_water, &G_water, &B_water)==0){
fprintf(stderr,"ERROR: File reading error!\n");
printUsage();
exit(1);
}
if (maxRGB!=255)
ExpandLevels(R_water, G_water, B_water, w_water*h_water,maxRGB);
/* Check the size of the images */
if (w_orig!=w_water || h_orig!=h_water){
fprintf(stderr,"ERROR: Images with different sizes\n");
exit(1);
}
/******************************************************************************/
/* Colorspace conversion if necessary */
convertRGB2Channel(R_orig, G_orig, B_orig, &channel1_orig, &channel2_orig,
&channel3_orig, w_orig, h_orig, commandLine.colorSpace);
convertRGB2Channel(R_water, G_water, B_water, &channel1_water, &channel2_water,
&channel3_water, w_water, h_water, commandLine.colorSpace);
/* Free memory */
free(R_orig);free(B_orig);free(G_orig);
free(R_water);free(G_water);free(B_water);
/* Attack channel 1 if necessary */
if((channel1_sup = (image *)malloc(sizeof(image) * w_orig * h_orig))==NULL) {
fprintf(stderr,"ERROR: Memory allocation problem!\n");
exit(1);
}
if (commandLine.c1_flag == SS_ATTACK){
printf("Channel 1:\n");
attackChannel(channel1_orig, channel1_water, channel1_sup, w_water, h_water, &commandLine);
}
else {
printf("Channel 1: Untouched.\n");
for (i=0;i<w_water*h_water;i++)
channel1_sup[i] = channel1_water[i];
}
free(channel1_orig);free(channel1_water);
/* Attack channel 2 if necessary */
if((channel2_sup = (image *)malloc(sizeof(image) * w_orig * h_orig))==NULL) {
fprintf(stderr,"ERROR: Memory allocation problem!\n");
exit(1);
}
if (commandLine.c2_flag == SS_ATTACK){
printf("Channel 2:\n");
attackChannel(channel2_orig, channel2_water, channel2_sup, w_water, h_water, &commandLine);
}
else {
printf("Channel 2: Untouched.\n");
for (i=0;i<w_water*h_water;i++)
channel2_sup[i] = channel2_water[i];
}
free(channel2_orig);free(channel2_water);
/* Attack channel 3 if necessary */
if((channel3_sup = (image *)malloc(sizeof(image) * w_orig * h_orig))==NULL) {
fprintf(stderr,"ERROR: Memory allocation problem!\n");
exit(1);
}
if (commandLine.c3_flag == SS_ATTACK){
printf("Channel 3:\n");
attackChannel(channel3_orig, channel3_water, channel3_sup, w_water, h_water, &commandLine);
}
else {
printf("Channel 3: Untouched.\n");
for (i=0;i<w_water*h_water;i++)
channel3_sup[i] = channel3_water[i];
}
free(channel3_orig);free(channel3_water);
/* Colorspace conversion if necessary */
convertChannel2RGB(channel1_sup, channel2_sup, channel3_sup, &R_sup,
&G_sup, &B_sup, w_water, h_water, commandLine.colorSpace);
/* Free memory */
free(channel1_sup);free(channel2_sup);free(channel3_sup);
/******************************************************************************/
/* Save output */
attackFile = (char *)malloc(sizeof(char)*(strlen(commandLine.waterFile)+strlen("_attack")+1));
strcpy(attackFile, commandLine.waterFile);
attackFile[strlen(commandLine.waterFile)-4] = 0;
strcat(attackFile, "_attack.ppm");
printf("Saving attacked image in \"%s\"\n",attackFile);
WritePPM(attackFile, w_orig, h_orig, 255, R_sup, G_sup, B_sup);
/* Fre memory */
free(attackFile);
free(R_sup);free(G_sup);free(B_sup);
free(commandLine.origFile);
free(commandLine.waterFile);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -