Skip to content

Commit

Permalink
Fixed bug in writeRaw method, made components part of constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
acaudwell committed May 21, 2012
1 parent 36ea092 commit ddb0eb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions tga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

#include "tga.h"

TGAWriter::TGAWriter() {
TGAWriter::TGAWriter(int components)
: components(components) {
rle = true;
components = 3;
out = 0;

rle_count = 0;
Expand All @@ -55,6 +55,8 @@ void TGAWriter::writeRaw(std::vector<char>& buffer, int start, int pixel_count)

raw_count += pixel_count;

int written = 0;

while(pixel_count > 0) {
int write_count = std::min(128, pixel_count);

Expand All @@ -63,10 +65,11 @@ void TGAWriter::writeRaw(std::vector<char>& buffer, int start, int pixel_count)
out->write((char*)&counter_byte, 1);

for(int i=0; i < write_count; i++) {
out->write(&(buffer[start+i*components]), components);
out->write(&(buffer[start+(i+written)*components]), components);
}

pixel_count -= write_count;
written += write_count;
}
}

Expand Down Expand Up @@ -96,7 +99,7 @@ void TGAWriter::screenshot(const std::string& filename) {
if(!open(filename)) return;

std::vector<char> buffer;
buffer.resize(display.width * display.height * components * 4);
buffer.resize(display.width * display.height * components);

capture(buffer);
writeTGA(buffer);
Expand Down
2 changes: 1 addition & 1 deletion tga.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TGAWriter {
void init();

public:
TGAWriter();
TGAWriter(int components = 3);

bool open(const std::string& filename);
void close();
Expand Down

0 comments on commit ddb0eb6

Please sign in to comment.