Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4.  
  5. #include "error.h"
  6. #include "jpeg_manip.h"
  7.  
  8. #ifdef WIN32
  9. void pause(void)
  10. {
  11. system("pause");
  12. }
  13. #endif
  14.  
  15. /***************************** main() ***********************************
  16. Main function (see help for more details)
  17. ************************************************************************/
  18. int main(int argc, char ** argv)
  19. {
  20. int nbDCT = 0;
  21. int coef = 0;
  22. int i; // Loop variable
  23. int return_value;
  24. JPEGimg *img = NULL;
  25. DCTpos position = { 0 };
  26.  
  27. // To pause the system at exit if run under windows
  28. #ifdef WIN32
  29. atexit(pause);
  30. #endif
  31.  
  32. // Check number of arguments of the command line
  33. if (argc < 3)
  34. {
  35. printf("%s: Reads a jpeg image and write it in a new file\n", argv[0]);
  36. printf("Not enough arguments for %s\n", argv[0]);
  37. printf("Usage: %s <cover.jpg> <copy.jpg>\n", argv[0]);
  38. return EXIT_FAILURE;
  39. }
  40.  
  41. srand((int)time(NULL));
  42.  
  43. // read image
  44. img = jpeg_read(argv[1]);
  45. if (!img)
  46. return EXIT_FAILURE;
  47.  
  48. // print some informations
  49. printf("Number of components: %d\n", img->cinfo.num_components);
  50. for (i = 0; i < img->cinfo.num_components; i++)
  51. {
  52. 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);
  53. //Rajout
  54. nbDCT += img->cinfo.comp_info[i].height_in_blocks * img->cinfo.comp_info[i].width_in_blocks;
  55. }
  56. nbDCT *= 64;
  57. printf("NbDCT = %d\n\n", nbDCT);
  58.  
  59. for (int j = 0; j < img->cinfo.num_components; j++)
  60. {
  61. for (int k=0; k < img->cinfo.comp_info[j].height_in_blocks ; k++)
  62. {
  63. for (int f = 0; f < img->cinfo.comp_info[j].width_in_blocks; f++)
  64. {
  65. for (int i = 0; i < 64; i++)
  66. {
  67. if(img->dctCoeffs[j][k][f][1])
  68. {
  69. img->dctCoeffs[j][k][f][i]++;
  70. coef++;
  71. }
  72. }
  73. }
  74. }
  75. }
  76.  
  77. coef = coef / nbDCT;
  78. //
  79.  
  80. getDCTpos(img->dctCoeffs, &(img->cinfo), 0, &position);
  81. getDCTcoeffValue(img->dctCoeffs, &(img->cinfo), &position, &return_value);
  82. printf("First coefficient (comp 0, lin 0, col 0, coeff 0): %d\n", return_value);
  83.  
  84. // set first coefficient to 0
  85. img->dctCoeffs[2][39][29][0] = 0;
  86.  
  87. // write it in a new file
  88. return_value = jpeg_write_from_coeffs(argv[2], img);
  89. if (return_value == EXIT_SUCCESS)
  90. printf("\nImage written in %s\n", argv[2]);
  91. free_jpeg_img(img);
  92.  
  93. return EXIT_SUCCESS;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement