Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
- #include "error.h"
- #include "jpeg_manip.h"
- #ifdef WIN32
- void pause(void)
- {
- system("pause");
- }
- #endif
- /***************************** main() ***********************************
- Main function (see help for more details)
- ************************************************************************/
- int main(int argc, char ** argv)
- {
- int nbDCT = 0;
- int coef = 0;
- int i; // Loop variable
- int return_value;
- JPEGimg *img = NULL;
- DCTpos position = { 0 };
- // To pause the system at exit if run under windows
- #ifdef WIN32
- atexit(pause);
- #endif
- // Check number of arguments of the command line
- if (argc < 3)
- {
- printf("%s: Reads a jpeg image and write it in a new file\n", argv[0]);
- printf("Not enough arguments for %s\n", argv[0]);
- printf("Usage: %s <cover.jpg> <copy.jpg>\n", argv[0]);
- return EXIT_FAILURE;
- }
- srand((int)time(NULL));
- // read image
- img = jpeg_read(argv[1]);
- if (!img)
- return EXIT_FAILURE;
- // print some informations
- printf("Number of components: %d\n", img->cinfo.num_components);
- for (i = 0; i < img->cinfo.num_components; i++)
- {
- printf("Component %d:\n %d lines, %d columns\n\n", i, img->cinfo.comp_info[i].height_in_blocks, img->cinfo.comp_info[i].width_in_blocks);
- //Rajout
- nbDCT += img->cinfo.comp_info[i].height_in_blocks * img->cinfo.comp_info[i].width_in_blocks;
- }
- nbDCT *= 64;
- printf("NbDCT = %d\n\n", nbDCT);
- for (int j = 0; j < img->cinfo.num_components; j++)
- {
- for (int k=0; k < img->cinfo.comp_info[j].height_in_blocks ; k++)
- {
- for (int f = 0; f < img->cinfo.comp_info[j].width_in_blocks; f++)
- {
- for (int i = 0; i < 64; i++)
- {
- if(img->dctCoeffs[j][k][f][1])
- {
- img->dctCoeffs[j][k][f][i]++;
- coef++;
- }
- }
- }
- }
- }
- coef = coef / nbDCT;
- //
- getDCTpos(img->dctCoeffs, &(img->cinfo), 0, &position);
- getDCTcoeffValue(img->dctCoeffs, &(img->cinfo), &position, &return_value);
- printf("First coefficient (comp 0, lin 0, col 0, coeff 0): %d\n", return_value);
- // set first coefficient to 0
- img->dctCoeffs[2][39][29][0] = 0;
- // write it in a new file
- return_value = jpeg_write_from_coeffs(argv[2], img);
- if (return_value == EXIT_SUCCESS)
- printf("\nImage written in %s\n", argv[2]);
- free_jpeg_img(img);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement