fork(6) download
  1. #define NEW_ALGO
  2. using System;
  3.  
  4.  
  5. public class Test
  6. {
  7. private static void printArray(byte[] arr, int w, int h) {
  8. for (int i = 0; i < h; ++i)
  9. {
  10. for (int j = 0; j < w; ++j)
  11. Console.Write("{0} ", arr[i*w + j]);
  12. Console.WriteLine("");
  13. }
  14. }
  15.  
  16. public static void Main()
  17. {
  18. int origWidth = 5;
  19. int origHeight = 10;
  20. byte[] srcData = new byte[origWidth * origHeight];
  21. for (int ii = 0; ii < origWidth*origHeight; ++ii)
  22. srcData[ii] = (byte)ii;
  23. Console.WriteLine("Original");
  24. printArray(srcData, origWidth, origHeight);
  25.  
  26. // find max scale value
  27. int scale = 3; // NOTE: temporary
  28.  
  29. // create new byte array to store new image
  30. int width = origWidth * scale;
  31. int height = origHeight * scale;
  32. int stride = width;
  33. byte[] trgData = new byte[height * stride];
  34.  
  35. // update the progress bar
  36. // progressBar1.Value = 10;
  37.  
  38. #if NEW_ALGO
  39. int targetIdx = 0;
  40. for (int i = 0; i < height; ++i)
  41. {
  42. int iUnscaled = i / scale;
  43. for (int j = 0; j < width; ++j) {
  44. int jUnscaled = j / scale;
  45. trgData[targetIdx++] = srcData[iUnscaled * origWidth + jUnscaled];
  46. }
  47. }
  48. #else
  49. // OLD ALGORITHM
  50. int i = -1; // index for src data
  51. // copy pixel data
  52.  
  53. // for (int i = 0; i < )
  54. for (int n = 0; n < trgData.Length; n++)
  55. {
  56. if (n % stride == 0)
  57. {
  58. i++;
  59. }
  60. trgData[n] = srcData[i];
  61. }
  62. #endif
  63.  
  64. Console.WriteLine("\nScaled");
  65. printArray(trgData, width, height);
  66.  
  67.  
  68.  
  69. // your code goes here
  70. }
  71. }
Success #stdin #stdout 0.04s 34000KB
stdin
Standard input is empty
stdout
Original
0 1 2 3 4 
5 6 7 8 9 
10 11 12 13 14 
15 16 17 18 19 
20 21 22 23 24 
25 26 27 28 29 
30 31 32 33 34 
35 36 37 38 39 
40 41 42 43 44 
45 46 47 48 49 

Scaled
0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 
0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 
0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 
5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 
5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 
5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 
10 10 10 11 11 11 12 12 12 13 13 13 14 14 14 
10 10 10 11 11 11 12 12 12 13 13 13 14 14 14 
10 10 10 11 11 11 12 12 12 13 13 13 14 14 14 
15 15 15 16 16 16 17 17 17 18 18 18 19 19 19 
15 15 15 16 16 16 17 17 17 18 18 18 19 19 19 
15 15 15 16 16 16 17 17 17 18 18 18 19 19 19 
20 20 20 21 21 21 22 22 22 23 23 23 24 24 24 
20 20 20 21 21 21 22 22 22 23 23 23 24 24 24 
20 20 20 21 21 21 22 22 22 23 23 23 24 24 24 
25 25 25 26 26 26 27 27 27 28 28 28 29 29 29 
25 25 25 26 26 26 27 27 27 28 28 28 29 29 29 
25 25 25 26 26 26 27 27 27 28 28 28 29 29 29 
30 30 30 31 31 31 32 32 32 33 33 33 34 34 34 
30 30 30 31 31 31 32 32 32 33 33 33 34 34 34 
30 30 30 31 31 31 32 32 32 33 33 33 34 34 34 
35 35 35 36 36 36 37 37 37 38 38 38 39 39 39 
35 35 35 36 36 36 37 37 37 38 38 38 39 39 39 
35 35 35 36 36 36 37 37 37 38 38 38 39 39 39 
40 40 40 41 41 41 42 42 42 43 43 43 44 44 44 
40 40 40 41 41 41 42 42 42 43 43 43 44 44 44 
40 40 40 41 41 41 42 42 42 43 43 43 44 44 44 
45 45 45 46 46 46 47 47 47 48 48 48 49 49 49 
45 45 45 46 46 46 47 47 47 48 48 48 49 49 49 
45 45 45 46 46 46 47 47 47 48 48 48 49 49 49