Permalink
Browse files

png: added PNG_COLOR_TYPE_*

  • Loading branch information...
lvv committed Jan 15, 2011
1 parent 0f1af41 commit 771fdd3b6c8a1819b78d5dce73e3722e72407056
Showing with 30 additions and 17 deletions.
  1. +12 −2 png.h
  2. +18 −15 t-png.cc
14 png.h
@@ -13,6 +13,13 @@
#include <lvv/array.h>
using lvv::array;
// possible tipes:
// PNG_COLOR_TYPE_GRAY
// PNG_COLOR_TYPE_PALETTE
// PNG_COLOR_TYPE_RGB
// PNG_COLOR_TYPE_RGB_ALPHA
// PNG_COLOR_TYPE_GRAY_ALPHA
namespace lvv {
@@ -27,10 +34,10 @@
template <int height, int width, int channel=4> static
template <int height, int width, int channel=4, int PNG_TYPE=PNG_COLOR_TYPE_RGB_ALPHA, typename T=uint8_t> static
void array2png (const char* file_name, uint8_t* A) {
png_byte color_type = PNG_COLOR_TYPE_RGB_ALPHA;
png_byte color_type = PNG_TYPE;
png_byte bit_depth = 8;
png_structp png_ptr;
@@ -73,6 +80,9 @@ void array2png (const char* file_name, uint8_t* A) {
template <typename T, int H, int W, int CH=4> static
void array2png ( const char* file_name, array<array<array<T,CH>,W>,H>& A ) { array2png<H,W,CH> (file_name, &A[0][0][0]); }
template <typename T, int H, int W> static
void array2png ( const char* file_name, array<array<array<T,3>,W>,H>& A ) { array2png<H,W,3,PNG_COLOR_TYPE_RGB> (file_name, &A[0][0][0]); }
}; // namespace lvv
@@ -6,24 +6,27 @@ int main() {
const int W = 200;
const int H = 200;
const int CH = 4;
array<array<array<uint8_t,CH>,W>,H> A; A = 255;
for (int r = 0; r<H; r++) {
A[r][r][0] = 0;
A[r][r][1] = 0;
A[r][r][2] = 0;
// A: lvv::array
{
const int CH = 3;
array<array<array<uint8_t,CH>,W>,H> A; A = 255;
for (int r = 0; r<H; r++) A[r][r] = 0;
array2png ("t-a.png", A);
}
array<uint8_t, W*H*CH> B;
B = 255;
for (int r = 0; r<H; r++) {
B[r*W*CH + r*CH+0] = 0;
B[r*W*CH + r*CH+1] = 0;
B[r*W*CH + r*CH+2] = 0;
// B: C-array
{
const int CH = 3;
array<uint8_t, W*H*CH> B; B = 255;
for (int r = 0; r<H; r++) {
B[r*W*CH + r*CH+0] = 0;
B[r*W*CH + r*CH+1] = 0;
B[r*W*CH + r*CH+2] = 0;
}
array2png <H,W,CH,PNG_COLOR_TYPE_RGB> ("t-b.png", &B[0]);
}
array2png ("t-a.png", A);
array2png <H,W,CH> ("t-b.png", &B[0]);
}

0 comments on commit 771fdd3

Please sign in to comment.