Advertisement
DragonOsman

resize.c pseudocode

Nov 2nd, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.38 KB | None | 0 0
  1. /**
  2. * Pseudo code for resize.c  
  3. * Program to enlarge a BMP image by factor of n (number passed in as argument to program when running it).
  4. * begin main
  5. *     if argc is not equal to 4
  6. *         print out message for correct usage
  7. *         return 1 for error
  8. *     end if
  9. *     store filename of input file (argv[2]) in variable of type char *
  10. *     store filename of output file (argv[3]) in another variable of type char *
  11. *     create a variable of type int and store in it the return value of atoi() with
  12. *     argv[1] passed into it (this is the number, n, which will be used as the factor to resize the image by).
  13. *     if the value of n is not between 1 and 100 (inclusive)
  14. *         print out an error message
  15. *         return 2 for error
  16. *     end if
  17. *     declare file pointer variable and store the name of the input file in it, and try to open file for reading
  18. *     if the file couldn't be opened (and file pointer is NULL)
  19. *         print out error message
  20. *         return 3 for error
  21. *     end if
  22. *     try to open the output file for writing, declared as a file pointer variable
  23. *     if the file couldn't be opened (and file pointer is NULL)
  24. *         print out error message
  25. *         return 4 for error
  26. *     read input file's BITMAPFILEHEADER, after declaring a variable of type BITMAPFILEHEADER
  27. *     read input file's BITMAPINFOHEADER, after declaring a variable of type BITMAPINFOHEADER
  28. *     if BMP file is not a 24-bit uncompressed BMP 4.0 (likely)
  29. *         close input file
  30. *         close outtput file
  31. *         print error message
  32. *         return 4 for error
  33. *     end if
  34. *     remember the input file's padding, storing it an integer variable named padding (be sure to calculate it correctly)
  35. *     remember original image's dimensions as integer variables img_width and img_height
  36. *     calculate resized image's dimensions by multiplying original by factor of n
  37. *     calculate resized image's padding
  38. *     update the header info for the resized image, calculating the new bfSize and biSizeImage
  39. *     write outfiles BITMAPFILEHEADER and BITMAPINFOHEADER using fwrite
  40. *     iterate over input file's scanlines in a for loop, going from 0 until the height of the original image - 1
  41. *         iterate over pixels in scanline in an inner for loop, going from 0 to the width of the orignal image - 1 to resize horizontally
  42. *             declare RGBTRIPLE variabl for temporary storage
  43. *             read into storage from input file
  44. *             for 0 to n - 1 times
  45. *                 write into output file the RGBTRIPLE data, by as many bytes as RGBTRIPLE, one byte on each iteration
  46. *             end for
  47. *         for 0 to output file scanline padding
  48. *             put in a 0 for the padding
  49. *         end for
  50. *         skip over input file padding
  51. *         for 0 to original image width, iterate over the image's width to resize vertically
  52. *             create another temporary storage place RGBTRIPLEs
  53. *             read triples data from input file and store it
  54. *             for 0 to as many times as the original image's height
  55. *                 write into output file the RGBTRIPLE data, by as many bytes as RGBTRIPLE, one byte on each iteration
  56. *             end for
  57. *         end for
  58. *         rewind cursor by size of the input file padding
  59. *        end for
  60. *     end for
  61. *     close input file
  62. *     close output file
  63. *     return 0 for success
  64. * end main
  65. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement