TinyJPEG mat alignment - Serbipunk/notes GitHub Wiki

测试出,该data数组为<h, w, ch>排列,ch的含义为rgb的数组。

#include <iostream>

#define TJE_IMPLEMENTATION
#include "tiny_jpeg.h"

int main() {
  const int cols=640; const int rows=360; const int chs=3;
  unsigned char mat[cols*rows*chs];

  // canvas
  for(int ch=0; ch<chs; ++ch) {
    for(int h=0; h<rows; ++h) {
      for(int w=0; w<cols; ++w) {
         mat[(ch*rows+h)*cols+w] = (unsigned char)0;
      }
    }
  }
  // paint
  for(int h=0; h<rows; ++h) {
    for(int w=0; w<cols; ++w) {
       // mat[(h*cols+w)*3+0] = (unsigned char)255;   // r
       mat[(h*cols+w)*3+1] = (unsigned char)255;   // g
       // mat[(h*cols+w)*3+2] = (unsigned char)255;   // b
    }
  }

  //
  for(int h=200; h<220; ++h) {
    for(int w=0; w<cols; ++w) {
      mat[(h*cols+w)*3+1] = (unsigned char)0;   // black belt
    }
  }
  

  if ( !tje_encode_to_file("out.jpg", cols, rows, chs, mat) ) {
    fprintf(stderr, "Could not write JPEG\n");
    return EXIT_FAILURE;
  }

  return 0;
}
⚠️ **GitHub.com Fallback** ⚠️