Browse Source

Fixed jpg. Added a basic image for testing colors

master
Joshua Moerman 12 years ago
parent
commit
446dc14daf
  1. 4
      ImageStreams.xcodeproj/project.pbxproj
  2. 16
      ImageStreams/jpg.hpp
  3. 46
      ImageStreams/main.cpp

4
ImageStreams.xcodeproj/project.pbxproj

@ -10,6 +10,7 @@
4263431015FA676F00977AF9 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4263430F15FA676F00977AF9 /* main.cpp */; }; 4263431015FA676F00977AF9 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4263430F15FA676F00977AF9 /* main.cpp */; };
4263431215FA676F00977AF9 /* ImageStreams.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4263431115FA676F00977AF9 /* ImageStreams.1 */; }; 4263431215FA676F00977AF9 /* ImageStreams.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4263431115FA676F00977AF9 /* ImageStreams.1 */; };
4263431C15FA6A3200977AF9 /* libpng.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4263431B15FA6A3200977AF9 /* libpng.framework */; }; 4263431C15FA6A3200977AF9 /* libpng.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4263431B15FA6A3200977AF9 /* libpng.framework */; };
4263431F1604CA3900977AF9 /* libjpeg.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4263431E1604CA3900977AF9 /* libjpeg.a */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
@ -34,6 +35,7 @@
4263431A15FA686300977AF9 /* basics.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = basics.hpp; sourceTree = "<group>"; }; 4263431A15FA686300977AF9 /* basics.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = basics.hpp; sourceTree = "<group>"; };
4263431B15FA6A3200977AF9 /* libpng.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = libpng.framework; path = Library/Frameworks/libpng.framework; sourceTree = SDKROOT; }; 4263431B15FA6A3200977AF9 /* libpng.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = libpng.framework; path = Library/Frameworks/libpng.framework; sourceTree = SDKROOT; };
4263431D1604A79F00977AF9 /* jpg.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = jpg.hpp; sourceTree = "<group>"; }; 4263431D1604A79F00977AF9 /* jpg.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = jpg.hpp; sourceTree = "<group>"; };
4263431E1604CA3900977AF9 /* libjpeg.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libjpeg.a; path = ../../../../../usr/local/lib/libjpeg.a; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -42,6 +44,7 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
4263431C15FA6A3200977AF9 /* libpng.framework in Frameworks */, 4263431C15FA6A3200977AF9 /* libpng.framework in Frameworks */,
4263431F1604CA3900977AF9 /* libjpeg.a in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -51,6 +54,7 @@
4263430015FA676F00977AF9 = { 4263430015FA676F00977AF9 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
4263431E1604CA3900977AF9 /* libjpeg.a */,
4263431B15FA6A3200977AF9 /* libpng.framework */, 4263431B15FA6A3200977AF9 /* libpng.framework */,
4263430E15FA676F00977AF9 /* ImageStreams */, 4263430E15FA676F00977AF9 /* ImageStreams */,
4263430C15FA676F00977AF9 /* Products */, 4263430C15FA676F00977AF9 /* Products */,

16
ImageStreams/jpg.hpp

@ -21,6 +21,15 @@
*/ */
namespace jpg{ namespace jpg{
template <typename P>
J_COLOR_SPACE color_space(){
int num_colors = pixel_formats::traits<P>::num_colors;
switch (num_colors) {
case 1: return JCS_GRAYSCALE;
case 3: return JCS_RGB;
default: return JCS_UNKNOWN;
}
}
template <typename P = pixel_formats::rgb> template <typename P = pixel_formats::rgb>
struct ostream{ struct ostream{
@ -47,10 +56,10 @@ namespace jpg{
cinfo.image_width = width; cinfo.image_width = width;
cinfo.image_height = height; cinfo.image_height = height;
cinfo.input_components = pixel_formats::traits<pixel>::num_colors; cinfo.input_components = pixel_formats::traits<pixel>::num_colors;
//cinfo.in_color_space = JCS_RGB; // or JCS_GRAYSCALE, will be set in jpeg_set_defaults() cinfo.in_color_space = color_space<pixel>();
jpeg_set_defaults(&cinfo); jpeg_set_defaults(&cinfo);
//jpeg_set_quality(&cinfo, 75, true); // quality in [0, 100], boolean indicates "force_baseline" (only matters when quality < 25) jpeg_set_quality(&cinfo, 95, true); // quality in [0, 100], boolean indicates "force_baseline" (only matters when quality < 25)
jpeg_start_compress(&cinfo, true); // true means we will write completely jpeg_start_compress(&cinfo, true); // true means we will write completely
} }
@ -65,7 +74,8 @@ namespace jpg{
++x; ++x;
if(x >= row.size()){ if(x >= row.size()){
// this will return the number of scanlines written // this will return the number of scanlines written
jpeg_write_scanlines(&cinfo, reinterpret_cast<unsigned char const*>(row.data()), 1); unsigned char * ptr = reinterpret_cast<unsigned char *>(row.data());
jpeg_write_scanlines(&cinfo, &ptr, 1);
x = 0; x = 0;
} }

46
ImageStreams/main.cpp

@ -10,12 +10,21 @@
#include "png.hpp" #include "png.hpp"
#include "bmp.hpp" #include "bmp.hpp"
#include "jpg.hpp"
#include "basics.hpp" #include "basics.hpp"
#include <cmath> #include <cmath>
#include <vector> #include <vector>
#include <array>
#include <algorithm> #include <algorithm>
template <typename ImageType>
void basic_colors(std::string filename) {
ImageType image(8, 1, filename);
std::array<double, 2> v = {0.0, 1.0};
for(auto b : v) for(auto g : v) for(auto r : v) image << typename ImageType::pixel(r,g,b);
}
template <typename ImageType> template <typename ImageType>
void xor_color(std::string filename){ void xor_color(std::string filename){
size_t size = 512; size_t size = 512;
@ -142,25 +151,22 @@ void mandelbrot(std::string filename) {
} }
int main(int argc, const char * argv[]){ int main(int argc, const char * argv[]){
xor_color<png::colored_ostream>("xor_color.png"); #define test(fun, kind) \
xor_color<bmp::colored_ostream>("xor_color.bmp"); std::cout << "Testing " #fun << std::endl; \
fun<png::kind ## _ostream>(#fun ".png"); \
xor_grad<png::gray_ostream>("xor_grad.png"); fun<bmp::kind ## _ostream>(#fun ".bmp"); \
xor_grad<bmp::gray_ostream>("xor_grad.bmp"); fun<jpg::kind ## _ostream>(#fun ".jpg")
noise<png::gray_ostream>("noise.png"); test(basic_colors, colored);
noise<bmp::gray_ostream>("noise.bmp"); test(xor_color, colored);
test(logistic, colored);
automata<png::gray_ostream>("automata.png"); test(logistic2, colored);
automata<bmp::gray_ostream>("automata.bmp");
test(noise, gray);
logistic<png::colored_ostream>("logistic.png"); test(xor_grad, gray);
logistic<bmp::colored_ostream>("logistic.bmp"); test(automata, gray);
test(mandelbrot, gray);
logistic2<png::colored_ostream>("logistic2.png");
logistic2<bmp::colored_ostream>("logistic2.bmp"); #undef test
mandelbrot<png::gray_ostream>("mandelbrot.png");
mandelbrot<bmp::gray_ostream>("mandelbrot.bmp");
} }