function [zz] = D35WQ8_zigzag(quant)

    % Fixed block size
    % W = H = 8
    % C = 3

    [N, H, W, C] = size(quant);
    %Only works for square shaped blocks: H = W
    
    batch = N * C;
    % NHWC -> NCHW
    arr = permute(quant, [1, 4, 2, 3]);
    arr = reshape(arr, batch, H*W);
    
    %% WTF slides :D :D :D :D
    % https://uk.mathworks.com/matlabcentral/fileexchange/15335-jpeg-encoder-decoder/content/JPEG%20Encoder%20Decoder/JPEG%20Encoder%20Decoder/jpeg.m
    idxs = uint8([
       1   2   6   7  15  16  28  29;
       3   5   8  14  17  27  30  43;
       4   9  13  18  26  31  42  44;
      10  12  19  25  32  41  45  54;
      11  20  24  33  40  46  53  55;
      21  23  34  39  47  52  56  61;
      22  35  38  48  51  57  60  62;
      36  37  49  50  58  59  63  64]);
  
    idxs_std = uint8([
            1  9  2  3  10 17 25 18;
            11 4  5  12 19 26 33 41;
            34 27 20 13 6  7  14 21;
            28 35 42 49 57 50 43 36;
            29 22 15 8  16 23 30 37;
            44 51 58 59 52 45 38 31; 
            24 32 39 46 53 60 61 54; 
            47 40 48 55 62 63 56 64]);
    

    
    %% reordering
    zz=arr(:, idxs_std(:));
    
end