gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
gl2ppm.cpp
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #include "gl2ppm.h"
7 
8 void create_ppm(FILE *outfile, PixelBuffer *buffer)
9 {
10  if(buffer->getFormat() != GL_RGB || buffer->getType() != GL_UNSIGNED_BYTE) {
11  Msg::Error("PPM only implemented for GL_RGB and GL_UNSIGNED_BYTE");
12  return;
13  }
14 
15  int width = buffer->getWidth();
16  int height = buffer->getHeight();
17  unsigned char *pixels = (unsigned char *)buffer->getPixels();
18 
19  fprintf(outfile, "P6\n");
20  fprintf(outfile, "%d %d\n", width, height);
21  fprintf(outfile, "%d\n", 255);
22 
23  int row_stride = width * 3;
24  int i = height - 1;
25  while(i >= 0) {
26  fwrite(&pixels[i * row_stride], 1, row_stride, outfile);
27  i--;
28  }
29 }
PixelBuffer::getHeight
int getHeight()
Definition: PixelBuffer.h:71
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
PixelBuffer::getFormat
GLenum getFormat()
Definition: PixelBuffer.h:74
PixelBuffer::getType
GLenum getType()
Definition: PixelBuffer.h:75
PixelBuffer::getPixels
void * getPixels()
Definition: PixelBuffer.h:76
PixelBuffer::getWidth
int getWidth()
Definition: PixelBuffer.h:70
gl2ppm.h
create_ppm
void create_ppm(FILE *outfile, PixelBuffer *buffer)
Definition: gl2ppm.cpp:8
PixelBuffer
Definition: PixelBuffer.h:32