-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with .vtf file modification. #458
Comments
I'm just looking at it, but you take look at your type casting of your
unsigned char. I know the char should give you an address, but in c++ it
gives an actual char and not int value. Please try an int.
…On Tue, Jul 3, 2018, 11:53 AM Mince228 ***@***.***> wrote:
So I've been trying to modify the contents of a .vtf file and then save it
as a new file. I have this:
`
unsigned char *pSrcImage = pTex->ImageData( iFrame, iCubeFace, iMipLevel,
0, 0, z );
float *ImgArray = (float*)pSrcImage;
for (int i = 0; i < iWidth*iHeight * 3; i+=3)
{
ImgArray[i] = 0.0f;
ImgArray[i+1] = 1.0f;
ImgArray[i+2] = 0.0f;
}
*pSrcImage = *(unsigned char*)ImgArray;
CUtlBuffer finBuf;
pTex->Serialize(finBuf);
FILE *fin;
fin = fopen("output.vtf", "w+b");
fwrite(finBuf.Base(), 1, srcVTFLength, fin);
fclose(fin);`
This is meant to change the color of a particular bitmap to a green color.
It successfully creates a working vtf file but it doesn't seem to modify
its contents. It says that ImageData() returns a pointer to the bitmap data
of the vtf interface for the selected face,frame, etc. So I'm considering
that this pointer should be replacing the data of the vtf that I'm
modifying unless it makes a copy of the data and returns the pointer to the
copied data. If anyone has any info on this it would be much appreciated.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#458>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AGDYvk-BQAXdzZPKZz4gJpxBJt7ComFIks5uC6-pgaJpZM4VBYnA>
.
|
i also want to say that in that statement that you given the address of the
array for your pointer. I can see your reasoning why your thought type
casting it. Where ever your array is in location, it could be a negative if
you type cast as a char.
…On Tue, Jul 3, 2018, 11:53 AM Mince228 ***@***.***> wrote:
So I've been trying to modify the contents of a .vtf file and then save it
as a new file. I have this:
`
unsigned char *pSrcImage = pTex->ImageData( iFrame, iCubeFace, iMipLevel,
0, 0, z );
float *ImgArray = (float*)pSrcImage;
for (int i = 0; i < iWidth*iHeight * 3; i+=3)
{
ImgArray[i] = 0.0f;
ImgArray[i+1] = 1.0f;
ImgArray[i+2] = 0.0f;
}
*pSrcImage = *(unsigned char*)ImgArray;
CUtlBuffer finBuf;
pTex->Serialize(finBuf);
FILE *fin;
fin = fopen("output.vtf", "w+b");
fwrite(finBuf.Base(), 1, srcVTFLength, fin);
fclose(fin);`
This is meant to change the color of a particular bitmap to a green color.
It successfully creates a working vtf file but it doesn't seem to modify
its contents. It says that ImageData() returns a pointer to the bitmap data
of the vtf interface for the selected face,frame, etc. So I'm considering
that this pointer should be replacing the data of the vtf that I'm
modifying unless it makes a copy of the data and returns the pointer to the
copied data. If anyone has any info on this it would be much appreciated.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#458>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AGDYvk-BQAXdzZPKZz4gJpxBJt7ComFIks5uC6-pgaJpZM4VBYnA>
.
|
And last thing where are ya sending your pointer unsigned char variable to.
it doesn't look like you are writing to your file.
…On Tue, Jul 3, 2018, 11:53 AM Mince228 ***@***.***> wrote:
So I've been trying to modify the contents of a .vtf file and then save it
as a new file. I have this:
`
unsigned char *pSrcImage = pTex->ImageData( iFrame, iCubeFace, iMipLevel,
0, 0, z );
float *ImgArray = (float*)pSrcImage;
for (int i = 0; i < iWidth*iHeight * 3; i+=3)
{
ImgArray[i] = 0.0f;
ImgArray[i+1] = 1.0f;
ImgArray[i+2] = 0.0f;
}
*pSrcImage = *(unsigned char*)ImgArray;
CUtlBuffer finBuf;
pTex->Serialize(finBuf);
FILE *fin;
fin = fopen("output.vtf", "w+b");
fwrite(finBuf.Base(), 1, srcVTFLength, fin);
fclose(fin);`
This is meant to change the color of a particular bitmap to a green color.
It successfully creates a working vtf file but it doesn't seem to modify
its contents. It says that ImageData() returns a pointer to the bitmap data
of the vtf interface for the selected face,frame, etc. So I'm considering
that this pointer should be replacing the data of the vtf that I'm
modifying unless it makes a copy of the data and returns the pointer to the
copied data. If anyone has any info on this it would be much appreciated.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#458>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AGDYvk-BQAXdzZPKZz4gJpxBJt7ComFIks5uC6-pgaJpZM4VBYnA>
.
|
Oh so I found that the last bit of casting was unnecessary and I could just modify the value in the ImgArray and it would modify the vtf output. To answer your last question, pSrcImage is a pointer that points to whatever
|
Ok, so the last bit of the problem is that if I output the array into a .pfm file using
it outputs a correctly working .pfm file with the whole image being colored either red, green or blue based on the "for" loop, but the .vtf seems to be addressed differently: https://imgur.com/RDh2RUf the first image being
the second
and the third
I'm not sure how to solve this, and the strange thing is that it only colors the green channel and not the red or blue one. |
Ok, so I figured it out. The image needs to be converted into an |
So I've been trying to modify the contents of a .vtf file and then save it as a new file. I have this:
This is meant to change the color of a particular bitmap to a green color.
It successfully creates a working vtf file but it doesn't seem to modify its contents. It says that ImageData() returns a pointer to the bitmap data of the vtf interface for the selected face,frame, etc. So I'm considering that this pointer should be replacing the data of the vtf that I'm modifying unless it makes a copy of the data and returns the pointer to the copied data. If anyone has any info on this it would be much appreciated.
The text was updated successfully, but these errors were encountered: