Board.KolibriOS.org

Official KolibriOS board
It is currently Sun Oct 25, 2020 3:21 am

All times are UTC+03:00




Post new topic  Reply to topic  [ 96 posts ]  Go to page Previous 13 4 5 6 7
Author Message
PostPosted: Sun Sep 27, 2020 5:04 pm 
Offline

Joined: Mon Sep 07, 2020 7:09 pm
Posts: 128
Допустим есть код
Code:
   char* text = "HELLO!";
void *buf = malloc(768*256*3 * sizeof(char));
   *((int*)buf) = 768;
   *((int*)buf+1) = 256;
   memset((char*)buf+8, (char)-1, 768*256*3);
   int len = countUTF8Z(text, -1);
   drawText(buf, 0, 0, text, len, 0xFFFF0000, 0x08031428);

Он работает, но фон белый
И где тут заполняется буфер цветом?
Если он тут не заполняется, как его тогда вообще заполнить?
PS это Си

_________________
How to use different compilers in KolibriOS
Old doc
http://diamond.kolibrios.org/hll/hll.htm
New doc
https://maxcodehack.github.io/hll-kos/


Top
   
PostPosted: Sun Sep 27, 2020 6:18 pm 
Offline
Mentor
User avatar

Joined: Mon Oct 19, 2009 10:58 am
Posts: 516
maxcodehack wrote:
И где тут заполняется буфер цветом?
Code:
memset((char*)buf+8, (char)-1, 768*256*3);

BTW, this memset writes beyond the buffer. Check the length.


Top
   
PostPosted: Sun Sep 27, 2020 6:23 pm 
Offline

Joined: Mon Sep 07, 2020 7:09 pm
Posts: 128
I need to write
memset((char*)buf+8, (char)-1, 768*256*3 - sizeof(char));
?
I get this code from C_Layer

_________________
How to use different compilers in KolibriOS
Old doc
http://diamond.kolibrios.org/hll/hll.htm
New doc
https://maxcodehack.github.io/hll-kos/


Last edited by maxcodehack on Sun Sep 27, 2020 7:52 pm, edited 2 times in total.

Top
   
PostPosted: Sun Sep 27, 2020 7:01 pm 
Offline
Mentor
User avatar

Joined: Mon Oct 19, 2009 10:58 am
Posts: 516
What is the address of the last byte you allocate via malloc?
What is the address of the last byte you write to via memset?

maxcodehack wrote:
sizeof(char)

You can read about sizeof(char) in the C standard draft, 6.5.3.4 The sizeof operator.


Top
   
PostPosted: Sun Sep 27, 2020 7:07 pm 
Offline

Joined: Mon Sep 07, 2020 7:09 pm
Posts: 128
I get this code from C_Layer

_________________
How to use different compilers in KolibriOS
Old doc
http://diamond.kolibrios.org/hll/hll.htm
New doc
https://maxcodehack.github.io/hll-kos/


Top
   
PostPosted: Sun Sep 27, 2020 8:46 pm 
Offline
Mentor
User avatar

Joined: Mon Oct 19, 2009 10:58 am
Posts: 516
  1. A pixel color is coded as one or more channels.
  2. Each color channel is coded separately according to its depth.
  3. The number of channels and their ordering and depth are collectively called pixel format.
  4. The most common pixel formats have 8-bit channels, e.g. Red, Green, Blue. Hence for such pixel formats one channel occupies one byte.
  5. There is no single standartized way to name pixel formats, e.g. RGB, RGB888, true color and 24bit may refer to the same format.
  6. A convenient way to write colors in text is hex, one of binary-to-text encodings.
  7. Description of drawText function (part of RasterWorks) mentions two pixel formats accepted: 24bpp and 32bpp (bpp -- bits per pixel).
  8. You define the format to use in the last argument of the function, it's 24bpp in your example.
  9. What KolibriOS expects to be 24bpp can be found in description of sf7, it's BBGGRRBBGGRRBBGGRR...
  10. I.e. a byte describing Blue component of the first pixel, a byte describing Green component of the first pixel, a byte describing Red component of the first pixel. Then data of the second and other pixels go.
  11. White color in 24bpp pixel format is Red=255, Green=255, Blue=255. Or, using shorter hex notation, 0xFFFFFF.
  12. (char)-1 in your example is a byte with value 0xFF in hex, read why.
  13. So, the background color in your example is white because memset writes many 0xFF's, which are interpreted as 0xFFFFFF triplets, which mean white pixels.
  14. Description of drawText function says that the first argument is a pointer to the structure of three fields: xSize, ySize, picture.
  15. To allocate enough memory for this structure, calculate its size, which is the sum of the sizes of its fields. It's not always the case, but this time you are lucky.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 96 posts ]  Go to page Previous 13 4 5 6 7

All times are UTC+03:00


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited