-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjpg_imagen.cpp
102 lines (73 loc) · 2.22 KB
/
jpg_imagen.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdlib.h>
#include <string>
#include <iostream>
#include "jpg_imagen.hpp"
#include "jpg_readwrite.hpp"
namespace jpg
{
//**********************************************************************
//
// constructor: crea imagen, cargándola de un archivo JPG
Imagen::Imagen( const std::string & nombreArchivo )
{
using namespace std ;
// incializar la imagen a la imagen nula
buf = NULL ;
w = 0 ;
h = 0 ;
//cout << "cargando archivo jpeg '" << nombreArchivo << "' .... " << flush ;
buf = JpegFile::JpegFileToRGB( nombreArchivo.c_str(), &w, &h ) ;
if (buf == NULL)
{ std::cout << "error al cargar imagen (vea stderr para detalles)" << std::endl << std::flush ;
exit(1);
}
//cout << " hecho." << endl << flush ;
}
//**********************************************************************
unsigned char * Imagen::leerPixels()
{
return buf ;
}
//**********************************************************************
unsigned char * Imagen::leerPixel( unsigned ix, unsigned iy )
{
return buf + (unsigned long)3*( (unsigned long)w*(unsigned long)iy + (unsigned long)ix );
}
//**********************************************************************
unsigned long Imagen::tamX() const
{
return w ;
}
//**********************************************************************
unsigned long Imagen::tamY() const
{
return h ;
}
//**********************************************************************
void Imagen::escribirEn( const std::string & nombreArchivo )
{
/**
static BOOL RGBToJpegFile(CString fileName, // path
unsigned char *dataBuf, // RGB buffer
UINT width, // pixels
UINT height, // rows
BOOL color, // TRUE = RGB
// FALSE = Grayscale
int quality); // 0 - 100
**/
bool result = bool( JpegFile::RGBToJpegFile( nombreArchivo.c_str(), buf,w,h,1,100) );
if ( ! result )
{
std::cout << "error al escribir imagen (" << nombreArchivo << ")." ;
exit(1) ;
}
}
//**********************************************************************
Imagen::~Imagen ()
{
if ( buf != NULL )
delete[] buf ;
buf = NULL ;
}
//**********************************************************************
} // fin namespace jpg