Photoshop: Save as array of bytes?

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
monobogdan
Member
Member
Posts: 71
Joined: Wed Jan 25, 2017 3:37 pm

Photoshop: Save as array of bytes?

Post by monobogdan »

Hi. I'm need to save some bitmap as array of bytes. Can i do it in photoshop?
Boris
Member
Member
Posts: 145
Joined: Sat Nov 07, 2015 3:12 pm

Re: Photoshop: Save as array of bytes?

Post by Boris »

Jpg, PDF are arrays of bytes.
You need to tell us how do you want your
array of bytes to look like.
ex: all pixels row per row, without padding, in this format ?R(8bits)G(8bits)B(8bits)
monobogdan
Member
Member
Posts: 71
Joined: Wed Jan 25, 2017 3:37 pm

Re: Photoshop: Save as array of bytes?

Post by monobogdan »

Boris wrote:Jpg, PDF are arrays of bytes.
You need to tell us how do you want your
array of bytes to look like.
ex: all pixels row per row, without padding, in this format ?R(8bits)G(8bits)B(8bits)
Yes, export as simple C header row per row. Color format R8G8B8
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: Photoshop: Save as array of bytes?

Post by Schol-R-LEA »

monobogdan wrote:
Boris wrote:Jpg, PDF are arrays of bytes.
You need to tell us how do you want your
array of bytes to look like.
ex: all pixels row per row, without padding, in this format ?R(8bits)G(8bits)B(8bits)
Yes, export as simple C header row per row. Color format R8G8B8
This document discusses PhotoShop format support, but it doesn't really discuss what you seem to want.

However, I can tell you definitely that GIMP will export an image as a C header (note: save the GIMP format file first, the use Export As - the 'save' function always saves as an XCF file first, and you usually have to save first before you can export). However, the format it saves to is a lot more complex than what you are looking for, and the files it produces are enormous compared to you typical compressed image format such as PNG or JPEG - I just tried it to save a 261KB file, and the header file was over 1.6 MB. Part of this is the lack of compression - when I checked, I found that the equivalent BMP file is almost as big, at 1.1 MB - but the text format itself is not particularly suited for bitmaps in the first place (the one major text-based format, SVG - which is an XML format - is designed for defining vectors rather than bitmaps, hence the name Scalable Vector Graphics).
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Photoshop: Save as array of bytes?

Post by Love4Boobies »

It sounds like you want BMP images. Parse the headers to make sure they are uncompressed 24-bit and to see if there is any palette data. The image data should be in the format you describe. Another format that is exceedingly simple to parse is PCX, which is pretty much the same, except it uses RLE compression (i.e., repeat the next pixel a certain amount of times). Other formats are more interesting but will require more work on your part.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
monobogdan
Member
Member
Posts: 71
Joined: Wed Jan 25, 2017 3:37 pm

Re: Photoshop: Save as array of bytes?

Post by monobogdan »

Love4Boobies wrote:It sounds like you want BMP images. Parse the headers to make sure they are uncompressed 24-bit and to see if there is any palette data. The image data should be in the format you describe. Another format that is exceedingly simple to parse is PCX, which is pretty much the same, except it uses RLE compression (i.e., repeat the next pixel a certain amount of times). Other formats are more interesting but will require more work on your part.
In VESA with some videomodes too strange color formats, 16 bit works but 24 bits not.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Photoshop: Save as array of bytes?

Post by Love4Boobies »

You said something about RGB with 8 bits per channel earlier but perhaps you were replying to something else. VBE/Core does normally support 24-bit video modes but if your implementation does not, convert your image to an appropriate color depth and/or perform some quantization on the image, perhaps with dithering. Floyd-Steinberg is particularly simple to implement.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: Photoshop: Save as array of bytes?

Post by onlyonemac »

You're looking for "raw". This will give you a set of bytes representing the R, G, and B values for each pixel. You'll need to load this into RAM and then write it to the framebuffer to display it. Note that this doesn't store the size of the image, so you'll need to store or enter that separately.

(This is not the same thing as a raw file from a camera, which is another use of the term "raw" that you might come across in the context of image editing software.)
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Photoshop: Save as array of bytes?

Post by Love4Boobies »

Bitmap, not raw. :)
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: Photoshop: Save as array of bytes?

Post by Schol-R-LEA »

Let's take this again from the top. @monobogdan, would you mind explaining what you are trying to accomplish, why you want a bitmap defined as a data structure in C source code, and why some other solution - say, an embedded bitmap as a blob added to the executable image, or some sort of vector definable form that you could implement a simple drawing routine for - would not work?
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Photoshop: Save as array of bytes?

Post by Love4Boobies »

My guess is that he wants a simple implementation so he can do something cool with his GUI (which he mentioned elsewhere on the forum). It's always fun to see a wallpaper for the first time. :) Something like JPEG takes quite a while to implement.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: Photoshop: Save as array of bytes?

Post by onlyonemac »

Love4Boobies wrote:Bitmap, not raw. :)
Requires too much parsing for a noob.

Look at it this way: the easiest possible way to get an image that you can display on the screen (think of it as a "hello world" for VGA) is by exporting as raw. Just resize your image to, say, 640x480 pixels, save it as raw, and you'll have an array of bytes ready to load into the video memory. Bitmap is the next step from there.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Photoshop: Save as array of bytes?

Post by Love4Boobies »

No, that's what that data structure is called and it can be used for many things, not just images (e.g., this is often what people on this forum use for their first allocators). It's a contiguous map of bits, where each bit (or group of bits) represents an equal part of the whole, in succession.

To my knowledge, Photoshop is the only program which uses this weird "raw" name in the way that you have, which normally suggests something else to anyone familiar with raw data coming from CCD's. However, it's really uncommon and requires elaboration (i.e., "the Photoshop kind") so I suggest avoiding this meaning altogether.

EDIT: See this section on Wikipedia.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Photoshop: Save as array of bytes?

Post by dozniak »

+1 to boobies, raw usually means a slightly more complicated image format.
Learn to read.
User avatar
matt11235
Member
Member
Posts: 286
Joined: Tue Aug 02, 2016 1:52 pm
Location: East Riding of Yorkshire, UK

Re: Photoshop: Save as array of bytes?

Post by matt11235 »

dozniak wrote:+1 to boobies, raw usually means a slightly more complicated image format.
RAW is usually the data straight from the sensor of the camera, it requires a lot of processing before you can get something to look at.
Exporting an image that has already been processed as a RAW doesn't really make sense, much like going from a 32kbps mp3 to a 1000kbps FLAC.
com.sun.java.swing.plaf.nimbus.InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState
Compiler Development Forum
Post Reply