Browse Source

gcc warnings

pull/2/head
Odilitime 5 years ago
parent
commit
8852c0eba0
  1. 49
      src/pnm.cpp
  2. 2
      src/pnm.h

49
src/pnm.cpp

@ -1,5 +1,7 @@ @@ -1,5 +1,7 @@
#include "pnm.h"
#include <iostream>
#include <stdio.h>
#include <string.h>
// pnm
// The PNM format is just an abstraction of the PBM, PGM, and PPM formats. I.e. the name "PNM" refers collectively to PBM, PGM, and PPM.
@ -16,7 +18,8 @@ RGBAPNMObject * readPPM(const char* fileName) { @@ -16,7 +18,8 @@ RGBAPNMObject * readPPM(const char* fileName) {
// formatted read of header
char fileType[11];
fscanf(fr, "%9s", fileType);
int res=0;
res = fscanf(fr, "%9s", fileType);
data->magicNum=fileType;
std::cout << "fileType:" << fileType << std::endl;
@ -37,7 +40,7 @@ RGBAPNMObject * readPPM(const char* fileName) { @@ -37,7 +40,7 @@ RGBAPNMObject * readPPM(const char* fileName) {
// read the rest of header
unsigned int width, height;
fscanf(fr, "%u\n %u\n", &width, &height);
res = fscanf(fr, "%u\n %u\n", &width, &height);
data->width = width;
data->height = height;
@ -46,10 +49,10 @@ RGBAPNMObject * readPPM(const char* fileName) { @@ -46,10 +49,10 @@ RGBAPNMObject * readPPM(const char* fileName) {
data->maxColVal = 255; // just set a default
if (bits != 1) {
unsigned int maximum;
fscanf(fr, "%u\n", &maximum);
res = fscanf(fr, "%u\n", &maximum);
data->maxColVal = height;
}
int size = width * height;
unsigned int size = width * height;
if (bits != 1) {
size *= bits/8;
}
@ -58,7 +61,7 @@ RGBAPNMObject * readPPM(const char* fileName) { @@ -58,7 +61,7 @@ RGBAPNMObject * readPPM(const char* fileName) {
char* pixels = new char[size];
// unformatted read of binary pixel data
fread(pixels, sizeof(int), size, fr);
res = fread(pixels, sizeof(int), size, fr);
data->m_Ptr = pixels;
// close file
@ -71,14 +74,15 @@ RGBAPNMObject * readPPM(const char* fileName) { @@ -71,14 +74,15 @@ RGBAPNMObject * readPPM(const char* fileName) {
void writePBM4(const char *filename, const RGBAPNMObject &data) {
FILE *fp = fopen(filename, "wb"); /* b - binary mode */
fprintf(fp, "P6\n%d %d\n255\n", data.width, data.height);
for (int j = 0; j < data.height; ++j) {
for (int i = 0; i < data.width; ++i) {
for (unsigned int j = 0; j < data.height; ++j) {
for (unsigned int i = 0; i < data.width; ++i) {
static unsigned char color[1];
unsigned int pos = ((i * 4) + (j * 4 * 1024));
//color[0] = data.m_Ptr[pos + 0]; /* red */
//color[1] = data.m_Ptr[pos + 1]; /* green */
//color[2] = data.m_Ptr[pos + 2]; /* blue */
color[0] = data.m_Ptr[pos + 3]; /* alpha */
color[0] = static_cast<unsigned char>(data.m_Ptr[pos + 3]); /*
alpha */
fwrite(color, 1, 1, fp);
}
}
@ -88,11 +92,12 @@ void writePBM4(const char *filename, const RGBAPNMObject &data) { @@ -88,11 +92,12 @@ void writePBM4(const char *filename, const RGBAPNMObject &data) {
void writePGM5(const char *filename, const RGBAPNMObject &data) {
FILE *fp = fopen(filename, "wb"); /* b - binary mode */
fprintf(fp, "P5\n%d %d\n255\n", data.width, data.height);
for (int j = 0; j < data.height; ++j) {
for (int i = 0; i < data.width; ++i) {
for (unsigned int j = 0; j < data.height; ++j) {
for (unsigned int i = 0; i < data.width; ++i) {
static unsigned char color[1];
unsigned int pos = ((i * 4) + (j * 4 * 1024));
color[0] = data.m_Ptr[pos + 0]; /* red */
color[0] = static_cast<unsigned char>(data.m_Ptr[pos + 0]); /* red
*/
//color[1] = data.m_Ptr[pos + 1]; /* green */
//color[2] = data.m_Ptr[pos + 2]; /* blue */
//color[3] = data.m_Ptr[pos + 3]; /* alpha */
@ -105,13 +110,13 @@ void writePGM5(const char *filename, const RGBAPNMObject &data) { @@ -105,13 +110,13 @@ void writePGM5(const char *filename, const RGBAPNMObject &data) {
void writePPM6(const char *filename, const RGBAPNMObject &data) {
FILE *fp = fopen(filename, "wb"); /* b - binary mode */
fprintf(fp, "P6\n%d %d\n255\n", data.width, data.height);
for (int j = 0; j < data.height; ++j) {
for (int i = 0; i < data.width; ++i) {
for (unsigned int j = 0; j < data.height; ++j) {
for (unsigned int i = 0; i < data.width; ++i) {
static unsigned char color[3];
unsigned int pos = ((i * 4) + (j * 4 * 1024));
color[0] = data.m_Ptr[pos + 0]; /* red */
color[1] = data.m_Ptr[pos + 1]; /* green */
color[2] = data.m_Ptr[pos + 2]; /* blue */
color[0] = static_cast<unsigned char>(data.m_Ptr[pos + 0]); /* red */
color[1] = static_cast<unsigned char>(data.m_Ptr[pos + 1]); /* green */
color[2] = static_cast<unsigned char>(data.m_Ptr[pos + 2]); /* blue */
//color[3] = data.m_Ptr[pos + 3]; /* alpha */
fwrite(color, 1, 3, fp);
}
@ -122,14 +127,14 @@ void writePPM6(const char *filename, const RGBAPNMObject &data) { @@ -122,14 +127,14 @@ void writePPM6(const char *filename, const RGBAPNMObject &data) {
void writePPM8(const char *filename, const RGBAPNMObject &data) {
FILE *fp = fopen(filename, "wb"); /* b - binary mode */
fprintf(fp, "P8\n%d %d\n255\n", data.width, data.height);
for (int j = 0; j < data.height; ++j) {
for (int i = 0; i < data.width; ++i) {
for (unsigned int j = 0; j < data.height; ++j) {
for (unsigned int i = 0; i < data.width; ++i) {
static unsigned char color[4];
unsigned int pos = ((i * 4) + (j * 4 * 1024));
color[0] = data.m_Ptr[pos + 0]; /* red */
color[1] = data.m_Ptr[pos + 1]; /* green */
color[2] = data.m_Ptr[pos + 2]; /* blue */
color[3] = data.m_Ptr[pos + 3]; /* alpha */
color[0] = static_cast<unsigned char>(data.m_Ptr[pos + 0]); /* red */
color[1] = static_cast<unsigned char>(data.m_Ptr[pos + 1]); /* green */
color[2] = static_cast<unsigned char>(data.m_Ptr[pos + 2]); /* blue */
color[3] = static_cast<unsigned char>(data.m_Ptr[pos + 3]); /* alpha */
fwrite(color, 1, 4, fp);
}
}

2
src/pnm.h

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
// this structure expects RGBA
struct RGBAPNMObject {
std::string magicNum;
int width, height, maxColVal;
unsigned int width, height, maxColVal;
char * m_Ptr;
};

Loading…
Cancel
Save