Answer the question
In order to leave comments, you need to log in
Why incorrect array output in Visual C++ console?
Good evening.
The task is to convert the existing image in jpeg format to DIB and build a two-dimensional matrix based on this DIB file.
I am using Intel Jpeg library 1.5.
The program runs correctly (I checked each piece with prints).
But when calling an array that turned out. I get this output with this output:
In the console, instead of data from the array, the suit of the "heart" appears (for example, a heart).
When called in such a barbaric way:
Displays a set of suits, several spades, tefs, hearts.
I broke my whole head over this. What could it be. img - buffer with data
is set like this:cout << img[n] << setw(5);
cout << img << setw(5);
unsigned char *img = new unsigned char[ImageSize];
image.DIBBytes = img;
#include "stdafx.h"
//#include "scan.h"
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
#include <wchar.h>
#include <math.h>
#include <iostream>
#include "ijl.h"
#include <conio.h>
#include <windows.h>
#include <dos.h>
#pragma comment(lib,"ijl15.lib")
using namespace std;
int JPGquality = 75;//in percents
int i;
int j;
#define MAX_LOADSTRING 100
BOOL DecodeJPGFileToGeneralBuffer(
LPCSTR lpszPathName,
DWORD* width,
DWORD* height,
DWORD* nchannels,
BYTE** buffer)
{
BOOL bres;
IJLERR jerr;
DWORD x = 0; // pixels in scan line
DWORD y = 0; // number of scan lines
DWORD c = 0; // number of channels
DWORD wholeimagesize;
BYTE* pixel_buf = NULL;
// Allocate the IJL JPEG_CORE_PROPERTIES structure.
JPEG_CORE_PROPERTIES jcprops;
bres = TRUE;
__try
{
// Initialize the IntelR JPEG Library.
jerr = ijlInit(&jcprops);
if (IJL_OK != jerr)
{
bres = FALSE;
__leave;
}
// Get information on the JPEG image
// (i.e., width, height, and channels).
jcprops.JPGFile = const_cast<LPSTR>(lpszPathName);
jerr = ijlRead(&jcprops, IJL_JFILE_READPARAMS);
if (IJL_OK != jerr)
{
bres = FALSE;
__leave;
}
// Set up local data.
x = jcprops.JPGWidth;
y = jcprops.JPGHeight;
c = 3; // Decode into a 3 channel pixel buffer.
// Compute size of desired pixel buffer.
wholeimagesize = (x * y * c);
// Allocate memory to hold the decompressed image data.
pixel_buf = new BYTE[wholeimagesize];
if (NULL == pixel_buf)
{
bres = FALSE;
__leave;
}
// Set up the info on the desired DIB properties.
jcprops.DIBWidth = x;
jcprops.DIBHeight = y; // Implies a bottom-up DIB.
jcprops.DIBChannels = c;
jcprops.DIBColor = IJL_BGR;
jcprops.DIBPadBytes = 0;
jcprops.DIBBytes = pixel_buf;
// Set the JPG color space ... this will always be
// somewhat of an educated guess at best because JPEG
// is "color blind" (i.e., nothing in the bit stream
// tells you what color space the data was encoded from).
// However, in this example we assume that we are
// reading JFIF files which means that 3 channel images
// are in the YCbCr color space and 1 channel images are
// in the Y color space.
switch (jcprops.JPGChannels)
{
case 1:
{
jcprops.JPGColor = IJL_G;
break;
}
case 3:
{
jcprops.JPGColor = IJL_YCBCR;
break;
}
default:
{
// This catches everything else, but no
// color twist will be performed by the IJL.
jcprops.DIBColor = (IJL_COLOR)IJL_OTHER;
jcprops.JPGColor = (IJL_COLOR)IJL_OTHER;
break;
}
}
// Now get the actual JPEG image data into the pixel buffer.
jerr = ijlRead(&jcprops, IJL_JFILE_READWHOLEIMAGE);
if (IJL_OK != jerr)
{
bres = FALSE;
__leave;
}
} // __try
__finally
{
if (FALSE == bres)
{
if (NULL != pixel_buf)
{
delete[] pixel_buf;
pixel_buf = NULL;
}
}
// Clean up the IntelR JPEG Library.
ijlFree(&jcprops);
*width = x;
*height = y;
*nchannels = c;
*buffer = pixel_buf;
} // __finally
return bres;
} // DecodeJPGFileToGeneralBuffer()
DWORD x;
DWORD y;
DWORD nchannels;
BYTE* buffer;
char temp[255];
LPCSTR lpszPathName;
int main()
{
JPEG_CORE_PROPERTIES jcprops;
IJLERR jerr;
int st, sty, l, i1, i2, j1, j2, kk;
float mx, my, mxi, myi, ax, ay, a, m20, m02, m11, alpha, elongation;//разные моменты и центр масс
sty = 0; y = 0;
jerr = ijlInit(&jcprops);
sprintf(temp, "0.jpg", 1);//MessageBoxA(0,temp,0,0);
jcprops.JPGFile = const_cast<LPSTR>(temp);
sty += y;
jerr = ijlRead(&jcprops, IJL_JFILE_READPARAMS);
x = jcprops.JPGWidth;
y = jcprops.JPGHeight;
ijlFree(&jcprops);
buffer = new BYTE[x*y * 3];
DecodeJPGFileToGeneralBuffer(temp,
&x,
&y,
&nchannels,
&buffer);
std::cout << y << "= os y" << endl;
std::cout << x << "= os x" << endl;
std::cout << nchannels << "= channel" << endl;
std::cout << buffer[j*x * 3] << "= buffer 1" << endl;
std::cout << buffer[j*x * 3+1] << "= buffer 2" << endl;
std::cout << buffer[j*x * 3+1] << "= buffer 3" << endl;
system("pause");
std::cout << "end"<< endl;
system("pause");
}
Answer the question
In order to leave comments, you need to log in
You output char* and char, the text is displayed up to 0 (if my memory serves me right) and a character.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question