Page 2 of 2
Posted: Tue Mar 04, 2008 10:11 am
by Zacariaz
of course i could just create my own raw image format, and i probably will, but i still need the ability to import/export other formats (probably only jpeg and png) and while i could, i guess, use various libs for the task, it's is my experience that thing work best if you do it your self.
As for the png part i am really really close, there is just a tiny little part that i don't understand.
I haven't investigated jpeg yet, but my guest is that it won't be too hard either.
Posted: Tue Mar 04, 2008 10:44 am
by Dex
But this is not the ? you asked, You wanted a uncompressed image format, with alpha support and the only one's available are rare, so you would be best writing your own.
The point that you will need to support other file format is true for all OS used today.
Also most of the other image formats are compressed.
But you start with a simple format usually bmp or your own and work your way up.
Posted: Tue Mar 04, 2008 11:47 am
by Zacariaz
I actually had writen very long reply, but instead i descided to restate my my question.
"I need an lossless image format which is not to complicated. Which would you recomment?" but then again i have allready found that PNG and me work work together pretty well, there is just that little tiny bit which i can't understand.
So, my question, if i should bother restating it, must be: "Where can i get some complete specs for the png image format?" but im pretty sure that the specs i allready have are complete, its just me who can understand it. I just wish i knew what it was, then i would know how to ask the right question.
Thus the only option left is getting hold of someone who have some experience with png.
By the way i do find png simple, much more than i would have thought before i started. This post was really one of those: "i want to do this, but its probably too complicated for me." as it turns out, this isn't true, but i do need help.
Posted: Wed Mar 05, 2008 6:10 am
by eddyb
your image looks like the one atachated?
maybe i wrong the colours...
Posted: Wed Mar 05, 2008 1:13 pm
by Dex
If you used it right, it would come out like the posted image.
Note: There's two icon's displayed in this image.
Posted: Thu Mar 06, 2008 1:07 am
by Solar
Zacariaz wrote:So, my question, if i should bother restating it, must be: "Where can i get some complete specs for the png image format?" but im pretty sure that the specs i allready have are complete...
http://www.libpng.org/pub/png/pngdocs.html is your safest bet.
By the way i do find png simple, much more than i would have thought before i started.
I found PNG to be heavily influenced by the IFF metaformat, which was proposed by Electronic Arts in 1985. As most of the "early" formats, it was
from techies
for techies, and it shows.
While IFF itself more or less died together with the AmigaOS, there are many quite successful deviants of the format (RIFF WAV, AIFF, PNG) still around today.
Posted: Thu Mar 06, 2008 3:53 am
by eddyb
Dex wrote:If you used it right, it would come out like the posted image.
Note: There's two icon's displayed in this image.
yah. i think there is a problem with colour palette(i tried with other images and if i dont put the palette of the image, i get a ugly one, else i could put on the screen images verry well) and with the size.
Also, i made a program that converts a bmp image into an asm file that have the image(as pixels array) and the palette of the image.
who wants to post the code?
Posted: Thu Mar 06, 2008 6:35 am
by Zacariaz
Solar wrote:Zacariaz wrote:So, my question, if i should bother restating it, must be: "Where can i get some complete specs for the png image format?" but im pretty sure that the specs i allready have are complete...
http://www.libpng.org/pub/png/pngdocs.html is your safest bet.
And that is exactly the docs im using, atlest from the same site, but still when looking at a sample image there is data in the IDAT chunk that should be there according to the docs, that is atleast how i interpet them.
Here is the data in hex: (uncompressed no nothing 1 pixel png image)
Code: Select all
[signature]89 50 4e 47 0d 0a 1a 0a[/signature]
[IHDR]
[chunk-length]00 00 00 0d[/chunk-length]
[chunk-type]49 48 44 52[/chunk-type]
[width]00 00 00 01[/width]
[height]00 00 00 01[/height]
[bit-depth]08[/bit-depth]
[color-type]02[/color-type]
[compression-methode]00[/compression-methode]
[filter-methode]00[/filter-methode]
[interlace-methode]00[/interlace-methode]
[CRC]90 77 53 de[/CRC]
[/IHDR]
[IDAT]
[chunk-length]00 00 00 0f[/chunk-length]
[chunk-type]49 44 41 54[/chunk-type]
[?]78 01 01 04 00 fb ff 00[/?]
[pixel-value]23 57 bd[/pixel-value]
[?]01 d8 01 38[/?]
[CRC]18 f1 06 f3[/CRC]
[/IDAT]
[IEND]
[chunk-length]00 00 00 00[/chunk-length]
[chunk-type]49 45 4e 44[/chunk-type]
[CRC]ae 42 60 82[/CRC]
[/IEND]
As you can see i have actually got 12 byte which i don't know what to do with and no matter how many times i read the docs, it can't find an explanation.
Just for the sake of it i uploaded the test file, but i had to sip it, otherwise it would just show as a 1px image which is kinda hard to hit
Posted: Thu Mar 06, 2008 11:16 am
by Dex
eddyb wrote:Dex wrote:If you used it right, it would come out like the posted image.
Note: There's two icon's displayed in this image.
yah. i think there is a problem with colour palette(i tried with other images and if i dont put the palette of the image, i get a ugly one, else i could put on the screen images verry well) and with the size.
Also, i made a program that converts a bmp image into an asm file that have the image(as pixels array) and the palette of the image.
who wants to post the code?
This is a bit off topic, but to answer your ?.
I think you maybe mixing this up with 256 color 8bpp, this is for 24/32bpp, theres no palette, the format is RRGGBB for 24bpp and XXRRGGBB for 32bpp, XX in most caser's = 0x00.
So the color white, would be 0x00ffffff for 32bpp.
I have a bootable demo that sets up vesa and displays these icon's, if you want it and the code let me know.
PS: I would like to see your code, thanks.
Posted: Thu Mar 06, 2008 1:33 pm
by eddyb
yah, i use 256 colors, in mode 320x200
this is the code for my "transformer":
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <sys/nearptr.h>
#include <string.h>
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned long dword;
typedef struct tagBITMAP /* the structure for a bitmap. */
{
word width;
word height;
byte palette[256*3];
byte *data;
} BITMAP;
/**************************************************************************
* fskip *
* Skips bytes in a file. *
**************************************************************************/
void fskip(FILE *fp, int num_bytes)
{
int i;
for (i=0; i<num_bytes; i++)
fgetc(fp);
}
void load_bmp(char *file,BITMAP *b)
{
FILE *fp;
long index;
word num_colors;
int x;
/* open the file */
if ((fp = fopen(file,"rb")) == NULL)
{
printf("Error opening file %s.\n",file);
exit(1);
}
/* check to see if it is a valid bitmap file */
if (fgetc(fp)!='B' || fgetc(fp)!='M')
{
fclose(fp);
printf("%s is not a bitmap file.\n",file);
exit(1);
}
/* read in the width and height of the image, and the
number of colors used; ignore the rest */
fskip(fp,16);
fread(&b->width, sizeof(word), 1, fp);
fskip(fp,2);
fread(&b->height,sizeof(word), 1, fp);
fskip(fp,22);
fread(&num_colors,sizeof(word), 1, fp);
fskip(fp,6);
/* assume we are working with an 8-bit file */
if (num_colors==0) num_colors=256;
/* try to allocate memory */
if ((b->data = (byte *) malloc((word)(b->width*b->height))) == NULL)
{
fclose(fp);
printf("Error allocating memory for file %s.\n",file);
exit(1);
}
/* read the palette information */
for(index=0;index<num_colors;index++)
{
b->palette[(int)(index*3+2)] = fgetc(fp) >> 2;
b->palette[(int)(index*3+1)] = fgetc(fp) >> 2;
b->palette[(int)(index*3+0)] = fgetc(fp) >> 2;
x=fgetc(fp);
}
/* read the bitmap */
for(index=(b->height-1)*b->width;index>=0;index-=b->width)
for(x=0;x<b->width;x++)
b->data[(word)(index+x)]=(byte)fgetc(fp);
fclose(fp);
}
int main(int argc, char * argv[])
{
if(argc<2)
{
puts("No arguments!\nUse: bitmap.exe [file_des]");
return;
}
int i,x,y;
char ch[256];
char chb[256];
char cha[256];
strcpy(ch, argv[1]);
strcpy(chb, ch);
strcpy(cha, ch);
strcat(chb, ".bmp");
strcat(cha, ".asm");
BITMAP bmp;
load_bmp(chb,&bmp); /* open the file */
FILE * fp;
fp = fopen(cha, "w");
fprintf(fp, ";%s bitmap file\n;transormed by edy\n\nglobal _%s\n_%s:\n", chb, ch, ch);
for(y=0;y<(bmp.width*bmp.height)/12;y++)
{
fprintf(fp, "db ");
for(x=0;x<12;x++)
{
if(x==11)
fprintf(fp, "%#X", bmp.data[x+y*12]);
else
fprintf(fp, "%#X,", bmp.data[x+y*12]);
}
fprintf(fp, "\n");
}
fprintf(fp, "\n\n;%s bitmap palette\n\nglobal _%s_palette\n_%s_palette:\n", chb, ch, ch);
for(y=0;y<(256*3)/12;y++)
{
fprintf(fp, "db ");
for(x=0;x<12;x++)
{
if(x==11)
fprintf(fp, "%#X", bmp.palette[x+y*12]);
else
fprintf(fp, "%#X,", bmp.palette[x+y*12]);
}
fprintf(fp, "\n");
}
printf("Image %s succefuly transformed\n whith res: %ux%u", chb, bmp.width, bmp.height);
getch();
return 0;
}
its transform a <name>.bmp image in a <name>.asm file with this content:
Code: Select all
;a comment...
<name>:
<here comes the data as pixels array>
<name>_palette:
<here comes the image palette>
<name> is the argument
(eg if u want to transform music.bmp:
)
to have many images, i use a batch that executes the prog for each image, then gather the images(asm images
)(using comand
Code: Select all
copy \b img1.asm + img2.asm +... imgs.asm
) into a single .asm file.
Note: that's for 8 byte bitmaps.
Posted: Thu Mar 06, 2008 8:07 pm
by Dex
Thanks
.
Posted: Fri Mar 07, 2008 12:28 am
by eddyb
thanks to
this and
this
.
Also(if isn't offtopic), how i can get a bigger resolution modifying the video registers?
Posted: Fri Mar 07, 2008 2:01 am
by pcmattman
Code: Select all
int i;
for (i=0; i<num_bytes; i++)
fgetc(fp);
fseek with SEEK_CUR much?
Posted: Fri Mar 07, 2008 10:07 pm
by Dex
For realmode you can try vesa and bank switching, for info read these topic's and see my demo, to get 640*480 256 colors
http://www.osdev.org/phpBB2/viewtopic.p ... ight=vesa1
If you mean to use in pmode, theres also a demo of mine using vesa and LFB, lower down in the topic.